From 6b9e0b1dbd3417dcddbab40534e4cd60219ad266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 17 May 2022 13:15:40 +0300 Subject: [PATCH] build-libcxx: Build both static and shared libc++ in one single cmake build Since bedf657d0f4c54ffe9ef4303382657a74296b544 in llvm-project (May 18th), a static libc++ built at the same time as a shared one no longer contain dllexport directives, making that library actually usable. Since dfa88927ae1411ccc3b248b7e624f2acf623d947 (Jun 6th), the libc++ headers no longer have dllimport attributes, making the headers installed from a build containing a shared library usable both for the shared and static library, without the user having to set any specific defines. These two changes allow removing the manual build workarounds of building the libraries in separate CMake invocations in a specific order. --- build-libcxx.sh | 110 ++++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 64 deletions(-) diff --git a/build-libcxx.sh b/build-libcxx.sh index 27bd323..9880379 100755 --- a/build-libcxx.sh +++ b/build-libcxx.sh @@ -16,18 +16,18 @@ set -e -BUILD_STATIC=1 -BUILD_SHARED=1 +BUILD_STATIC=ON +BUILD_SHARED=ON while [ $# -gt 0 ]; do if [ "$1" = "--disable-shared" ]; then - BUILD_SHARED= + BUILD_SHARED=OFF elif [ "$1" = "--enable-shared" ]; then - BUILD_SHARED=1 + BUILD_SHARED=ON elif [ "$1" = "--disable-static" ]; then - BUILD_STATIC= + BUILD_STATIC=OFF elif [ "$1" = "--enable-static" ]; then - BUILD_STATIC=1 + BUILD_STATIC=ON else PREFIX="$1" fi @@ -74,62 +74,44 @@ else BUILDCMD=make fi -build_all() { - type="$1" - CMAKEFLAGS="" - if [ "$type" = "shared" ]; then - SHARED=TRUE - STATIC=FALSE - CMAKEFLAGS="$CMAKEFLAGS -DLIBCXXABI_USE_LLVM_UNWINDER=ON" - else - SHARED=FALSE - STATIC=TRUE - fi +for arch in $ARCHS; do + [ -z "$CLEAN" ] || rm -rf build-$arch + mkdir -p build-$arch + cd build-$arch + cmake \ + ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$PREFIX/$arch-w64-mingw32" \ + -DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \ + -DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \ + -DCMAKE_CXX_COMPILER_TARGET=$arch-w64-windows-gnu \ + -DCMAKE_CROSSCOMPILING=TRUE \ + -DCMAKE_SYSTEM_NAME=Windows \ + -DCMAKE_C_COMPILER_WORKS=TRUE \ + -DCMAKE_CXX_COMPILER_WORKS=TRUE \ + -DLLVM_PATH="$LLVM_PATH" \ + -DCMAKE_AR="$PREFIX/bin/llvm-ar" \ + -DCMAKE_RANLIB="$PREFIX/bin/llvm-ranlib" \ + -DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \ + -DLIBUNWIND_USE_COMPILER_RT=TRUE \ + -DLIBUNWIND_ENABLE_SHARED=$BUILD_SHARED \ + -DLIBUNWIND_ENABLE_STATIC=$BUILD_STATIC \ + -DLIBCXX_USE_COMPILER_RT=ON \ + -DLIBCXX_ENABLE_SHARED=$BUILD_SHARED \ + -DLIBCXX_ENABLE_STATIC=$BUILD_STATIC \ + -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \ + -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \ + -DLIBCXX_CXX_ABI=libcxxabi \ + -DLIBCXX_LIBDIR_SUFFIX="" \ + -DLIBCXX_INCLUDE_TESTS=FALSE \ + -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=FALSE \ + -DLIBCXXABI_USE_COMPILER_RT=ON \ + -DLIBCXXABI_USE_LLVM_UNWINDER=ON \ + -DLIBCXXABI_ENABLE_SHARED=OFF \ + -DLIBCXXABI_LIBDIR_SUFFIX="" \ + .. - for arch in $ARCHS; do - [ -z "$CLEAN" ] || rm -rf build-$arch-$type - mkdir -p build-$arch-$type - cd build-$arch-$type - cmake \ - ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX="$PREFIX/$arch-w64-mingw32" \ - -DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \ - -DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \ - -DCMAKE_CXX_COMPILER_TARGET=$arch-w64-windows-gnu \ - -DCMAKE_CROSSCOMPILING=TRUE \ - -DCMAKE_SYSTEM_NAME=Windows \ - -DCMAKE_C_COMPILER_WORKS=TRUE \ - -DCMAKE_CXX_COMPILER_WORKS=TRUE \ - -DLLVM_PATH="$LLVM_PATH" \ - -DCMAKE_AR="$PREFIX/bin/llvm-ar" \ - -DCMAKE_RANLIB="$PREFIX/bin/llvm-ranlib" \ - -DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \ - -DLIBUNWIND_USE_COMPILER_RT=TRUE \ - -DLIBUNWIND_ENABLE_SHARED=$SHARED \ - -DLIBUNWIND_ENABLE_STATIC=$STATIC \ - -DLIBCXX_USE_COMPILER_RT=ON \ - -DLIBCXX_ENABLE_SHARED=$SHARED \ - -DLIBCXX_ENABLE_STATIC=$STATIC \ - -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \ - -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \ - -DLIBCXX_CXX_ABI=libcxxabi \ - -DLIBCXX_LIBDIR_SUFFIX="" \ - -DLIBCXX_INCLUDE_TESTS=FALSE \ - -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=FALSE \ - -DLIBCXXABI_USE_COMPILER_RT=ON \ - -DLIBCXXABI_ENABLE_SHARED=OFF \ - -DLIBCXXABI_LIBDIR_SUFFIX="" \ - $CMAKEFLAGS \ - .. - - $BUILDCMD ${CORES+-j$CORES} - $BUILDCMD install - cd .. - done -} - -# Build shared first and static afterwards; the headers for static linking also -# work when linking against the DLL, but not vice versa. -[ -z "$BUILD_SHARED" ] || build_all shared -[ -z "$BUILD_STATIC" ] || build_all static + $BUILDCMD ${CORES+-j$CORES} + $BUILDCMD install + cd .. +done