Skip to content

Commit 242e733

Browse files
authored
Build fat when CROSS_COMPILE_HOSTS is set (#2859) (#2896)
This adjusts to building SwiftPM fat specifically when the build is happening on an Intel host and cross-compile host is set to "macosx-arm64". (cherry picked from commit 6306663)
1 parent ea0fde3 commit 242e733

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Utilities/bootstrap

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ def parse_build_args(args):
182182
args.clang_path = get_clang_path(args)
183183
args.cmake_path = get_cmake_path(args)
184184
args.ninja_path = get_ninja_path(args)
185-
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
185+
if os.getenv("CROSS_COMPILE_HOSTS"): # Use XCBuild target directory when building for multiple arches.
186+
args.target_dir = os.path.join(args.build_dir, "apple/Products")
187+
else:
188+
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
186189
args.bootstrap_dir = os.path.join(args.target_dir, "bootstrap")
187190
args.conf = 'release' if args.release else 'debug'
188191
args.bin_dir = os.path.join(args.target_dir, args.conf)
@@ -353,7 +356,8 @@ def install(args):
353356
# Install the swiftmodule and swiftdoc files.
354357
for module in libswiftpm_modules:
355358
install_binary(args, module + ".swiftmodule", dest)
356-
install_binary(args, module + ".swiftdoc", dest)
359+
if not os.getenv("CROSS_COMPILE_HOSTS"): # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
360+
install_binary(args, module + ".swiftdoc", dest)
357361

358362
# Install the C headers.
359363
tscclibc_include_dir = os.path.join(args.tsc_source_dir, "Sources/TSCclibc/include")
@@ -399,7 +403,10 @@ def install_binary(args, binary, dest_dir):
399403
note("Installing %s to %s" % (src, dest))
400404

401405
mkdir_p(os.path.dirname(dest))
402-
file_util.copy_file(src, dest, update=1)
406+
if os.path.isdir(src) and os.getenv("CROSS_COMPILE_HOSTS"): # Handle swiftmodule directories if compiling for multiple arches.
407+
dir_util.copy_tree(src, dest)
408+
else:
409+
file_util.copy_file(src, dest, update=1)
403410

404411
# -----------------------------------------------------------
405412
# Build functions
@@ -561,6 +568,13 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
561568
if integrated_swift_driver:
562569
swiftpm_args.append("--use-integrated-swift-driver")
563570

571+
build_target = get_build_target(args)
572+
cross_compile_host = os.getenv("CROSS_COMPILE_HOSTS")
573+
if build_target == 'x86_64-apple-macosx' and cross_compile_host == "macosx-arm64":
574+
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
575+
elif cross_compile_host:
576+
error("cannot cross-compile for %s" % cross_compile_host)
577+
564578
call_swiftpm(args, swiftpm_args)
565579

566580
# Setup symlinks that'll allow using swiftpm from the build directory.

0 commit comments

Comments
 (0)