@@ -1361,6 +1361,61 @@ function cmake_config_opt() {
1361
1361
fi
1362
1362
}
1363
1363
1364
+ function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
1365
+ local clang_dest_dir=" $1 "
1366
+
1367
+ HOST_CXX_DIR=$( dirname " ${HOST_CXX} " )
1368
+ HOST_LIB_CLANG_DIR=" ${HOST_CXX_DIR} /../lib/clang"
1369
+ DEST_LIB_CLANG_DIR=" ${clang_dest_dir} /lib/clang"
1370
+
1371
+ [ -d " ${HOST_LIB_CLANG_DIR} " -a -d " ${DEST_LIB_CLANG_DIR} " ] || return 0
1372
+
1373
+ DEST_CXX_BUILTINS_VERSION=$( ls -1 " ${DEST_LIB_CLANG_DIR} " )
1374
+ DEST_BUILTINS_DIR=" ${clang_dest_dir} /lib/clang/${DEST_CXX_BUILTINS_VERSION} /lib/darwin"
1375
+
1376
+ if [[ -d " ${DEST_BUILTINS_DIR} " ]]; then
1377
+ for HOST_CXX_BUILTINS_PATH in " ${HOST_LIB_CLANG_DIR} " /* ; do
1378
+ HOST_CXX_BUILTINS_DIR=" ${HOST_CXX_BUILTINS_PATH} /lib/darwin"
1379
+ echo " copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR} ."
1380
+
1381
+ for OS in ios watchos tvos; do
1382
+ # Copy over the device .a when necessary
1383
+ LIB_NAME=" libclang_rt.$OS .a"
1384
+ HOST_LIB_PATH=" $HOST_CXX_BUILTINS_DIR /$LIB_NAME "
1385
+ DEST_LIB_PATH=" ${DEST_BUILTINS_DIR} /${LIB_NAME} "
1386
+ if [[ ! -f " ${DEST_LIB_PATH} " ]]; then
1387
+ if [[ -f " ${HOST_LIB_PATH} " ]]; then
1388
+ call cp " ${HOST_LIB_PATH} " " ${DEST_LIB_PATH} "
1389
+ elif [[ " ${VERBOSE_BUILD} " ]]; then
1390
+ echo " no file exists at ${HOST_LIB_PATH} "
1391
+ fi
1392
+ fi
1393
+
1394
+ # Copy over the simulator .a when necessary
1395
+ SIM_LIB_NAME=" libclang_rt.${OS} sim.a"
1396
+ HOST_SIM_LIB_PATH=" $HOST_CXX_BUILTINS_DIR /$SIM_LIB_NAME "
1397
+ DEST_SIM_LIB_PATH=" ${DEST_BUILTINS_DIR} /${SIM_LIB_NAME} "
1398
+ if [[ ! -f " ${DEST_SIM_LIB_PATH} " ]]; then
1399
+ if [[ -f " ${HOST_SIM_LIB_PATH} " ]]; then
1400
+ call cp " ${HOST_SIM_LIB_PATH} " " ${DEST_SIM_LIB_PATH} "
1401
+ elif [[ -f " ${HOST_LIB_PATH} " ]]; then
1402
+ # The simulator .a might not exist if the host
1403
+ # Xcode is old. In that case, copy over the
1404
+ # device library to the simulator location to allow
1405
+ # clang to find it. The device library has the simulator
1406
+ # slices in Xcode that doesn't have the simulator .a, so
1407
+ # the link is still valid.
1408
+ echo " copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME} "
1409
+ call cp " ${HOST_LIB_PATH} " " ${DEST_SIM_LIB_PATH} "
1410
+ elif [[ " ${VERBOSE_BUILD} " ]]; then
1411
+ echo " no file exists at ${HOST_SIM_LIB_PATH} "
1412
+ fi
1413
+ fi
1414
+ done
1415
+ done
1416
+ fi
1417
+ }
1418
+
1364
1419
#
1365
1420
# Configure and build each product
1366
1421
#
@@ -2421,55 +2476,7 @@ for host in "${ALL_HOSTS[@]}"; do
2421
2476
# builtins for iOS/tvOS/watchOS to ensure that Swift's
2422
2477
# stdlib can use compiler-rt builtins when targetting iOS/tvOS/watchOS.
2423
2478
if [[ " ${product} " = " llvm" ]] && [[ " ${BUILD_LLVM} " = " 1" ]] && [[ " $( uname -s) " = " Darwin" ]]; then
2424
- HOST_CXX_DIR=$( dirname " ${HOST_CXX} " )
2425
- HOST_LIB_CLANG_DIR=" ${HOST_CXX_DIR} /../lib/clang"
2426
- DEST_LIB_CLANG_DIR=" $( build_directory_bin ${host} llvm) /../lib/clang"
2427
-
2428
- if [[ -d " ${HOST_LIB_CLANG_DIR} " ]] && [[ -d " ${DEST_LIB_CLANG_DIR} " ]]; then
2429
- DEST_CXX_BUILTINS_VERSION=$( ls " ${DEST_LIB_CLANG_DIR} " | awk ' {print $0}' )
2430
- DEST_BUILTINS_DIR=" $( build_directory_bin ${host} llvm) /../lib/clang/$DEST_CXX_BUILTINS_VERSION /lib/darwin"
2431
-
2432
- if [[ -d " ${DEST_BUILTINS_DIR} " ]]; then
2433
- for HOST_CXX_BUILTINS_PATH in " ${HOST_LIB_CLANG_DIR} " /* ; do
2434
- HOST_CXX_BUILTINS_DIR=" ${HOST_CXX_BUILTINS_PATH} /lib/darwin"
2435
- echo " copying compiler-rt embedded builtins from ${HOST_CXX_BUILTINS_DIR} into the local clang build directory ${DEST_BUILTINS_DIR} ."
2436
-
2437
- for OS in ios watchos tvos; do
2438
- # Copy over the device .a when necessary
2439
- LIB_NAME=" libclang_rt.$OS .a"
2440
- HOST_LIB_PATH=" $HOST_CXX_BUILTINS_DIR /$LIB_NAME "
2441
- DEST_LIB_PATH=" ${DEST_BUILTINS_DIR} /${LIB_NAME} "
2442
- if [[ ! -f " ${DEST_LIB_PATH} " ]]; then
2443
- if [[ -f " ${HOST_LIB_PATH} " ]]; then
2444
- call cp " ${HOST_LIB_PATH} " " ${DEST_LIB_PATH} "
2445
- elif [[ " ${VERBOSE_BUILD} " ]]; then
2446
- echo " no file exists at ${HOST_LIB_PATH} "
2447
- fi
2448
- fi
2449
- # Copy over the simulator .a when necessary
2450
- SIM_LIB_NAME=" libclang_rt.${OS} sim.a"
2451
- HOST_SIM_LIB_PATH=" $HOST_CXX_BUILTINS_DIR /$SIM_LIB_NAME "
2452
- DEST_SIM_LIB_PATH=" ${DEST_BUILTINS_DIR} /${SIM_LIB_NAME} "
2453
- if [[ ! -f " ${DEST_SIM_LIB_PATH} " ]]; then
2454
- if [[ -f " ${HOST_SIM_LIB_PATH} " ]]; then
2455
- call cp " ${HOST_SIM_LIB_PATH} " " ${DEST_SIM_LIB_PATH} "
2456
- elif [[ -f " ${HOST_LIB_PATH} " ]]; then
2457
- # The simulator .a might not exist if the host
2458
- # Xcode is old. In that case, copy over the
2459
- # device library to the simulator location to allow
2460
- # clang to find it. The device library has the simulator
2461
- # slices in Xcode that doesn't have the simulator .a, so
2462
- # the link is still valid.
2463
- echo " copying over faux-sim library ${HOST_LIB_PATH} to ${SIM_LIB_NAME} "
2464
- call cp " ${HOST_LIB_PATH} " " ${DEST_SIM_LIB_PATH} "
2465
- elif [[ " ${VERBOSE_BUILD} " ]]; then
2466
- echo " no file exists at ${HOST_SIM_LIB_PATH} "
2467
- fi
2468
- fi
2469
- done
2470
- done
2471
- fi
2472
- fi
2479
+ copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain " $( build_directory_bin ${host} llvm) /.."
2473
2480
fi
2474
2481
done
2475
2482
done
@@ -2990,6 +2997,13 @@ for host in "${ALL_HOSTS[@]}"; do
2990
2997
build_dir=$( build_directory ${host} ${product} )
2991
2998
2992
2999
call env DESTDIR=" ${host_install_destdir} " " ${CMAKE_BUILD[@]} " " ${build_dir} " -- ${INSTALL_TARGETS}
3000
+
3001
+ # When we are installing LLVM copy over the compiler-rt
3002
+ # builtins for iOS/tvOS/watchOS to ensure that we don't
3003
+ # have linker errors when building apps for such platforms.
3004
+ if [[ " ${product} " = " llvm" ]] && [[ ! -z " ${LLVM_INSTALL_COMPONENTS} " ]] && [[ " $( uname -s) " = " Darwin" ]]; then
3005
+ copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain " ${host_install_destdir}${host_install_prefix} "
3006
+ fi
2993
3007
done
2994
3008
done
2995
3009
0 commit comments