Skip to content

Commit

Permalink
Add LTO build of libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jun 7, 2024
1 parent 26535db commit 26edb13
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT
# $(2): shared libraries ON or OFF
# $(3): the name of the target being built for
# $(4): extra compiler flags to pass
# $(5): extra libdir suffix
LIBCXX_CMAKE_FLAGS = \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
Expand Down Expand Up @@ -238,8 +239,8 @@ LIBCXX_CMAKE_FLAGS = \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(WASI_SDK_CFLAGS) $(EXTRA_CFLAGS) $(4) --target=$(3)" \
-DCMAKE_CXX_FLAGS="$(WASI_SDK_CXXFLAGS) $(EXTRA_CXXFLAGS) $(4) --target=$(3)" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3) \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3) \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3)$(5) \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3)$(5) \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
$(LLVM_PROJ_DIR)/runtimes

Expand All @@ -252,6 +253,12 @@ define BUILD_LIBCXX
cd build/libcxx-$(3) && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,$(1),$(2),$(3),$(4))
ninja $(NINJA_FLAGS) -C build/libcxx-$(3)
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx-$(3) install

mkdir -p build/libcxx-$(3)-lto
cd build/libcxx-$(3)-lto && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,$(1),OFF,$(3),$(4) -flto,/llvm-lto/$(shell $(BUILD_PREFIX)/bin/clang -dumpversion))
ninja $(NINJA_FLAGS) -C build/libcxx-$(3)-lto
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx-$(3)-lto install

rm -rf $(BUILD_PREFIX)/share/wasi-sysroot/include/$(3)/c++
mv $(BUILD_PREFIX)/share/wasi-sysroot/include/c++ $(BUILD_PREFIX)/share/wasi-sysroot/include/$(3)/
endef
Expand Down

0 comments on commit 26edb13

Please sign in to comment.