2020-04-08 15:26:31 -04:00
|
|
|
#!/usr/bin/env bash
|
2024-09-04 16:47:20 -04:00
|
|
|
# ===----------------------------------------------------------------------===##
|
2020-04-08 15:26:31 -04:00
|
|
|
#
|
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#
|
2024-09-04 16:47:20 -04:00
|
|
|
# ===----------------------------------------------------------------------===##
|
2020-04-08 15:26:31 -04:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
PROGNAME="$(basename "${0}")"
|
2020-04-23 13:53:14 -04:00
|
|
|
|
|
|
|
function error() { printf "error: %s\n" "$*"; exit 1; }
|
|
|
|
|
2020-04-08 15:26:31 -04:00
|
|
|
function usage() {
|
|
|
|
cat <<EOF
|
|
|
|
Usage:
|
2020-04-23 13:53:14 -04:00
|
|
|
${PROGNAME} [options]
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2020-04-23 13:53:14 -04:00
|
|
|
[-h|--help] Display this help and exit.
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2020-10-13 12:27:22 -04:00
|
|
|
--llvm-root <DIR> Path to the root of the LLVM monorepo. Only the libcxx
|
2020-04-23 13:53:14 -04:00
|
|
|
and libcxxabi directories are required.
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2020-10-13 12:27:22 -04:00
|
|
|
--build-dir <DIR> Path to the directory to use for building. This will
|
2020-04-23 13:53:14 -04:00
|
|
|
contain intermediate build products.
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2020-10-13 12:27:22 -04:00
|
|
|
--install-dir <DIR> Path to the directory to install the library to.
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2020-10-13 12:27:22 -04:00
|
|
|
--symbols-dir <DIR> Path to the directory to install the .dSYM bundle to.
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2020-04-23 13:53:14 -04:00
|
|
|
--architectures "<arch>..." A whitespace separated list of architectures to build for.
|
|
|
|
The library will be built for each architecture independently,
|
|
|
|
and a universal binary containing all architectures will be
|
|
|
|
created from that.
|
2020-04-08 15:26:31 -04:00
|
|
|
|
2022-02-03 10:57:49 -05:00
|
|
|
--headers-only Only install the header part of the library -- don't actually
|
|
|
|
build the full library.
|
|
|
|
|
2020-04-23 13:53:14 -04:00
|
|
|
--version X[.Y[.Z]] The version of the library to encode in the dylib.
|
2020-04-08 15:26:31 -04:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case ${1} in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--llvm-root)
|
|
|
|
llvm_root="${2}"
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
--build-dir)
|
|
|
|
build_dir="${2}"
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
--symbols-dir)
|
|
|
|
symbols_dir="${2}"
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
--install-dir)
|
|
|
|
install_dir="${2}"
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
--architectures)
|
2020-04-23 13:53:14 -04:00
|
|
|
architectures="${2}"
|
|
|
|
shift; shift
|
2020-04-08 15:26:31 -04:00
|
|
|
;;
|
2022-02-03 10:57:49 -05:00
|
|
|
--headers-only)
|
|
|
|
headers_only=true
|
|
|
|
shift
|
|
|
|
;;
|
2020-04-08 15:26:31 -04:00
|
|
|
--version)
|
|
|
|
version="${2}"
|
|
|
|
shift; shift
|
|
|
|
;;
|
|
|
|
*)
|
2020-04-23 13:53:14 -04:00
|
|
|
error "Unknown argument '${1}'"
|
2020-04-08 15:26:31 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-02-03 10:57:49 -05:00
|
|
|
for arg in llvm_root build_dir symbols_dir install_dir architectures version; do
|
2020-04-08 15:26:31 -04:00
|
|
|
if [ -z ${!arg+x} ]; then
|
2020-04-23 13:53:14 -04:00
|
|
|
error "Missing required argument '--${arg//_/-}'"
|
2020-04-08 15:26:31 -04:00
|
|
|
elif [ "${!arg}" == "" ]; then
|
2020-04-23 13:53:14 -04:00
|
|
|
error "Argument to --${arg//_/-} must not be empty"
|
2020-04-08 15:26:31 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-10-13 12:27:22 -04:00
|
|
|
# Allow using relative paths
|
2020-10-16 12:57:30 -04:00
|
|
|
function realpath() {
|
|
|
|
if [[ $1 = /* ]]; then echo "$1"; else echo "$(pwd)/${1#./}"; fi
|
|
|
|
}
|
2021-06-03 18:26:31 -04:00
|
|
|
for arg in llvm_root build_dir symbols_dir install_dir; do
|
2020-10-13 12:27:22 -04:00
|
|
|
path="$(realpath "${!arg}")"
|
|
|
|
eval "${arg}=\"${path}\""
|
|
|
|
done
|
|
|
|
|
2020-04-08 15:26:31 -04:00
|
|
|
function step() {
|
|
|
|
separator="$(printf "%0.s-" $(seq 1 ${#1}))"
|
|
|
|
echo
|
|
|
|
echo "${separator}"
|
|
|
|
echo "${1}"
|
|
|
|
echo "${separator}"
|
|
|
|
}
|
|
|
|
|
|
|
|
for arch in ${architectures}; do
|
2023-03-18 13:34:29 -04:00
|
|
|
# Construct the target-triple that we're testing for. Otherwise, the target triple is currently detected
|
|
|
|
# as <arch>-apple-darwin<version> instead of <arch>-apple-macosx<version>, which trips up the test suite.
|
|
|
|
# TODO: This shouldn't be necessary anymore if `clang -print-target-triple` behaved properly, see https://llvm.org/PR61762.
|
|
|
|
# Then LLVM would guess the LLVM_DEFAULT_TARGET_TRIPLE properly and we wouldn't have to specify it.
|
|
|
|
target=$(xcrun clang -arch ${arch} -xc - -### 2>&1 | grep --only-matching -E '"-triple" ".+?"' | grep --only-matching -E '"[^ ]+-apple-[^ ]+?"' | tr -d '"')
|
|
|
|
|
2020-04-08 15:26:31 -04:00
|
|
|
mkdir -p "${build_dir}/${arch}"
|
[libc++] Allow testing Apple's system library as it is installed (#99086)
In order to test libc++ under the "Apple System Library" configuration,
we need to run the tests using DYLD_LIBRARY_PATH. This is required
because libc++ gets an install_name of /usr/lib when built as a system
library, which means that we must override the copy of libc++ used by
the whole process. This effectively reverts 2cf2f1b, which was the wrong
solution for the problem I was having.
Of course, this assumes that the just-built libc++ is sufficient to
replace the system library, which is not actually the case
out-of-the-box. Indeed, the system library contains a few symbols that
are not provided by the upstream library, leading to undefined symbols
when replacing the system library by the just-built one.
To solve this problem, we separately build shims that provide those
missing symbols and we manually link against them when we build
executables in the tests. While this is somewhat brittle, it provides a
localized and unintrusive way to allow testing the Apple system
configuration in an upstream environment, which has been a frequent
request.
2024-07-18 15:49:07 -05:00
|
|
|
|
|
|
|
step "Building shims to make libc++ compatible with the system libc++ on Apple platforms when running the tests"
|
|
|
|
shims_library="${build_dir}/${arch}/apple-system-shims.a"
|
2024-07-17 14:46:35 -04:00
|
|
|
# Note that this doesn't need to match the Standard version used to build the rest of the library.
|
[libc++] Allow testing Apple's system library as it is installed (#99086)
In order to test libc++ under the "Apple System Library" configuration,
we need to run the tests using DYLD_LIBRARY_PATH. This is required
because libc++ gets an install_name of /usr/lib when built as a system
library, which means that we must override the copy of libc++ used by
the whole process. This effectively reverts 2cf2f1b, which was the wrong
solution for the problem I was having.
Of course, this assumes that the just-built libc++ is sufficient to
replace the system library, which is not actually the case
out-of-the-box. Indeed, the system library contains a few symbols that
are not provided by the upstream library, leading to undefined symbols
when replacing the system library by the just-built one.
To solve this problem, we separately build shims that provide those
missing symbols and we manually link against them when we build
executables in the tests. While this is somewhat brittle, it provides a
localized and unintrusive way to allow testing the Apple system
configuration in an upstream environment, which has been a frequent
request.
2024-07-18 15:49:07 -05:00
|
|
|
xcrun clang++ -c -std=c++2b -target ${target} "${llvm_root}/libcxxabi/src/vendor/apple/shims.cpp" -static -o "${shims_library}"
|
|
|
|
|
|
|
|
step "Building libc++.dylib and libc++abi.dylib for architecture ${arch}"
|
2022-02-03 10:57:49 -05:00
|
|
|
xcrun cmake -S "${llvm_root}/runtimes" \
|
|
|
|
-B "${build_dir}/${arch}" \
|
|
|
|
-GNinja \
|
|
|
|
-DCMAKE_MAKE_PROGRAM="$(xcrun --find ninja)" \
|
|
|
|
-C "${llvm_root}/libcxx/cmake/caches/Apple.cmake" \
|
|
|
|
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
|
|
|
|
-DCMAKE_INSTALL_PREFIX="${build_dir}/${arch}-install" \
|
|
|
|
-DCMAKE_OSX_ARCHITECTURES="${arch}" \
|
2023-03-18 12:10:31 -04:00
|
|
|
-DLIBCXXABI_LIBRARY_VERSION="${version}" \
|
2023-03-18 13:34:29 -04:00
|
|
|
-DLIBCXX_LIBRARY_VERSION="${version}" \
|
[libc++] Allow testing Apple's system library as it is installed (#99086)
In order to test libc++ under the "Apple System Library" configuration,
we need to run the tests using DYLD_LIBRARY_PATH. This is required
because libc++ gets an install_name of /usr/lib when built as a system
library, which means that we must override the copy of libc++ used by
the whole process. This effectively reverts 2cf2f1b, which was the wrong
solution for the problem I was having.
Of course, this assumes that the just-built libc++ is sufficient to
replace the system library, which is not actually the case
out-of-the-box. Indeed, the system library contains a few symbols that
are not provided by the upstream library, leading to undefined symbols
when replacing the system library by the just-built one.
To solve this problem, we separately build shims that provide those
missing symbols and we manually link against them when we build
executables in the tests. While this is somewhat brittle, it provides a
localized and unintrusive way to allow testing the Apple system
configuration in an upstream environment, which has been a frequent
request.
2024-07-18 15:49:07 -05:00
|
|
|
-DLIBCXX_TEST_PARAMS="target_triple=${target};apple_system_shims=${shims_library}" \
|
|
|
|
-DLIBCXXABI_TEST_PARAMS="target_triple=${target};apple_system_shims=${shims_library}" \
|
|
|
|
-DLIBUNWIND_TEST_PARAMS="target_triple=${target};apple_system_shims=${shims_library}"
|
2022-02-03 10:57:49 -05:00
|
|
|
|
|
|
|
if [ "$headers_only" = true ]; then
|
2022-06-10 15:10:26 -04:00
|
|
|
xcrun cmake --build "${build_dir}/${arch}" --target install-cxx-headers install-cxxabi-headers -- -v
|
2022-02-03 10:57:49 -05:00
|
|
|
else
|
|
|
|
xcrun cmake --build "${build_dir}/${arch}" --target install-cxx install-cxxabi -- -v
|
|
|
|
fi
|
2020-04-08 15:26:31 -04:00
|
|
|
done
|
|
|
|
|
2020-06-04 10:32:16 -04:00
|
|
|
function universal_dylib() {
|
|
|
|
dylib=${1}
|
|
|
|
|
|
|
|
inputs=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/${dylib}"; done)
|
|
|
|
|
|
|
|
step "Creating a universal dylib ${dylib} from the dylibs for all architectures"
|
2022-02-03 10:57:49 -05:00
|
|
|
xcrun lipo -create ${inputs} -output "${build_dir}/${dylib}"
|
2020-06-04 10:32:16 -04:00
|
|
|
|
|
|
|
step "Installing the (stripped) universal dylib to ${install_dir}/usr/lib"
|
|
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
|
|
cp "${build_dir}/${dylib}" "${install_dir}/usr/lib/${dylib}"
|
2022-02-03 10:57:49 -05:00
|
|
|
xcrun strip -S "${install_dir}/usr/lib/${dylib}"
|
2020-06-04 10:32:16 -04:00
|
|
|
|
|
|
|
step "Installing the unstripped dylib and the dSYM bundle to ${symbols_dir}"
|
2022-02-03 10:57:49 -05:00
|
|
|
xcrun dsymutil "${build_dir}/${dylib}" -o "${symbols_dir}/${dylib}.dSYM"
|
2020-06-04 10:32:16 -04:00
|
|
|
cp "${build_dir}/${dylib}" "${symbols_dir}/${dylib}"
|
|
|
|
}
|
|
|
|
|
2022-02-03 10:57:49 -05:00
|
|
|
if [ "$headers_only" != true ]; then
|
|
|
|
universal_dylib libc++.1.dylib
|
|
|
|
universal_dylib libc++abi.dylib
|
|
|
|
(cd "${install_dir}/usr/lib" && ln -s "libc++.1.dylib" libc++.dylib)
|
2023-03-18 11:57:24 -04:00
|
|
|
|
|
|
|
experimental_libs=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++experimental.a"; done)
|
|
|
|
xcrun lipo -create ${experimental_libs} -output "${install_dir}/usr/lib/libc++experimental.a"
|
2022-02-03 10:57:49 -05:00
|
|
|
fi
|
2020-04-08 15:26:31 -04:00
|
|
|
|
|
|
|
# Install the headers by copying the headers from one of the built architectures
|
|
|
|
# into the install directory. Headers from all architectures should be the same.
|
2021-06-03 18:26:31 -04:00
|
|
|
step "Installing the libc++ and libc++abi headers to ${install_dir}/usr/include"
|
2020-04-08 15:26:31 -04:00
|
|
|
any_arch=$(echo ${architectures} | cut -d ' ' -f 1)
|
2021-06-03 18:26:31 -04:00
|
|
|
mkdir -p "${install_dir}/usr/include"
|
|
|
|
ditto "${build_dir}/${any_arch}-install/include" "${install_dir}/usr/include"
|
2020-06-04 10:32:16 -04:00
|
|
|
if [[ $EUID -eq 0 ]]; then # Only chown if we're running as root
|
2021-06-03 18:26:31 -04:00
|
|
|
chown -R root:wheel "${install_dir}/usr/include"
|
2020-06-04 10:32:16 -04:00
|
|
|
fi
|
|
|
|
|
2022-02-03 10:57:49 -05:00
|
|
|
if [ "$headers_only" != true ]; then
|
|
|
|
step "Installing the libc++ and libc++abi licenses"
|
|
|
|
mkdir -p "${install_dir}/usr/local/OpenSourceLicenses"
|
|
|
|
cp "${llvm_root}/libcxx/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxx.txt"
|
|
|
|
cp "${llvm_root}/libcxxabi/LICENSE.TXT" "${install_dir}/usr/local/OpenSourceLicenses/libcxxabi.txt"
|
|
|
|
|
|
|
|
# Also install universal static archives for libc++ and libc++abi
|
|
|
|
libcxx_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++.a"; done)
|
|
|
|
libcxxabi_archives=$(for arch in ${architectures}; do echo "${build_dir}/${arch}-install/lib/libc++abi.a"; done)
|
|
|
|
step "Creating universal static archives for libc++ and libc++abi from the static archives for each architecture"
|
|
|
|
mkdir -p "${install_dir}/usr/local/lib/libcxx"
|
|
|
|
xcrun libtool -static ${libcxx_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++-static.a"
|
|
|
|
xcrun libtool -static ${libcxxabi_archives} -o "${install_dir}/usr/local/lib/libcxx/libc++abi-static.a"
|
|
|
|
fi
|