1919import json
2020import sys
2121import os , platform
22- import re
2322import subprocess
2423
2524def printerr (message ):
@@ -159,7 +158,9 @@ def get_swiftpm_options(action, args):
159158 if args .verbose or action == 'install' :
160159 swiftpm_args += ['--verbose' ]
161160
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' ):
163164 swiftpm_args += [
164165 # Relative library rpath for swift; will only be used when /usr/lib/swift
165166 # is not available.
@@ -168,13 +169,12 @@ def get_swiftpm_options(action, args):
168169 else :
169170 swiftpm_args += [
170171 # 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 ,
172173 ]
173174
174- build_target = get_build_target (args )
175175 cross_compile_hosts = args .cross_compile_hosts
176176 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-' ):
178178 swiftpm_args += ["--arch" , "x86_64" , "--arch" , "arm64" ]
179179 else :
180180 printerr ("cannot cross-compile for %s" % cross_compile_hosts )
@@ -290,7 +290,7 @@ def get_build_target(args):
290290 command = [args .swift_exec , '-print-target-info' ]
291291 target_info_json = subprocess .check_output (command , stderr = subprocess .PIPE , universal_newlines = True ).strip ()
292292 args .target_info = json .loads (target_info_json )
293- if platform . system () == 'Darwin' :
293+ if '-apple-macosx' in args . target_info [ "target" ][ "unversionedTriple" ] :
294294 return args .target_info ["target" ]["unversionedTriple" ]
295295
296296 return args .target_info ["target" ]["triple" ]
0 commit comments