@@ -162,7 +162,10 @@ def parse_build_args(args):
162
162
args .clang_path = get_clang_path (args )
163
163
args .cmake_path = get_cmake_path (args )
164
164
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 ))
166
169
args .bootstrap_dir = os .path .join (args .target_dir , "bootstrap" )
167
170
args .conf = 'release' if args .release else 'debug'
168
171
args .bin_dir = os .path .join (args .target_dir , args .conf )
@@ -312,7 +315,8 @@ def install(args):
312
315
# Install the swiftmodule and swiftdoc files.
313
316
for module in libswiftpm_modules :
314
317
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 )
316
320
317
321
# Install the C headers.
318
322
tscclibc_include_dir = os .path .join (args .tsc_source_dir , "Sources/TSCclibc/include" )
@@ -358,7 +362,10 @@ def install_binary(args, binary, dest_dir):
358
362
note ("Installing %s to %s" % (src , dest ))
359
363
360
364
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 )
362
369
363
370
# -----------------------------------------------------------
364
371
# Build functions
@@ -453,12 +460,21 @@ def build_swiftpm_with_swiftpm(args):
453
460
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
454
461
note ("Building SwiftPM (with swift-build)" )
455
462
456
- call_swiftpm ( args , [
463
+ swiftpm_args = [
457
464
"SWIFT_EXEC=" + args .swiftc_path ,
458
465
"SWIFTPM_PD_LIBS=" + os .path .join (args .bootstrap_dir , "pm" ),
459
466
os .path .join (args .bootstrap_dir , "bin/swift-build" ),
460
467
"--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 )
462
478
463
479
# Setup symlinks that'll allow using swiftpm from the build directory.
464
480
symlink_force (args .swiftc_path , os .path .join (args .target_dir , args .conf , "swiftc" ))
0 commit comments