@@ -143,6 +143,9 @@ def add_build_args(parser):
143
143
dest = "cross_compile_hosts" ,
144
144
help = "List of cross compile hosts targets." ,
145
145
default = [])
146
+ parser .add_argument (
147
+ "--cross-compile-config" ,
148
+ help = "Swift flags to cross-compile SPM with itself" )
146
149
147
150
def add_test_args (parser ):
148
151
"""Configures the parser with the arguments necessary for the test action."""
@@ -196,8 +199,14 @@ def parse_build_args(args):
196
199
args .clang_path = get_clang_path (args )
197
200
args .cmake_path = get_cmake_path (args )
198
201
args .ninja_path = get_ninja_path (args )
199
- if args .cross_compile_hosts : # Use XCBuild target directory when building for multiple arches.
200
- args .target_dir = os .path .join (args .build_dir , "apple/Products" )
202
+ if args .cross_compile_hosts :
203
+ if "macosx-arm64" in args .cross_compile_hosts :
204
+ # Use XCBuild target directory when building for multiple arches.
205
+ args .target_dir = os .path .join (args .build_dir , "apple/Products" )
206
+ elif re .match ('android-' , args .cross_compile_hosts ):
207
+ args .target_dir = os .path .join (
208
+ args .build_dir ,
209
+ get_build_target (args ,cross_compile = True ))
201
210
else :
202
211
args .target_dir = os .path .join (args .build_dir , get_build_target (args ))
203
212
args .bootstrap_dir = os .path .join (args .target_dir , "bootstrap" )
@@ -271,10 +280,15 @@ def get_ninja_path(args):
271
280
else :
272
281
return call_output (["which" , "ninja" ], verbose = args .verbose )
273
282
274
- def get_build_target (args ):
275
- """Returns the target-triple of the current machine."""
283
+ def get_build_target (args , cross_compile = False ):
284
+ """Returns the target-triple of the current machine or for cross-compilation ."""
276
285
try :
277
- target_info_json = subprocess .check_output ([args .swiftc_path , '-print-target-info' ], stderr = subprocess .PIPE , universal_newlines = True ).strip ()
286
+ command = [args .swiftc_path , '-print-target-info' ]
287
+ if cross_compile :
288
+ cross_compile_json = json .load (open (args .cross_compile_config ))
289
+ command += ['-target' , cross_compile_json ["target" ]]
290
+ target_info_json = subprocess .check_output (command ,
291
+ stderr = subprocess .PIPE , universal_newlines = True ).strip ()
278
292
args .target_info = json .loads (target_info_json )
279
293
return args .target_info ["target" ]["unversionedTriple" ]
280
294
except Exception as e :
@@ -309,8 +323,8 @@ def build(args):
309
323
build_swift_argument_parser (args )
310
324
build_swift_driver (args )
311
325
build_swift_crypto (args )
326
+ build_swiftpm_with_cmake (args )
312
327
313
- build_swiftpm_with_cmake (args )
314
328
build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
315
329
316
330
def test (args ):
@@ -458,7 +472,7 @@ def install_binary(args, binary, dest_dir):
458
472
# Build functions
459
473
# -----------------------------------------------------------
460
474
461
- def build_with_cmake (args , cmake_args , source_path , build_dir , targets = [] ):
475
+ def build_with_cmake (args , cmake_args , source_path , build_dir ):
462
476
"""Runs CMake if needed, then builds with Ninja."""
463
477
cache_path = os .path .join (build_dir , "CMakeCache.txt" )
464
478
if args .reconfigure or not os .path .isfile (cache_path ) or not args .swiftc_path in open (cache_path ).read ():
@@ -489,8 +503,6 @@ def build_with_cmake(args, cmake_args, source_path, build_dir, targets=[]):
489
503
if args .verbose :
490
504
ninja_cmd .append ("-v" )
491
505
492
- ninja_cmd += targets
493
-
494
506
call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
495
507
496
508
def build_llbuild (args ):
@@ -596,26 +608,20 @@ def build_swiftpm_with_cmake(args):
596
608
"""Builds SwiftPM using CMake."""
597
609
note ("Building SwiftPM (with CMake)" )
598
610
599
- if args .bootstrap :
600
- cmake_flags = [
601
- get_llbuild_cmake_arg (args ),
602
- "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
603
- "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
604
- "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
605
- "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
606
- "-DSwiftCrypto_DIR=" + os .path .join (args .swift_crypto_build_dir , "cmake/modules" ),
607
- "-DFIND_PM_DEPS:BOOL=YES" ,
608
- ]
609
- else :
610
- cmake_flags = [ "-DFIND_PM_DEPS:BOOL=NO" ]
611
+ cmake_flags = [
612
+ get_llbuild_cmake_arg (args ),
613
+ "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
614
+ "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
615
+ "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
616
+ "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
617
+ "-DSwiftCrypto_DIR=" + os .path .join (args .swift_crypto_build_dir , "cmake/modules" ),
618
+ ]
611
619
612
620
if platform .system () == 'Darwin' :
613
621
cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
614
622
cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
615
623
616
- targets = [] if args .bootstrap else ["PD4" , "PD4_2" ]
617
-
618
- build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir , targets )
624
+ build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir )
619
625
620
626
if args .llbuild_link_framework :
621
627
add_rpath_for_cmake_build (args , args .llbuild_build_dir )
@@ -791,7 +797,8 @@ def get_swiftpm_flags(args):
791
797
)
792
798
793
799
# Don't use GNU strerror_r on Android.
794
- if 'ANDROID_DATA' in os .environ :
800
+ if 'ANDROID_DATA' in os .environ or (args .cross_compile_hosts and re .match (
801
+ 'android-' , args .cross_compile_hosts )):
795
802
build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
796
803
797
804
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
@@ -803,6 +810,8 @@ def get_swiftpm_flags(args):
803
810
cross_compile_hosts = args .cross_compile_hosts
804
811
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts :
805
812
build_flags += ["--arch" , "x86_64" , "--arch" , "arm64" ]
813
+ elif cross_compile_hosts and re .match ('android-' , cross_compile_hosts ):
814
+ build_flags .extend (["--destination" , args .cross_compile_config ])
806
815
elif cross_compile_hosts :
807
816
error ("cannot cross-compile for %s" % cross_compile_hosts )
808
817
0 commit comments