11
11
import subprocess
12
12
import sys
13
13
import errno
14
+ import re
14
15
15
16
if platform .system () == 'Darwin' :
16
17
shared_lib_ext = '.dylib'
@@ -96,7 +97,11 @@ def get_swiftpm_options(args):
96
97
os .path .join (args .toolchain , 'lib' , 'swift' , 'Block' ),
97
98
]
98
99
99
- if 'ANDROID_DATA' in os .environ :
100
+ if args .cross_compile_hosts :
101
+ swiftpm_args += ['--destination' , args .cross_compile_config ]
102
+
103
+ if 'ANDROID_DATA' in os .environ or (args .cross_compile_hosts and re .match (
104
+ 'android-' , args .cross_compile_hosts [0 ])):
100
105
swiftpm_args += [
101
106
'-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/android' ,
102
107
# SwiftPM will otherwise try to compile against GNU strerror_r on
@@ -180,8 +185,13 @@ def handle_invocation(args):
180
185
if args .sysroot :
181
186
env ['SDKROOT' ] = args .sysroot
182
187
188
+ env ['SWIFT_EXEC' ] = '%sc' % (swift_exec )
189
+
183
190
if args .action == 'build' :
184
- build_using_cmake (args , toolchain_bin , args .build_path , targets )
191
+ if args .cross_compile_hosts and not re .match ('-macosx' , args .cross_compile_hosts [0 ]):
192
+ swiftpm ('build' , swift_exec , swiftpm_args , env )
193
+ else :
194
+ build_using_cmake (args , toolchain_bin , args .build_path , targets )
185
195
186
196
elif args .action == 'clean' :
187
197
print ('Cleaning ' + args .build_path )
@@ -191,7 +201,6 @@ def handle_invocation(args):
191
201
tool_path = os .path .join (toolchain_bin , tool )
192
202
if os .path .exists (tool_path ):
193
203
env ['SWIFT_DRIVER_' + tool .upper ().replace ('-' ,'_' ) + '_EXEC' ] = '%s' % (tool_path )
194
- env ['SWIFT_EXEC' ] = '%sc' % (swift_exec )
195
204
test_args = swiftpm_args
196
205
test_args += ['-Xswiftc' , '-enable-testing' ]
197
206
if should_test_parallel ():
@@ -208,16 +217,17 @@ def handle_invocation(args):
208
217
else :
209
218
bin_path = swiftpm_bin_path (swift_exec , swiftpm_args , env )
210
219
swiftpm ('build' , swift_exec , swiftpm_args , env )
211
- non_darwin_install (bin_path , args . toolchain , args . verbose )
220
+ non_darwin_install (args , bin_path )
212
221
else :
213
222
assert False , 'unknown action \' {}\' ' .format (args .action )
214
223
215
224
# Installation flow for non-darwin platforms, only copies over swift-driver and swift-help
216
225
# TODO: Unify CMake-based installation flow used on Darwin with this
217
- def non_darwin_install (swiftpm_bin_path , toolchain , verbose ):
218
- toolchain_bin = os .path .join (toolchain , 'bin' )
219
- for exe in executables_to_install :
220
- install_binary (exe , swiftpm_bin_path , toolchain_bin , verbose )
226
+ def non_darwin_install (args , swiftpm_bin_path ):
227
+ for prefix in args .install_prefixes :
228
+ prefix_bin = os .path .join (prefix , 'bin' )
229
+ for exe in executables_to_install :
230
+ install_binary (exe , swiftpm_bin_path , prefix_bin , args .verbose )
221
231
222
232
def install (args , build_dir , targets ):
223
233
# Construct and install universal swift-driver, swift-help executables
@@ -584,6 +594,10 @@ def add_common_args(parser):
584
594
nargs = '*' ,
585
595
help = 'List of cross compile hosts targets.' ,
586
596
default = [])
597
+ parser .add_argument (
598
+ '--cross-compile-config' ,
599
+ metavar = 'PATH' ,
600
+ help = "A JSON SPM config file with Swift flags for cross-compilation" )
587
601
parser .add_argument ('--ninja-bin' , metavar = 'PATH' , help = 'ninja binary to use for testing' )
588
602
parser .add_argument ('--cmake-bin' , metavar = 'PATH' , help = 'cmake binary to use for building' )
589
603
parser .add_argument ('--build-path' , metavar = 'PATH' , default = '.build' , help = 'build in the given path' )
@@ -626,6 +640,8 @@ def add_common_args(parser):
626
640
args .cross_compile_hosts = [build_target + macos_deployment_target , 'arm64-apple-macosx%s' % macos_deployment_target ]
627
641
elif (build_target == 'arm64-apple-macosx' and 'macosx-x86_64' in args .cross_compile_hosts ):
628
642
args .cross_compile_hosts = [build_target + macos_deployment_target , 'x86_64-apple-macosx%s' % macos_deployment_target ]
643
+ elif args .cross_compile_hosts and re .match ('android-' , args .cross_compile_hosts [0 ]):
644
+ print ('Cross-compiling for %s' % args .cross_compile_hosts [0 ])
629
645
elif args .cross_compile_hosts :
630
646
error ("cannot cross-compile for %s" % cross_compile_hosts )
631
647
0 commit comments