@@ -1380,6 +1380,61 @@ function cmake_config_opt() {
1380
1380
fi
1381
1381
}
1382
1382
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
+
1383
1438
#
1384
1439
# Configure and build each product
1385
1440
#
@@ -2349,49 +2404,7 @@ for host in "${ALL_HOSTS[@]}"; do
2349
2404
# builtins for iOS/tvOS/watchOS to ensure that Swift's
2350
2405
# stdlib can use compiler-rt builtins when targetting iOS/tvOS/watchOS.
2351
2406
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) /.."
2395
2408
fi
2396
2409
done
2397
2410
done
@@ -2908,6 +2921,13 @@ for host in "${ALL_HOSTS[@]}"; do
2908
2921
build_dir=$( build_directory ${host} ${product} )
2909
2922
2910
2923
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
2911
2931
done
2912
2932
done
2913
2933
0 commit comments