Skip to content

Commit 38bcffa

Browse files
committed
[embedded] When copying clang builtins from host toolchain, include macho_embedded libraries
1 parent d35dcc8 commit 38bcffa

File tree

2 files changed

+12
-89
lines changed

2 files changed

+12
-89
lines changed

utils/build-script-impl

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,95 +1437,6 @@ function cmake_config_opt() {
14371437
fi
14381438
}
14391439

1440-
function copy_lib_stripping_architecture() {
1441-
local source="$1"
1442-
local dest="$2"
1443-
local arch="$3"
1444-
1445-
# An alternative approach would be to use || to first
1446-
# attempt the removal of the slice and fall back to the
1447-
# copy when failing.
1448-
# However, this would leave unneeded error messages in the logs
1449-
# that may hinder investigation; in addition, in this scenario
1450-
# the `call` function seems to not propagate correctly failure
1451-
# exit codes.
1452-
if lipo -archs "${source}" | grep -q "${arch}"; then
1453-
call lipo -remove "${arch}" "${source}" -output "${dest}"
1454-
else
1455-
call cp "${source}" "${dest}"
1456-
fi
1457-
}
1458-
1459-
function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
1460-
local clang_dest_dir="$1"
1461-
1462-
HOST_CXX_DIR=$(dirname "${HOST_CXX}")
1463-
HOST_LIB_CLANG_DIR="${HOST_CXX_DIR}/../lib/clang"
1464-
DEST_LIB_CLANG_DIR="${clang_dest_dir}/lib/clang"
1465-
1466-
[ -d "${HOST_LIB_CLANG_DIR}" -a -d "${DEST_LIB_CLANG_DIR}" ] || return 0
1467-
1468-
DEST_CXX_BUILTINS_VERSION=$(ls -1 "${DEST_LIB_CLANG_DIR}")
1469-
DEST_BUILTINS_DIR="${clang_dest_dir}/lib/clang/${DEST_CXX_BUILTINS_VERSION}/lib/darwin"
1470-
1471-
if [[ -d "${DEST_BUILTINS_DIR}" ]]; then
1472-
for HOST_CXX_BUILTINS_PATH in "${HOST_LIB_CLANG_DIR}"/*; do
1473-
HOST_CXX_BUILTINS_DIR="${HOST_CXX_BUILTINS_PATH}/lib/darwin"
1474-
echo "copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR}."
1475-
1476-
for OS in ios watchos tvos; do
1477-
# Copy over the device .a when necessary
1478-
LIB_NAME="libclang_rt.$OS.a"
1479-
HOST_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$LIB_NAME"
1480-
DEST_LIB_PATH="${DEST_BUILTINS_DIR}/${LIB_NAME}"
1481-
if [[ ! -f "${DEST_LIB_PATH}" ]]; then
1482-
if [[ -f "${HOST_LIB_PATH}" ]]; then
1483-
if [[ "$OS" == "tvos" ]]; then
1484-
# This is to avoid strip failures when generating a toolchain
1485-
copy_lib_stripping_architecture "${HOST_LIB_PATH}" "${DEST_LIB_PATH}" i386
1486-
else
1487-
call cp "${HOST_LIB_PATH}" "${DEST_LIB_PATH}"
1488-
fi
1489-
elif [[ "${VERBOSE_BUILD}" ]]; then
1490-
echo "no file exists at ${HOST_LIB_PATH}"
1491-
fi
1492-
fi
1493-
1494-
# Copy over the simulator .a when necessary
1495-
SIM_LIB_NAME="libclang_rt.${OS}sim.a"
1496-
HOST_SIM_LIB_PATH="$HOST_CXX_BUILTINS_DIR/$SIM_LIB_NAME"
1497-
DEST_SIM_LIB_PATH="${DEST_BUILTINS_DIR}/${SIM_LIB_NAME}"
1498-
if [[ ! -f "${DEST_SIM_LIB_PATH}" ]]; then
1499-
if [[ -f "${HOST_SIM_LIB_PATH}" ]]; then
1500-
if [[ "$OS" == "tvos" ]]; then
1501-
# This is to avoid strip failures when generating a toolchain
1502-
copy_lib_stripping_architecture "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}" i386
1503-
else
1504-
call cp "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
1505-
fi
1506-
elif [[ -f "${HOST_LIB_PATH}" ]]; then
1507-
# The simulator .a might not exist if the host
1508-
# Xcode is old. In that case, copy over the
1509-
# device library to the simulator location to allow
1510-
# clang to find it. The device library has the simulator
1511-
# slices in Xcode that doesn't have the simulator .a, so
1512-
# the link is still valid.
1513-
echo "copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME}"
1514-
if [[ "$OS" == "tvos" ]]; then
1515-
echo "Remove i386 from tvOS ${DEST_SIM_LIB_PATH}"
1516-
call lipo -remove i386 "${HOST_LIB_PATH}" -output "${DEST_SIM_LIB_PATH}"
1517-
else
1518-
call cp "${HOST_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
1519-
fi
1520-
elif [[ "${VERBOSE_BUILD}" ]]; then
1521-
echo "no file exists at ${HOST_SIM_LIB_PATH}"
1522-
fi
1523-
fi
1524-
done
1525-
done
1526-
fi
1527-
}
1528-
15291440
#
15301441
# Configure and build each product
15311442
#

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ def copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
185185
elif self.args.verbose_build:
186186
print('no file exists at {}', host_sim_lib_path)
187187

188+
os.makedirs(os.path.join(dest_builtins_dir, 'macho_embedded'), exist_ok=True)
189+
for _flavor in ['hard_pic', 'hard_static', 'soft_pic', 'soft_static']:
190+
# Copy over the macho_embedded .a when necessary
191+
lib_name = os.path.join('macho_embedded', 'libclang_rt.{}.a'.format(_flavor))
192+
host_lib_path = os.path.join(host_cxx_builtins_dir, lib_name)
193+
dest_lib_path = os.path.join(dest_builtins_dir, lib_name)
194+
if not os.path.isfile(dest_lib_path):
195+
if os.path.isfile(host_lib_path):
196+
shutil.copy(host_lib_path, dest_lib_path)
197+
elif self.args.verbose_build:
198+
print('no file exists at {}'.format(host_lib_path))
199+
188200
def should_build(self, host_target):
189201
"""should_build() -> Bool
190202

0 commit comments

Comments
 (0)