Skip to content

Commit 1b06d2c

Browse files
committed
[libc++] Refactor the Apple build scripts
This patch upstreams some changes we've made internally to how we're building the libc++ dylib on Apple platforms. The goal is still to eventually get rid of `apple-install-libcxx.sh` entirely and have a proper way to mirror what we do internally with just the normal CMake configuration. Differential Revision: https://reviews.llvm.org/D118912
1 parent 259c58d commit 1b06d2c

File tree

3 files changed

+56
-53
lines changed

3 files changed

+56
-53
lines changed

libcxx/cmake/caches/Apple.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ set(LIBCXXABI_HERMETIC_STATIC_LIBRARY ON CACHE BOOL "")
1919
set(LIBCXXABI_ENABLE_ASSERTIONS OFF CACHE BOOL "")
2020
set(LIBCXXABI_ENABLE_FORGIVING_DYNAMIC_CAST ON CACHE BOOL "")
2121

22+
set(LIBCXX_TEST_CONFIG "apple-libc++-shared.cfg.in" CACHE STRING "")
23+
set(LIBCXXABI_TEST_CONFIG "apple-libc++abi-shared.cfg.in" CACHE STRING "")
2224
set(LIBCXX_TEST_PARAMS "stdlib=apple-libc++" CACHE STRING "")
2325
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")

