Skip to content

Commit 6b9e0b1

Browse files
committed
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.
1 parent 5cc13ad commit 6b9e0b1

File tree

1 file changed

+47
-65
lines changed

1 file changed

+47
-65
lines changed

build-libcxx.sh

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
set -e
1818

19-
BUILD_STATIC=1
20-
BUILD_SHARED=1
19+
BUILD_STATIC=ON
20+
BUILD_SHARED=ON
2121

2222
while [ $# -gt 0 ]; do
2323
if [ "$1" = "--disable-shared" ]; then
24-
BUILD_SHARED=
24+
BUILD_SHARED=OFF
2525
elif [ "$1" = "--enable-shared" ]; then
26-
BUILD_SHARED=1
26+
BUILD_SHARED=ON
2727
elif [ "$1" = "--disable-static" ]; then
28-
BUILD_STATIC=
28+
BUILD_STATIC=OFF
2929
elif [ "$1" = "--enable-static" ]; then
30-
BUILD_STATIC=1
30+
BUILD_STATIC=ON
3131
else
3232
PREFIX="$1"
3333
fi
@@ -74,62 +74,44 @@ else
7474
BUILDCMD=make
7575
fi
7676

77-
build_all() {
78-
type="$1"
79-
CMAKEFLAGS=""
80-
if [ "$type" = "shared" ]; then
81-
SHARED=TRUE
82-
STATIC=FALSE
83-
CMAKEFLAGS="$CMAKEFLAGS -DLIBCXXABI_USE_LLVM_UNWINDER=ON"
84-
else
85-
SHARED=FALSE
86-
STATIC=TRUE
87-
fi
88-
89-
for arch in $ARCHS; do
90-
[ -z "$CLEAN" ] || rm -rf build-$arch-$type
91-
mkdir -p build-$arch-$type
92-
cd build-$arch-$type
93-
cmake \
94-
${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \
95-
-DCMAKE_BUILD_TYPE=Release \
96-
-DCMAKE_INSTALL_PREFIX="$PREFIX/$arch-w64-mingw32" \
97-
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
98-
-DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \
99-
-DCMAKE_CXX_COMPILER_TARGET=$arch-w64-windows-gnu \
100-
-DCMAKE_CROSSCOMPILING=TRUE \
101-
-DCMAKE_SYSTEM_NAME=Windows \
102-
-DCMAKE_C_COMPILER_WORKS=TRUE \
103-
-DCMAKE_CXX_COMPILER_WORKS=TRUE \
104-
-DLLVM_PATH="$LLVM_PATH" \
105-
-DCMAKE_AR="$PREFIX/bin/llvm-ar" \
106-
-DCMAKE_RANLIB="$PREFIX/bin/llvm-ranlib" \
107-
-DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \
108-
-DLIBUNWIND_USE_COMPILER_RT=TRUE \
109-
-DLIBUNWIND_ENABLE_SHARED=$SHARED \
110-
-DLIBUNWIND_ENABLE_STATIC=$STATIC \
111-
-DLIBCXX_USE_COMPILER_RT=ON \
112-
-DLIBCXX_ENABLE_SHARED=$SHARED \
113-
-DLIBCXX_ENABLE_STATIC=$STATIC \
114-
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
115-
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
116-
-DLIBCXX_CXX_ABI=libcxxabi \
117-
-DLIBCXX_LIBDIR_SUFFIX="" \
118-
-DLIBCXX_INCLUDE_TESTS=FALSE \
119-
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=FALSE \
120-
-DLIBCXXABI_USE_COMPILER_RT=ON \
121-
-DLIBCXXABI_ENABLE_SHARED=OFF \
122-
-DLIBCXXABI_LIBDIR_SUFFIX="" \
123-
$CMAKEFLAGS \
124-
..
125-
126-
$BUILDCMD ${CORES+-j$CORES}
127-
$BUILDCMD install
128-
cd ..
129-
done
130-
}
131-
132-
# Build shared first and static afterwards; the headers for static linking also
133-
# work when linking against the DLL, but not vice versa.
134-
[ -z "$BUILD_SHARED" ] || build_all shared
135-
[ -z "$BUILD_STATIC" ] || build_all static
77+
for arch in $ARCHS; do
78+
[ -z "$CLEAN" ] || rm -rf build-$arch
79+
mkdir -p build-$arch
80+
cd build-$arch
81+
cmake \
82+
${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \
83+
-DCMAKE_BUILD_TYPE=Release \
84+
-DCMAKE_INSTALL_PREFIX="$PREFIX/$arch-w64-mingw32" \
85+
-DCMAKE_C_COMPILER=$arch-w64-mingw32-clang \
86+
-DCMAKE_CXX_COMPILER=$arch-w64-mingw32-clang++ \
87+
-DCMAKE_CXX_COMPILER_TARGET=$arch-w64-windows-gnu \
88+
-DCMAKE_CROSSCOMPILING=TRUE \
89+
-DCMAKE_SYSTEM_NAME=Windows \
90+
-DCMAKE_C_COMPILER_WORKS=TRUE \
91+
-DCMAKE_CXX_COMPILER_WORKS=TRUE \
92+
-DLLVM_PATH="$LLVM_PATH" \
93+
-DCMAKE_AR="$PREFIX/bin/llvm-ar" \
94+
-DCMAKE_RANLIB="$PREFIX/bin/llvm-ranlib" \
95+
-DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \
96+
-DLIBUNWIND_USE_COMPILER_RT=TRUE \
97+
-DLIBUNWIND_ENABLE_SHARED=$BUILD_SHARED \
98+
-DLIBUNWIND_ENABLE_STATIC=$BUILD_STATIC \
99+
-DLIBCXX_USE_COMPILER_RT=ON \
100+
-DLIBCXX_ENABLE_SHARED=$BUILD_SHARED \
101+
-DLIBCXX_ENABLE_STATIC=$BUILD_STATIC \
102+
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
103+
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=TRUE \
104+
-DLIBCXX_CXX_ABI=libcxxabi \
105+
-DLIBCXX_LIBDIR_SUFFIX="" \
106+
-DLIBCXX_INCLUDE_TESTS=FALSE \
107+
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=FALSE \
108+
-DLIBCXXABI_USE_COMPILER_RT=ON \
109+
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
110+
-DLIBCXXABI_ENABLE_SHARED=OFF \
111+
-DLIBCXXABI_LIBDIR_SUFFIX="" \
112+
..
113+
114+
$BUILDCMD ${CORES+-j$CORES}
115+
$BUILDCMD install
116+
cd ..
117+
done

0 commit comments

Comments
 (0)