@@ -1281,6 +1281,36 @@ function cmake_config_opt() {
1281
1281
fi
1282
1282
}
1283
1283
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
+
1284
1314
#
1285
1315
# Configure and build each product
1286
1316
#
@@ -2249,31 +2279,7 @@ for host in "${ALL_HOSTS[@]}"; do
2249
2279
# builtins for iOS/tvOS/watchOS to ensure that Swift's
2250
2280
# stdlib can use compiler-rt builtins when targetting iOS/tvOS/watchOS.
2251
2281
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) /.."
2277
2283
fi
2278
2284
done
2279
2285
done
@@ -2780,6 +2786,13 @@ for host in "${ALL_HOSTS[@]}"; do
2780
2786
build_dir=$( build_directory ${host} ${product} )
2781
2787
2782
2788
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
2783
2796
done
2784
2797
done
2785
2798
0 commit comments