Skip to content

Commit 3894e37

Browse files
committed
[build] properly install compiler-rt from Xcode toolchain
Similarly to what was done for #25547, copy the compiler-rt built-ins for embedded platforms from the Xcode toolchain into the new generated one, so to avoid link time errors. Addresses SR-12001, rdar://57837918
1 parent 4cd68ed commit 3894e37

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

utils/build-script-impl

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,36 @@ function cmake_config_opt() {
12811281
fi
12821282
}
12831283

1284+
function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
1285+
local clang_dest_dir=$1
1286+
1287+
HOST_CXX_DIR=$(dirname "${HOST_CXX}")
1288+
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
1289+
DEST_LIB_CLANG_DIR="${clang_dest_dir}/lib/clang"
1290+
1291+
if [[ -d "${HOST_LIB_CLANG_DIR}" ]] && [[ -d "${DEST_LIB_CLANG_DIR}" ]]; then
1292+
DEST_CXX_BUILTINS_VERSION=$(ls "${DEST_LIB_CLANG_DIR}" | awk '{print $0}')
1293+
DEST_BUILTINS_DIR="${clang_dest_dir}/lib/clang/$DEST_CXX_BUILTINS_VERSION/lib/darwin"
1294+
1295+
if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
1296+
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
1297+
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
1298+
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."
1299+
1300+
for OS in ios watchos tvos; do
1301+
LIB_NAME="libclang_rt.$OS.a"
1302+
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
1303+
if [[ -f "${HOST_LIB_PATH}" ]]; then
1304+
call cp "${HOST_LIB_PATH}" "${DEST_BUILTINS_DIR}/${LIB_NAME}"
1305+
elif [[ "${VERBOSE_BUILD}" ]]; then
1306+
echo "no file exists at ${HOST_LIB_PATH}"
1307+
fi
1308+
done
1309+
done
1310+
fi
1311+
fi
1312+
}
1313+
12841314
#
12851315
# Configure and build each product
12861316
#
@@ -2249,31 +2279,7 @@ for host in "${ALL_HOSTS[@]}"; do
22492279
# builtins for iOS/tvOS/watchOS to ensure that Swift's
22502280
# stdlib can use compiler-rt builtins when targetting iOS/tvOS/watchOS.
22512281
if [[ "${product}" = "llvm" ]] && [[ "${BUILD_LLVM}" = "1" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
2252-
HOST_CXX_DIR=$(dirname "${HOST_CXX}")
2253-
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
2254-
DEST_LIB_CLANG_DIR="$(build_directory_bin ${host} llvm)/../lib/clang"
2255-
2256-
if [[ -d "${HOST_LIB_CLANG_DIR}" ]] && [[ -d "${DEST_LIB_CLANG_DIR}" ]]; then
2257-
DEST_CXX_BUILTINS_VERSION=$(ls "${DEST_LIB_CLANG_DIR}" | awk '{print $0}')
2258-
DEST_BUILTINS_DIR="$(build_directory_bin ${host} llvm)/../lib/clang/$DEST_CXX_BUILTINS_VERSION/lib/darwin"
2259-
2260-
if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
2261-
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
2262-
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
2263-
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."
2264-
2265-
for OS in ios watchos tvos; do
2266-
LIB_NAME="libclang_rt.$OS.a"
2267-
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
2268-
if [[ -f "${HOST_LIB_PATH}" ]]; then
2269-
call cp "${HOST_LIB_PATH}" "${DEST_BUILTINS_DIR}/${LIB_NAME}"
2270-
elif [[ "${VERBOSE_BUILD}" ]]; then
2271-
echo "no file exists at ${HOST_LIB_PATH}"
2272-
fi
2273-
done
2274-
done
2275-
fi
2276-
fi
2282+
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "$(build_directory_bin ${host} llvm)/.."
22772283
fi
22782284
done
22792285
done
@@ -2780,6 +2786,13 @@ for host in "${ALL_HOSTS[@]}"; do
27802786
build_dir=$(build_directory ${host} ${product})
27812787

27822788
call env DESTDIR="${host_install_destdir}" "${CMAKE_BUILD[@]}" "${build_dir}" -- ${INSTALL_TARGETS}
2789+
2790+
# When we are installing LLVM copy over the compiler-rt
2791+
# builtins for iOS/tvOS/watchOS to ensure that we don't
2792+
# have compiler crashes when building apps for such platforms.
2793+
if [[ "${product}" = "llvm" ]] && [[ ! -z "${LLVM_INSTALL_COMPONENTS}" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
2794+
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "${host_install_destdir}${host_install_prefix}"
2795+
fi
27832796
done
27842797
done
27852798

0 commit comments

Comments
 (0)