@@ -124,6 +124,11 @@ def add_build_args(parser):
124
124
help = "paths (relative to the project root) where to install build products [%(default)s]" ,
125
125
default = ["/tmp/swiftpm" ],
126
126
metavar = "PATHS" )
127
+ parser .add_argument (
128
+ "--cross-compile-hosts" ,
129
+ dest = "cross_compile_hosts" ,
130
+ help = "List of cross compile hosts targets." ,
131
+ default = [])
127
132
128
133
def add_test_args (parser ):
129
134
"""Configures the parser with the arguments necessary for the test action."""
@@ -162,7 +167,7 @@ def parse_build_args(args):
162
167
args .clang_path = get_clang_path (args )
163
168
args .cmake_path = get_cmake_path (args )
164
169
args .ninja_path = get_ninja_path (args )
165
- if os . getenv ( "CROSS_COMPILE_HOSTS" ) : # Use XCBuild target directory when building for multiple arches.
170
+ if args . cross_compile_hosts : # Use XCBuild target directory when building for multiple arches.
166
171
args .target_dir = os .path .join (args .build_dir , "apple/Products" )
167
172
else :
168
173
args .target_dir = os .path .join (args .build_dir , get_build_target (args ))
@@ -315,7 +320,7 @@ def install(args):
315
320
# Install the swiftmodule and swiftdoc files.
316
321
for module in libswiftpm_modules :
317
322
install_binary (args , module + ".swiftmodule" , dest )
318
- if not os . getenv ( "CROSS_COMPILE_HOSTS" ) : # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
323
+ if not args . cross_compile_hosts : # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
319
324
install_binary (args , module + ".swiftdoc" , dest )
320
325
321
326
# Install the C headers.
@@ -362,7 +367,7 @@ def install_binary(args, binary, dest_dir):
362
367
note ("Installing %s to %s" % (src , dest ))
363
368
364
369
mkdir_p (os .path .dirname (dest ))
365
- if os .path .isdir (src ) and os . getenv ( "CROSS_COMPILE_HOSTS" ) : # Handle swiftmodule directories if compiling for multiple arches.
370
+ if os .path .isdir (src ) and args . cross_compile_hosts : # Handle swiftmodule directories if compiling for multiple arches.
366
371
dir_util .copy_tree (src , dest )
367
372
else :
368
373
file_util .copy_file (src , dest , update = 1 )
@@ -468,11 +473,11 @@ def build_swiftpm_with_swiftpm(args):
468
473
]
469
474
470
475
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" :
476
+ cross_compile_hosts = args . cross_compile_hosts
477
+ if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts :
473
478
swiftpm_args += ["--arch" , "x86_64" , "--arch" , "arm64" ]
474
- elif cross_compile_host :
475
- error ("cannot cross-compile for %s" % cross_compile_host )
479
+ elif cross_compile_hosts :
480
+ error ("cannot cross-compile for %s" % cross_compile_hosts )
476
481
477
482
call_swiftpm (args , swiftpm_args )
478
483
0 commit comments