@@ -144,6 +144,9 @@ 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-config" ,
149
+ help = "Swift flags to cross-compile SPM with itself" )
147
150
148
151
def add_test_args (parser ):
149
152
"""Configures the parser with the arguments necessary for the test action."""
@@ -197,8 +200,14 @@ def parse_build_args(args):
197
200
args .clang_path = get_clang_path (args )
198
201
args .cmake_path = get_cmake_path (args )
199
202
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" )
203
+ if args .cross_compile_hosts :
204
+ if "macosx-arm64" in args .cross_compile_hosts :
205
+ # Use XCBuild target directory when building for multiple arches.
206
+ args .target_dir = os .path .join (args .build_dir , "apple/Products" )
207
+ elif re .match ('android-' , args .cross_compile_hosts ):
208
+ args .target_dir = os .path .join (
209
+ args .build_dir ,
210
+ get_build_target (args ,cross_compile = True ))
202
211
else :
203
212
args .target_dir = os .path .join (args .build_dir , get_build_target (args ))
204
213
args .bootstrap_dir = os .path .join (args .target_dir , "bootstrap" )
@@ -272,10 +281,15 @@ def get_ninja_path(args):
272
281
else :
273
282
return call_output (["which" , "ninja" ], verbose = args .verbose )
274
283
275
- def get_build_target (args ):
276
- """Returns the target-triple of the current machine."""
284
+ def get_build_target (args , cross_compile = False ):
285
+ """Returns the target-triple of the current machine or for cross-compilation ."""
277
286
try :
278
- target_info_json = subprocess .check_output ([args .swiftc_path , '-print-target-info' ], stderr = subprocess .PIPE , universal_newlines = True ).strip ()
287
+ command = [args .swiftc_path , '-print-target-info' ]
288
+ if cross_compile :
289
+ cross_compile_json = json .load (open (args .cross_compile_config ))
290
+ command += ['-target' , cross_compile_json ["target" ]]
291
+ target_info_json = subprocess .check_output (command ,
292
+ stderr = subprocess .PIPE , universal_newlines = True ).strip ()
279
293
args .target_info = json .loads (target_info_json )
280
294
return args .target_info ["target" ]["unversionedTriple" ]
281
295
except Exception as e :
@@ -310,8 +324,8 @@ def build(args):
310
324
build_swift_argument_parser (args )
311
325
build_swift_driver (args )
312
326
build_swift_crypto (args )
327
+ build_swiftpm_with_cmake (args )
313
328
314
- build_swiftpm_with_cmake (args )
315
329
build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
316
330
317
331
def test (args ):
@@ -469,7 +483,7 @@ def install_binary(args, binary, dest_dir):
469
483
# Build functions
470
484
# -----------------------------------------------------------
471
485
472
- def build_with_cmake (args , cmake_args , source_path , build_dir , targets = [] ):
486
+ def build_with_cmake (args , cmake_args , source_path , build_dir ):
473
487
"""Runs CMake if needed, then builds with Ninja."""
474
488
cache_path = os .path .join (build_dir , "CMakeCache.txt" )
475
489
if args .reconfigure or not os .path .isfile (cache_path ) or not args .swiftc_path in open (cache_path ).read ():
@@ -500,8 +514,6 @@ def build_with_cmake(args, cmake_args, source_path, build_dir, targets=[]):
500
514
if args .verbose :
501
515
ninja_cmd .append ("-v" )
502
516
503
- ninja_cmd += targets
504
-
505
517
call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
506
518
507
519
def build_llbuild (args ):
@@ -607,26 +619,20 @@ def build_swiftpm_with_cmake(args):
607
619
"""Builds SwiftPM using CMake."""
608
620
note ("Building SwiftPM (with CMake)" )
609
621
610
- if args .bootstrap :
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
- "-DFIND_PM_DEPS:BOOL=YES" ,
619
- ]
620
- else :
621
- cmake_flags = [ "-DFIND_PM_DEPS:BOOL=NO" ]
622
+ cmake_flags = [
623
+ get_llbuild_cmake_arg (args ),
624
+ "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
625
+ "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
626
+ "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
627
+ "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
628
+ "-DSwiftCrypto_DIR=" + os .path .join (args .swift_crypto_build_dir , "cmake/modules" ),
629
+ ]
622
630
623
631
if platform .system () == 'Darwin' :
624
632
cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
625
633
cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
626
634
627
- targets = [] if args .bootstrap else ["PD4" , "PD4_2" ]
628
-
629
- build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir , targets )
635
+ build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir )
630
636
631
637
if args .llbuild_link_framework :
632
638
add_rpath_for_cmake_build (args , args .llbuild_build_dir )
@@ -812,7 +818,8 @@ def get_swiftpm_flags(args):
812
818
)
813
819
814
820
# Don't use GNU strerror_r on Android.
815
- if 'ANDROID_DATA' in os .environ :
821
+ if 'ANDROID_DATA' in os .environ or (args .cross_compile_hosts and re .match (
822
+ 'android-' , args .cross_compile_hosts )):
816
823
build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
817
824
818
825
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
@@ -824,6 +831,8 @@ def get_swiftpm_flags(args):
824
831
cross_compile_hosts = args .cross_compile_hosts
825
832
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts :
826
833
build_flags += ["--arch" , "x86_64" , "--arch" , "arm64" ]
834
+ elif cross_compile_hosts and re .match ('android-' , cross_compile_hosts ):
835
+ build_flags .extend (["--destination" , args .cross_compile_config ])
827
836
elif cross_compile_hosts :
828
837
error ("cannot cross-compile for %s" % cross_compile_hosts )
829
838
0 commit comments