Skip to content

Commit 2ee8fe4

Browse files
authored
[5.3][build] properly install compiler-rt from Xcode toolchain (#34236)
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 Cherry-pick of #31247 -- this also brings in the improvements from #34049
1 parent a675720 commit 2ee8fe4

File tree

1 file changed

+63
-43
lines changed

1 file changed

+63
-43
lines changed

utils/build-script-impl

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,61 @@ function cmake_config_opt() {
13801380
fi
13811381
}
13821382

1383+
function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
1384+
local clang_dest_dir="$1"
1385+
1386+
HOST_CXX_DIR=$(dirname "${HOST_CXX}")
1387+
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
1388+
DEST_LIB_CLANG_DIR="${clang_dest_dir}/lib/clang"
1389+
1390+
[ -d "${HOST_LIB_CLANG_DIR}" -a -d "${DEST_LIB_CLANG_DIR}" ] || return 0
1391+
1392+
DEST_CXX_BUILTINS_VERSION=$(ls -1 "${DEST_LIB_CLANG_DIR}")
1393+
DEST_BUILTINS_DIR="${clang_dest_dir}/lib/clang/${DEST_CXX_BUILTINS_VERSION}/lib/darwin"
1394+
1395+
if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
1396+
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
1397+
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
1398+
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."
1399+
1400+
for OS in ios watchos tvos; do
1401+
# Copy over the device .a when necessary
1402+
LIB_NAME="libclang_rt.$OS.a"
1403+
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
1404+
DEST_LIB_PATH="${DEST_BUILTINS_DIR}/${LIB_NAME}"
1405+
if [[ ! -f "${DEST_LIB_PATH}" ]]; then
1406+
if [[ -f "${HOST_LIB_PATH}" ]]; then
1407+
call cp "${HOST_LIB_PATH}" "${DEST_LIB_PATH}"
1408+
elif [[ "${VERBOSE_BUILD}" ]]; then
1409+
echo "no file exists at ${HOST_LIB_PATH}"
1410+
fi
1411+
fi
1412+
1413+
# Copy over the simulator .a when necessary
1414+
SIM_LIB_NAME="libclang_rt.${OS}sim.a"
1415+
HOST_SIM_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$SIM_LIB_NAME"
1416+
DEST_SIM_LIB_PATH="${DEST_BUILTINS_DIR}/${SIM_LIB_NAME}"
1417+
if [[ ! -f "${DEST_SIM_LIB_PATH}" ]]; then
1418+
if [[ -f "${HOST_SIM_LIB_PATH}" ]]; then
1419+
call cp "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
1420+
elif [[ -f "${HOST_LIB_PATH}" ]]; then
1421+
# The simulator .a might not exist if the host
1422+
# Xcode is old. In that case, copy over the
1423+
# device library to the simulator location to allow
1424+
# clang to find it. The device library has the simulator
1425+
# slices in Xcode that doesn't have the simulator .a, so
1426+
# the link is still valid.
1427+
echo "copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME}"
1428+
call cp "${HOST_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
1429+
elif [[ "${VERBOSE_BUILD}" ]]; then
1430+
echo "no file exists at ${HOST_SIM_LIB_PATH}"
1431+
fi
1432+
fi
1433+
done
1434+
done
1435+
fi
1436+
}
1437+
13831438
#
13841439
# Configure and build each product
13851440
#
@@ -2349,49 +2404,7 @@ for host in "${ALL_HOSTS[@]}"; do
23492404
# builtins for iOS/tvOS/watchOS to ensure that Swift's
23502405
# stdlib can use compiler-rt builtins when targetting iOS/tvOS/watchOS.
23512406
if [[ "${product}" = "llvm" ]] && [[ "${BUILD_LLVM}" = "1" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
2352-
HOST_CXX_DIR=$(dirname "${HOST_CXX}")
2353-
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
2354-
DEST_LIB_CLANG_DIR="$(build_directory_bin ${host} llvm)/../lib/clang"
2355-
2356-
if [[ -d "${HOST_LIB_CLANG_DIR}" ]] && [[ -d "${DEST_LIB_CLANG_DIR}" ]]; then
2357-
DEST_CXX_BUILTINS_VERSION=$(ls "${DEST_LIB_CLANG_DIR}" | awk '{print $0}')
2358-
DEST_BUILTINS_DIR="$(build_directory_bin ${host} llvm)/../lib/clang/$DEST_CXX_BUILTINS_VERSION/lib/darwin"
2359-
2360-
if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
2361-
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
2362-
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
2363-
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."
2364-
2365-
for OS in ios watchos tvos; do
2366-
# Copy over the device .a
2367-
LIB_NAME="libclang_rt.$OS.a"
2368-
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
2369-
if [[ -f "${HOST_LIB_PATH}" ]]; then
2370-
call cp "${HOST_LIB_PATH}" "${DEST_BUILTINS_DIR}/${LIB_NAME}"
2371-
elif [[ "${VERBOSE_BUILD}" ]]; then
2372-
echo "no file exists at ${HOST_LIB_PATH}"
2373-
fi
2374-
# Copy over the simulator .a
2375-
SIM_LIB_NAME="libclang_rt.${OS}sim.a"
2376-
HOST_SIM_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$SIM_LIB_NAME"
2377-
if [[ -f "${HOST_SIM_LIB_PATH}" ]]; then
2378-
call cp "${HOST_SIM_LIB_PATH}" "${DEST_BUILTINS_DIR}/${SIM_LIB_NAME}"
2379-
elif [[ -f "${HOST_LIB_PATH}" ]]; then
2380-
# The simulator .a might not exist if the host
2381-
# Xcode is old. In that case, copy over the
2382-
# device library to the simulator location to allow
2383-
# clang to find it. The device library has the simulator
2384-
# slices in Xcode that doesn't have the simulator .a, so
2385-
# the link is still valid.
2386-
echo "copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME}"
2387-
call cp "${HOST_LIB_PATH}" "${DEST_BUILTINS_DIR}/${SIM_LIB_NAME}"
2388-
elif [[ "${VERBOSE_BUILD}" ]]; then
2389-
echo "no file exists at ${HOST_SIM_LIB_PATH}"
2390-
fi
2391-
done
2392-
done
2393-
fi
2394-
fi
2407+
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "$(build_directory_bin ${host} llvm)/.."
23952408
fi
23962409
done
23972410
done
@@ -2908,6 +2921,13 @@ for host in "${ALL_HOSTS[@]}"; do
29082921
build_dir=$(build_directory ${host} ${product})
29092922

29102923
call env DESTDIR="${host_install_destdir}" "${CMAKE_BUILD[@]}" "${build_dir}" -- ${INSTALL_TARGETS}
2924+
2925+
# When we are installing LLVM copy over the compiler-rt
2926+
# builtins for iOS/tvOS/watchOS to ensure that we don't
2927+
# have linker errors when building apps for such platforms.
2928+
if [[ "${product}" = "llvm" ]] && [[ ! -z "${LLVM_INSTALL_COMPONENTS}" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
2929+
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "${host_install_destdir}${host_install_prefix}"
2930+
fi
29112931
done
29122932
done
29132933

0 commit comments

Comments
 (0)