Skip to content

Commit

Permalink
Build libcxx and libcxxabi via llvm-project/runtimes
Browse files Browse the repository at this point in the history
This is the new method to build runtimes as of LLVM 12, and the previous
standalone method is deprecated since LLVM 14 and unsupported since
LLVM 15 (llvm/llvm-project@6f17768)

Building libcxx and libcxxabi in one go simplifies the setup necessary
as:
- tests CMakeLists.txt have some wrong dependencies which would need
  to be worked around.
- LIBCXXABI_LIBCXX_INCLUDES is not recognized when building separately
  and passing -I paths via the command line yields msys path munging
  problems on Windows.

This effectively drops support for LLVM 11 and older.
  • Loading branch information
glandium authored and sunfishcode committed May 12, 2022
1 parent e025da6 commit 37ae6af
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT build/wasi-libc.BUILT
cp -R $(ROOT_DIR)/build/llvm/lib/clang $(BUILD_PREFIX)/lib/
touch build/compiler-rt.BUILT

# Flags for libcxx.
# Flags for libcxx and libcxxabi.
LIBCXX_CMAKE_FLAGS = \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
Expand All @@ -136,11 +136,13 @@ LIBCXX_CMAKE_FLAGS = \
-DCMAKE_STAGING_PREFIX=$(PREFIX)/share/wasi-sysroot \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCXX_SUPPORTS_CXX11=ON \
-DLIBCXX_ENABLE_THREADS:BOOL=OFF \
-DLIBCXX_HAS_PTHREAD_API:BOOL=OFF \
-DLIBCXX_HAS_EXTERNAL_THREAD_API:BOOL=OFF \
-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF \
-DLIBCXX_HAS_WIN32_THREAD_API:BOOL=OFF \
-DLLVM_COMPILER_CHECKED=ON \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXX_ENABLE_SHARED:BOOL=OFF \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL=OFF \
Expand All @@ -150,30 +152,6 @@ LIBCXX_CMAKE_FLAGS = \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=$(LLVM_PROJ_DIR)/libcxxabi/include \
-DLIBCXX_HAS_MUSL_LIBC:BOOL=ON \
-DLIBCXX_ABI_VERSION=2 \
-DWASI_SDK_PREFIX=$(BUILD_PREFIX) \
--debug-trycompile

build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUILT
# Do the build.
mkdir -p build/libcxx
cd build/libcxx && cmake -G Ninja $(LIBCXX_CMAKE_FLAGS) \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \
$(LLVM_PROJ_DIR)/libcxx
ninja $(NINJA_FLAGS) -C build/libcxx
# Do the install.
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx install
touch build/libcxx.BUILT

# Flags for libcxxabi.
LIBCXXABI_CMAKE_FLAGS = \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DCMAKE_AR=$(BUILD_PREFIX)/bin/ar \
-DCMAKE_MODULE_PATH=$(ROOT_DIR)/cmake \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXXABI_ENABLE_SHARED:BOOL=OFF \
-DLIBCXXABI_SILENT_TERMINATE:BOOL=ON \
Expand All @@ -183,31 +161,25 @@ LIBCXXABI_CMAKE_FLAGS = \
-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF \
-DLIBCXXABI_HAS_WIN32_THREAD_API:BOOL=OFF \
-DLIBCXXABI_ENABLE_PIC:BOOL=OFF \
-DCXX_SUPPORTS_CXX11=ON \
-DLLVM_COMPILER_CHECKED=ON \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXXABI_LIBCXX_PATH=$(LLVM_PROJ_DIR)/libcxx \
-DLIBCXXABI_LIBCXX_INCLUDES=$(BUILD_PREFIX)/share/wasi-sysroot/include/c++/v1 \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
-DCMAKE_STAGING_PREFIX=$(PREFIX)/share/wasi-sysroot \
-DWASI_SDK_PREFIX=$(BUILD_PREFIX) \
-DUNIX:BOOL=ON \
--debug-trycompile

build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT
build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUILT
# Do the build.
mkdir -p build/libcxxabi
cd build/libcxxabi && cmake -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \
mkdir -p build/libcxx
cd build/libcxx && cmake -G Ninja $(LIBCXX_CMAKE_FLAGS) \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \
$(LLVM_PROJ_DIR)/libcxxabi
ninja $(NINJA_FLAGS) -C build/libcxxabi
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
$(LLVM_PROJ_DIR)/runtimes
ninja $(NINJA_FLAGS) -C build/libcxx
# Do the install.
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxxabi install
touch build/libcxxabi.BUILT
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx install
touch build/libcxx.BUILT

build/config.BUILT:
mkdir -p $(BUILD_PREFIX)/share/misc
Expand All @@ -216,7 +188,7 @@ build/config.BUILT:
cp wasi-sdk.cmake $(BUILD_PREFIX)/share/cmake
touch build/config.BUILT

build: build/llvm.BUILT build/wasi-libc.BUILT build/compiler-rt.BUILT build/libcxxabi.BUILT build/libcxx.BUILT build/config.BUILT
build: build/llvm.BUILT build/wasi-libc.BUILT build/compiler-rt.BUILT build/libcxx.BUILT build/config.BUILT

strip: build/llvm.BUILT
./strip_symbols.sh $(BUILD_PREFIX)
Expand Down

0 comments on commit 37ae6af

Please sign in to comment.