@@ -1444,6 +1444,25 @@ function cmake_config_opt() {
14441444 fi
14451445}
14461446
1447+ function copy_lib_stripping_architecture() {
1448+ local source=" $1 "
1449+ local dest=" $2 "
1450+ local arch=" $3 "
1451+
1452+ # An alternative approach would be to use || to first
1453+ # attempt the removal of the slice and fall back to the
1454+ # copy when failing.
1455+ # However, this would leave unneeded error messages in the logs
1456+ # that may hinder investigation; in addition, in this scenario
1457+ # the `call` function seems to not propagate correctly failure
1458+ # exit codes.
1459+ if lipo -archs " ${source} " | grep -q " ${arch} " ; then
1460+ call lipo -remove " ${arch} " " ${source} " -output " ${dest} "
1461+ else
1462+ call cp " ${source} " " ${dest} "
1463+ fi
1464+ }
1465+
14471466function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
14481467 local clang_dest_dir=" $1 "
14491468
@@ -1470,7 +1489,7 @@ function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
14701489 if [[ -f " ${HOST_LIB_PATH} " ]]; then
14711490 if [[ " $OS " == " tvos" ]]; then
14721491 # This is to avoid strip failures when generating a toolchain
1473- call lipo -remove i386 " ${HOST_LIB_PATH} " -output " ${DEST_LIB_PATH} " || call cp " ${HOST_LIB_PATH} " " ${DEST_LIB_PATH} "
1492+ copy_lib_stripping_architecture " ${HOST_LIB_PATH} " " ${DEST_LIB_PATH} " i386
14741493 else
14751494 call cp " ${HOST_LIB_PATH} " " ${DEST_LIB_PATH} "
14761495 fi
@@ -1487,7 +1506,7 @@ function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
14871506 if [[ -f " ${HOST_SIM_LIB_PATH} " ]]; then
14881507 if [[ " $OS " == " tvos" ]]; then
14891508 # This is to avoid strip failures when generating a toolchain
1490- call lipo -remove i386 " ${HOST_SIM_LIB_PATH} " -output " ${DEST_SIM_LIB_PATH} " || call cp " ${HOST_SIM_LIB_PATH} " " ${DEST_SIM_LIB_PATH} "
1509+ copy_lib_stripping_architecture " ${HOST_SIM_LIB_PATH} " " ${DEST_SIM_LIB_PATH} " i386
14911510 else
14921511 call cp " ${HOST_SIM_LIB_PATH} " " ${DEST_SIM_LIB_PATH} "
14931512 fi
0 commit comments