@@ -144,6 +144,12 @@ def add_build_args(parser):
144
144
dest = "cross_compile_hosts" ,
145
145
help = "List of cross compile hosts targets." ,
146
146
default = [])
147
+ parser .add_argument (
148
+ "--cross-compile-target-triple" ,
149
+ help = "Swift cross-compilation target triple" )
150
+ parser .add_argument (
151
+ "--cross-compile-config" ,
152
+ help = "Swift flags to cross-compile SPM with itself" )
147
153
148
154
def add_test_args (parser ):
149
155
"""Configures the parser with the arguments necessary for the test action."""
@@ -197,8 +203,14 @@ def parse_build_args(args):
197
203
args .clang_path = get_clang_path (args )
198
204
args .cmake_path = get_cmake_path (args )
199
205
args .ninja_path = get_ninja_path (args )
200
- if args .cross_compile_hosts : # Use XCBuild target directory when building for multiple arches.
201
- args .target_dir = os .path .join (args .build_dir , "apple/Products" )
206
+ if args .cross_compile_hosts :
207
+ if "macosx-arm64" in args .cross_compile_hosts :
208
+ # Use XCBuild target directory when building for multiple arches.
209
+ args .target_dir = os .path .join (args .build_dir , "apple/Products" )
210
+ elif re .match ('android-' , args .cross_compile_hosts ):
211
+ args .target_dir = os .path .join (
212
+ args .build_dir ,
213
+ get_build_target (args ,cross_compile = True ))
202
214
else :
203
215
args .target_dir = os .path .join (args .build_dir , get_build_target (args ))
204
216
args .bootstrap_dir = os .path .join (args .target_dir , "bootstrap" )
@@ -272,10 +284,14 @@ def get_ninja_path(args):
272
284
else :
273
285
return call_output (["which" , "ninja" ], verbose = args .verbose )
274
286
275
- def get_build_target (args ):
287
+ def get_build_target (args , cross_compile = False ):
276
288
"""Returns the target-triple of the current machine."""
277
289
try :
278
- target_info_json = subprocess .check_output ([args .swiftc_path , '-print-target-info' ], stderr = subprocess .PIPE , universal_newlines = True ).strip ()
290
+ command = [args .swiftc_path , '-print-target-info' ]
291
+ if cross_compile :
292
+ command += ['-target' , args .cross_compile_target_triple ]
293
+ target_info_json = subprocess .check_output (command ,
294
+ stderr = subprocess .PIPE , universal_newlines = True ).strip ()
279
295
args .target_info = json .loads (target_info_json )
280
296
return args .target_info ["target" ]["unversionedTriple" ]
281
297
except Exception as e :
@@ -310,8 +326,8 @@ def build(args):
310
326
build_swift_argument_parser (args )
311
327
build_swift_driver (args )
312
328
build_swift_crypto (args )
329
+ build_swiftpm_with_cmake (args )
313
330
314
- build_swiftpm_with_cmake (args )
315
331
build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
316
332
317
333
def test (args ):
@@ -440,7 +456,7 @@ def install_binary(args, binary, dest_dir):
440
456
# Build functions
441
457
# -----------------------------------------------------------
442
458
443
- def build_with_cmake (args , cmake_args , source_path , build_dir , targets = [] ):
459
+ def build_with_cmake (args , cmake_args , source_path , build_dir ):
444
460
"""Runs CMake if needed, then builds with Ninja."""
445
461
cache_path = os .path .join (build_dir , "CMakeCache.txt" )
446
462
if args .reconfigure or not os .path .isfile (cache_path ) or not args .swiftc_path in open (cache_path ).read ():
@@ -471,8 +487,6 @@ def build_with_cmake(args, cmake_args, source_path, build_dir, targets=[]):
471
487
if args .verbose :
472
488
ninja_cmd .append ("-v" )
473
489
474
- ninja_cmd += targets
475
-
476
490
call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
477
491
478
492
def build_llbuild (args ):
@@ -578,26 +592,20 @@ def build_swiftpm_with_cmake(args):
578
592
"""Builds SwiftPM using CMake."""
579
593
note ("Building SwiftPM (with CMake)" )
580
594
581
- if args .bootstrap :
582
- cmake_flags = [
583
- get_llbuild_cmake_arg (args ),
584
- "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
585
- "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
586
- "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
587
- "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
588
- "-DSwiftCrypto_DIR=" + os .path .join (args .swift_crypto_build_dir , "cmake/modules" ),
589
- "-DFIND_PM_DEPS:BOOL=YES" ,
590
- ]
591
- else :
592
- cmake_flags = [ "-DFIND_PM_DEPS:BOOL=NO" ]
595
+ cmake_flags = [
596
+ get_llbuild_cmake_arg (args ),
597
+ "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
598
+ "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
599
+ "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
600
+ "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
601
+ "-DSwiftCrypto_DIR=" + os .path .join (args .swift_crypto_build_dir , "cmake/modules" ),
602
+ ]
593
603
594
604
if platform .system () == 'Darwin' :
595
605
cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
596
606
cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
597
607
598
- targets = [] if args .bootstrap else ["PD4" , "PD4_2" ]
599
-
600
- build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir , targets )
608
+ build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir )
601
609
602
610
if args .llbuild_link_framework :
603
611
add_rpath_for_cmake_build (args , args .llbuild_build_dir )
@@ -783,7 +791,8 @@ def get_swiftpm_flags(args):
783
791
)
784
792
785
793
# Don't use GNU strerror_r on Android.
786
- if 'ANDROID_DATA' in os .environ :
794
+ if 'ANDROID_DATA' in os .environ or (args .cross_compile_hosts and re .match (
795
+ 'android-' , args .cross_compile_hosts )):
787
796
build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
788
797
789
798
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
@@ -795,6 +804,8 @@ def get_swiftpm_flags(args):
795
804
cross_compile_hosts = args .cross_compile_hosts
796
805
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts :
797
806
build_flags += ["--arch" , "x86_64" , "--arch" , "arm64" ]
807
+ elif cross_compile_hosts and re .match ('android-' , cross_compile_hosts ):
808
+ build_flags .extend (["--destination" , args .cross_compile_config ])
798
809
elif cross_compile_hosts :
799
810
error ("cannot cross-compile for %s" % cross_compile_hosts )
800
811
0 commit comments