libcxx/utils/ci/apple-install-libcxx.sh

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ ${PROGNAME} [options]
3030
3131
--symbols-dir <DIR> Path to the directory to install the .dSYM bundle to.
3232
33-
--sdk <SDK> SDK used for building the library. This represents
34-
the target platform that the library will run on.
35-
You can get a list of SDKs with \`xcodebuild -showsdks\`.
36-
3733
--architectures "<arch>..." A whitespace separated list of architectures to build for.
3834
The library will be built for each architecture independently,
3935
and a universal binary containing all architectures will be
4036
created from that.
4137
38+
--headers-only Only install the header part of the library -- don't actually
39+
build the full library.
40+
4241
--version X[.Y[.Z]] The version of the library to encode in the dylib.
4342
EOF
4443
}
@@ -65,14 +64,14 @@ while [[ $# -gt 0 ]]; do
6564
install_dir="${2}"
6665
shift; shift
6766
;;
68-
--sdk)
69-
sdk="${2}"
70-
shift; shift
71-
;;
7267
--architectures)
7368
architectures="${2}"
7469
shift; shift
7570
;;
71+
--headers-only)
72+
headers_only=true
73+
shift
74+
;;
7675
--version)
7776
version="${2}"
7877
shift; shift
@@ -83,7 +82,7 @@ while [[ $# -gt 0 ]]; do
8382
esac
8483
done
8584

86-
for arg in llvm_root build_dir symbols_dir install_dir sdk architectures version; do
85+
for arg in llvm_root build_dir symbols_dir install_dir architectures version; do
8786
if [ -z ${!arg+x} ]; then
8887
error "Missing required argument '--${arg//_/-}'"
8988
elif [ "${!arg}" == "" ]; then
@@ -111,22 +110,22 @@ function step() {
111110
for arch in ${architectures}; do
112111
step "Building libc++.dylib and libc++abi.dylib for architecture ${arch}"
113112
mkdir -p "${build_dir}/${arch}"
114-
(cd "${build_dir}/${arch}" &&
115-
xcrun --sdk "${sdk}" cmake "${llvm_root}/runtimes" \
116-
-GNinja \
117-
-DCMAKE_MAKE_PROGRAM="$(xcrun --sdk "${sdk}" --find ninja)" \
118-
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
119-
-C "${llvm_root}/libcxx/cmake/caches/Apple.cmake" \
120-
-DCMAKE_INSTALL_PREFIX="${build_dir}/${arch}-install" \
121-
-DCMAKE_INSTALL_NAME_DIR="/usr/lib" \
122-
-DCMAKE_OSX_ARCHITECTURES="${arch}" \
123-
-DLIBCXXABI_LIBRARY_VERSION="${version}" \
124-
-DLIBCXX_INCLUDE_BENCHMARKS=OFF \
125-
-DLIBCXX_TEST_CONFIG="apple-libc++-shared.cfg.in" \
126-
-DLIBCXXABI_TEST_CONFIG="apple-libc++abi-shared.cfg.in"
127-
)
128-
129-
xcrun --sdk "${sdk}" cmake --build "${build_dir}/${arch}" --target install-cxx install-cxxabi -- -v
113+
xcrun cmake -S "${llvm_root}/runtimes" \
114+
-B "${build_dir}/${arch}" \
115+
-GNinja \
116+
-DCMAKE_MAKE_PROGRAM="$(xcrun --find ninja)" \
117+
-C "${llvm_root}/libcxx/cmake/caches/Apple.cmake" \
118+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
119+
-DCMAKE_INSTALL_PREFIX="${build_dir}/${arch}-install" \
120+
-DCMAKE_INSTALL_NAME_DIR="/usr/lib" \
121+
-DCMAKE_OSX_ARCHITECTURES="${arch}" \
122+
-DLIBCXXABI_LIBRARY_VERSION="${version}"
123+
124+
if [ "$headers_only" = true ]; then
125+
xcrun cmake --build "${build_dir}/${arch}" --target install-cxx-headers -- -v
126+
else
127+
xcrun cmake --build "${build_dir}/${arch}" --target install-cxx install-cxxabi -- -v
128+
fi
130129
done
131130

132131
function universal_dylib() {
@@ -135,21 +134,23 @@ function universal_dylib() {
135134
inputs=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/${dylib}"; done)
136135

137136
step "Creating a universal dylib ${dylib} from the dylibs for all architectures"
138-
xcrun --sdk "${sdk}" lipo -create ${inputs} -output "${build_dir}/${dylib}"
137+
xcrun lipo -create ${inputs} -output "${build_dir}/${dylib}"
139138

140139
step "Installing the (stripped) universal dylib to ${install_dir}/usr/lib"
141140
mkdir -p "${install_dir}/usr/lib"
142141
cp "${build_dir}/${dylib}" "${install_dir}/usr/lib/${dylib}"
143-
xcrun --sdk "${sdk}" strip -S "${install_dir}/usr/lib/${dylib}"
142+
xcrun strip -S "${install_dir}/usr/lib/${dylib}"
144143

145144
step "Installing the unstripped dylib and the dSYM bundle to ${symbols_dir}"
146-
xcrun --sdk "${sdk}" dsymutil "${build_dir}/${dylib}" -o "${symbols_dir}/${dylib}.dSYM"
145+
xcrun dsymutil "${build_dir}/${dylib}" -o "${symbols_dir}/${dylib}.dSYM"
147146
cp "${build_dir}/${dylib}" "${symbols_dir}/${dylib}"
148147
}
149148

150-
universal_dylib libc++.1.dylib
151-
universal_dylib libc++abi.dylib
152-
(cd "${install_dir}/usr/lib" && ln -s "libc++.1.dylib" libc++.dylib)
149+
if [ "$headers_only" != true ]; then
150+
universal_dylib libc++.1.dylib
151+
universal_dylib libc++abi.dylib
152+
(cd "${install_dir}/usr/lib" && ln -s "libc++.1.dylib" libc++.dylib)
153+
fi
153154

154155
# Install the headers by copying the headers from one of the built architectures
155156
# into the install directory. Headers from all architectures should be the same.
@@ -162,15 +163,17 @@ if [[ $EUID -eq 0 ]]; then # Only chown if we're running as root
162163
chown -R root:wheel "${install_dir}/usr/include"
163164
fi
164165

165-
step "Installing the libc++ and libc++abi licenses"
166-
mkdir -p "${install_dir}/usr/local/OpenSourceLicenses"
167-
cp "${llvm_root}/libcxx/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxx.txt"
168-
cp "${llvm_root}/libcxxabi/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxxabi.txt"
169-
170-
# Also install universal static archives for libc++ and libc++abi
171-
libcxx_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++.a"; done)
172-
libcxxabi_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++abi.a"; done)
173-
step "Creating universal static archives for libc++ and libc++abi from the static archives for each architecture"
174-
mkdir -p "${install_dir}/usr/local/lib/libcxx"
175-
xcrun --sdk "${sdk}" libtool -static ${libcxx_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++-static.a"
176-
xcrun --sdk "${sdk}" libtool -static ${libcxxabi_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++abi-static.a"
166+
if [ "$headers_only" != true ]; then
167+
step "Installing the libc++ and libc++abi licenses"
168+
mkdir -p "${install_dir}/usr/local/OpenSourceLicenses"
169+
cp "${llvm_root}/libcxx/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxx.txt"
170+
cp "${llvm_root}/libcxxabi/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxxabi.txt"
171+
172+
# Also install universal static archives for libc++ and libc++abi
173+
libcxx_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++.a"; done)
174+
libcxxabi_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++abi.a"; done)
175+
step "Creating universal static archives for libc++ and libc++abi from the static archives for each architecture"
176+
mkdir -p "${install_dir}/usr/local/lib/libcxx"
177+
xcrun libtool -static ${libcxx_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++-static.a"
178+
xcrun libtool -static ${libcxxabi_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++abi-static.a"
179+
fi

libcxx/utils/ci/run-buildbot

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,15 @@ generic-abi-unstable)
416416
apple-system)
417417
clean
418418

419-
sdk_root="$(xcrun --sdk macosx --show-sdk-path)"
420419
arch="$(uname -m)"
421-
422-
${MONOREPO_ROOT}/libcxx/utils/ci/apple-install-libcxx.sh \
423-
--llvm-root ${MONOREPO_ROOT} \
424-
--build-dir ${BUILD_DIR} \
425-
--install-dir ${INSTALL_DIR} \
426-
--symbols-dir "${BUILD_DIR}/symbols" \
427-
--sdk "macosx" \
428-
--architectures "${arch}" \
429-
--version "999.99"
420+
xcrun --sdk macosx \
421+
${MONOREPO_ROOT}/libcxx/utils/ci/apple-install-libcxx.sh \
422+
--llvm-root ${MONOREPO_ROOT} \
423+
--build-dir ${BUILD_DIR} \
424+
--install-dir ${INSTALL_DIR} \
425+
--symbols-dir "${BUILD_DIR}/symbols" \
426+
--architectures "${arch}" \
427+
--version "999.99"
430428

431429
# TODO: It would be better to run the tests against the fake-installed version of libc++ instead
432430
xcrun --sdk macosx ninja -vC "${BUILD_DIR}/${arch}" check-cxx check-cxxabi check-cxx-abilist

0 commit comments

Comments
 (0)