@@ -182,7 +182,10 @@ def parse_build_args(args):
182
182
args .clang_path = get_clang_path (args )
183
183
args .cmake_path = get_cmake_path (args )
184
184
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 ))
186
189
args .bootstrap_dir = os .path .join (args .target_dir , "bootstrap" )
187
190
args .conf = 'release' if args .release else 'debug'
188
191
args .bin_dir = os .path .join (args .target_dir , args .conf )
@@ -353,7 +356,8 @@ def install(args):
353
356
# Install the swiftmodule and swiftdoc files.
354
357
for module in libswiftpm_modules :
355
358
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 )
357
361
358
362
# Install the C headers.
359
363
tscclibc_include_dir = os .path .join (args .tsc_source_dir , "Sources/TSCclibc/include" )
@@ -399,7 +403,10 @@ def install_binary(args, binary, dest_dir):
399
403
note ("Installing %s to %s" % (src , dest ))
400
404
401
405
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 )
403
410
404
411
# -----------------------------------------------------------
405
412
# Build functions
@@ -561,6 +568,13 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
561
568
if integrated_swift_driver :
562
569
swiftpm_args .append ("--use-integrated-swift-driver" )
563
570
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
+
564
578
call_swiftpm (args , swiftpm_args )
565
579
566
580
# Setup symlinks that'll allow using swiftpm from the build directory.
0 commit comments