Skip to content

Commit 6306663

Browse files
authored
Build fat when CROSS_COMPILE_HOSTS is set (#2859)
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".
1 parent c131bec commit 6306663

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Utilities/bootstrap

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ def parse_build_args(args):
162162
args.clang_path = get_clang_path(args)
163163
args.cmake_path = get_cmake_path(args)
164164
args.ninja_path = get_ninja_path(args)
165-
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
165+
if os.getenv("CROSS_COMPILE_HOSTS"): # Use XCBuild target directory when building for multiple arches.
166+
args.target_dir = os.path.join(args.build_dir, "apple/Products")
167+
else:
168+
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
166169
args.bootstrap_dir = os.path.join(args.target_dir, "bootstrap")
167170
args.conf = 'release' if args.release else 'debug'
168171
args.bin_dir = os.path.join(args.target_dir, args.conf)
@@ -312,7 +315,8 @@ def install(args):
312315
# Install the swiftmodule and swiftdoc files.
313316
for module in libswiftpm_modules:
314317
install_binary(args, module + ".swiftmodule", dest)
315-
install_binary(args, module + ".swiftdoc", dest)
318+
if not os.getenv("CROSS_COMPILE_HOSTS"): # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
319+
install_binary(args, module + ".swiftdoc", dest)
316320

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

360364
mkdir_p(os.path.dirname(dest))
361-
file_util.copy_file(src, dest, update=1)
365+
if os.path.isdir(src) and os.getenv("CROSS_COMPILE_HOSTS"): # Handle swiftmodule directories if compiling for multiple arches.
366+
dir_util.copy_tree(src, dest)
367+
else:
368+
file_util.copy_file(src, dest, update=1)
362369

363370
# -----------------------------------------------------------
364371
# Build functions
@@ -453,12 +460,21 @@ def build_swiftpm_with_swiftpm(args):
453460
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
454461
note("Building SwiftPM (with swift-build)")
455462

456-
call_swiftpm(args, [
463+
swiftpm_args = [
457464
"SWIFT_EXEC=" + args.swiftc_path,
458465
"SWIFTPM_PD_LIBS=" + os.path.join(args.bootstrap_dir, "pm"),
459466
os.path.join(args.bootstrap_dir, "bin/swift-build"),
460467
"--disable-sandbox",
461-
])
468+
]
469+
470+
build_target = get_build_target(args)
471+
cross_compile_host = os.getenv("CROSS_COMPILE_HOSTS")
472+
if build_target == 'x86_64-apple-macosx' and cross_compile_host == "macosx-arm64":
473+
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
474+
elif cross_compile_host:
475+
error("cannot cross-compile for %s" % cross_compile_host)
476+
477+
call_swiftpm(args, swiftpm_args)
462478

463479
# Setup symlinks that'll allow using swiftpm from the build directory.
464480
symlink_force(args.swiftc_path, os.path.join(args.target_dir, args.conf, "swiftc"))

0 commit comments

Comments
 (0)