Skip to content

[build] properly install compiler-rt from Xcode toolchain #31247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 63 additions & 49 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,61 @@ function cmake_config_opt() {
fi
}

function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
local clang_dest_dir="$1"

HOST_CXX_DIR=$(dirname "${HOST_CXX}")
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
DEST_LIB_CLANG_DIR="${clang_dest_dir}/lib/clang"

[ -d "${HOST_LIB_CLANG_DIR}" -a -d "${DEST_LIB_CLANG_DIR}" ] || return 0

DEST_CXX_BUILTINS_VERSION=$(ls -1 "${DEST_LIB_CLANG_DIR}")
DEST_BUILTINS_DIR="${clang_dest_dir}/lib/clang/${DEST_CXX_BUILTINS_VERSION}/lib/darwin"

if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."

for OS in ios watchos tvos; do
# Copy over the device .a when necessary
LIB_NAME="libclang_rt.$OS.a"
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
DEST_LIB_PATH="${DEST_BUILTINS_DIR}/${LIB_NAME}"
if [[ ! -f "${DEST_LIB_PATH}" ]]; then
if [[ -f "${HOST_LIB_PATH}" ]]; then
call cp "${HOST_LIB_PATH}" "${DEST_LIB_PATH}"
elif [[ "${VERBOSE_BUILD}" ]]; then
echo "no file exists at ${HOST_LIB_PATH}"
fi
fi

# Copy over the simulator .a when necessary
SIM_LIB_NAME="libclang_rt.${OS}sim.a"
HOST_SIM_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$SIM_LIB_NAME"
DEST_SIM_LIB_PATH="${DEST_BUILTINS_DIR}/${SIM_LIB_NAME}"
if [[ ! -f "${DEST_SIM_LIB_PATH}" ]]; then
if [[ -f "${HOST_SIM_LIB_PATH}" ]]; then
call cp "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
elif [[ -f "${HOST_LIB_PATH}" ]]; then
# The simulator .a might not exist if the host
# Xcode is old. In that case, copy over the
# device library to the simulator location to allow
# clang to find it. The device library has the simulator
# slices in Xcode that doesn't have the simulator .a, so
# the link is still valid.
echo "copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME}"
call cp "${HOST_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
elif [[ "${VERBOSE_BUILD}" ]]; then
echo "no file exists at ${HOST_SIM_LIB_PATH}"
fi
fi
done
done
fi
}

#
# Configure and build each product
#
Expand Down Expand Up @@ -2417,55 +2472,7 @@ for host in "${ALL_HOSTS[@]}"; do
# builtins for iOS/tvOS/watchOS to ensure that Swift's
# stdlib can use compiler-rt builtins when targetting iOS/tvOS/watchOS.
if [[ "${product}" = "llvm" ]] && [[ "${BUILD_LLVM}" = "1" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
HOST_CXX_DIR=$(dirname "${HOST_CXX}")
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
DEST_LIB_CLANG_DIR="$(build_directory_bin ${host} llvm)/../lib/clang"

if [[ -d "${HOST_LIB_CLANG_DIR}" ]] && [[ -d "${DEST_LIB_CLANG_DIR}" ]]; then
DEST_CXX_BUILTINS_VERSION=$(ls "${DEST_LIB_CLANG_DIR}" | awk '{print $0}')
DEST_BUILTINS_DIR="$(build_directory_bin ${host} llvm)/../lib/clang/$DEST_CXX_BUILTINS_VERSION/lib/darwin"

if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."

for OS in ios watchos tvos; do
# Copy over the device .a when necessary
LIB_NAME="libclang_rt.$OS.a"
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
DEST_LIB_PATH="${DEST_BUILTINS_DIR}/${LIB_NAME}"
if [[ ! -f "${DEST_LIB_PATH}" ]]; then
if [[ -f "${HOST_LIB_PATH}" ]]; then
call cp "${HOST_LIB_PATH}" "${DEST_LIB_PATH}"
elif [[ "${VERBOSE_BUILD}" ]]; then
echo "no file exists at ${HOST_LIB_PATH}"
fi
fi
# Copy over the simulator .a when necessary
SIM_LIB_NAME="libclang_rt.${OS}sim.a"
HOST_SIM_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$SIM_LIB_NAME"
DEST_SIM_LIB_PATH="${DEST_BUILTINS_DIR}/${SIM_LIB_NAME}"
if [[ ! -f "${DEST_SIM_LIB_PATH}" ]]; then
if [[ -f "${HOST_SIM_LIB_PATH}" ]]; then
call cp "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
elif [[ -f "${HOST_LIB_PATH}" ]]; then
# The simulator .a might not exist if the host
# Xcode is old. In that case, copy over the
# device library to the simulator location to allow
# clang to find it. The device library has the simulator
# slices in Xcode that doesn't have the simulator .a, so
# the link is still valid.
echo "copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME}"
call cp "${HOST_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
elif [[ "${VERBOSE_BUILD}" ]]; then
echo "no file exists at ${HOST_SIM_LIB_PATH}"
fi
fi
done
done
fi
fi
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "$(build_directory_bin ${host} llvm)/.."
fi
done
done
Expand Down Expand Up @@ -2986,6 +2993,13 @@ for host in "${ALL_HOSTS[@]}"; do
build_dir=$(build_directory ${host} ${product})

call env DESTDIR="${host_install_destdir}" "${CMAKE_BUILD[@]}" "${build_dir}" -- ${INSTALL_TARGETS}

# When we are installing LLVM copy over the compiler-rt
# builtins for iOS/tvOS/watchOS to ensure that we don't
# have linker errors when building apps for such platforms.
if [[ "${product}" = "llvm" ]] && [[ ! -z "${LLVM_INSTALL_COMPONENTS}" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "${host_install_destdir}${host_install_prefix}"
fi
done
done

Expand Down