19
19
import json
20
20
import sys
21
21
import os , platform
22
- import re
23
22
import subprocess
24
23
25
24
def printerr (message ):
@@ -159,7 +158,9 @@ def get_swiftpm_options(action, args):
159
158
if args .verbose or action == 'install' :
160
159
swiftpm_args += ['--verbose' ]
161
160
162
- if platform .system () == 'Darwin' :
161
+ build_target = get_build_target (args )
162
+ build_os = build_target .split ('-' )[2 ]
163
+ if build_os .startswith ('macosx' ):
163
164
swiftpm_args += [
164
165
# Relative library rpath for swift; will only be used when /usr/lib/swift
165
166
# is not available.
@@ -168,13 +169,12 @@ def get_swiftpm_options(action, args):
168
169
else :
169
170
swiftpm_args += [
170
171
# Library rpath for swift, dispatch, Foundation, etc. when installing
171
- '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/linux' ,
172
+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/' + build_os ,
172
173
]
173
174
174
- build_target = get_build_target (args )
175
175
cross_compile_hosts = args .cross_compile_hosts
176
176
if cross_compile_hosts :
177
- if re . search ( '-apple- macosx', build_target ) and re . match ('macosx-' , cross_compile_hosts ):
177
+ if build_os . startswith ( ' macosx' ) and cross_compile_hosts . startswith ('macosx-' ):
178
178
swiftpm_args += ["--arch" , "x86_64" , "--arch" , "arm64" ]
179
179
else :
180
180
printerr ("cannot cross-compile for %s" % cross_compile_hosts )
@@ -290,7 +290,7 @@ def get_build_target(args):
290
290
command = [args .swift_exec , '-print-target-info' ]
291
291
target_info_json = subprocess .check_output (command , stderr = subprocess .PIPE , universal_newlines = True ).strip ()
292
292
args .target_info = json .loads (target_info_json )
293
- if platform . system () == 'Darwin' :
293
+ if '-apple-macosx' in args . target_info [ "target" ][ "unversionedTriple" ] :
294
294
return args .target_info ["target" ]["unversionedTriple" ]
295
295
296
296
return args .target_info ["target" ]["triple" ]
0 commit comments