@@ -68,13 +68,16 @@ def swiftpm_bin_path(swift_exec: str, swiftpm_args: List[str], additional_env: D
68
68
return check_output (cmd , additional_env = additional_env , capture_stderr = False , verbose = verbose ).strip ()
69
69
70
70
71
- def get_build_target (swift_exec : str , args : argparse .Namespace ) -> str :
71
+ def get_build_target (swift_exec : str , args : argparse .Namespace , cross_compile : bool = False ) -> str :
72
72
"""Returns the target-triple of the current machine or for cross-compilation."""
73
73
try :
74
74
command = [swift_exec , '-print-target-info' ]
75
+ if cross_compile :
76
+ cross_compile_json = json .load (open (args .cross_compile_config ))
77
+ command += ['-target' , cross_compile_json ["target" ]]
75
78
target_info_json = subprocess .check_output (command , stderr = subprocess .PIPE , universal_newlines = True ).strip ()
76
79
args .target_info = json .loads (target_info_json )
77
- if platform . system () == 'Darwin' :
80
+ if re . search ( '-apple-macosx' , args . target_info [ "target" ][ "unversionedTriple" ]) :
78
81
return args .target_info ["target" ]["unversionedTriple" ]
79
82
return args .target_info ["target" ]["triple" ]
80
83
except Exception as e :
@@ -105,7 +108,10 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
105
108
for san in args .sanitize :
106
109
swiftpm_args += ['--sanitize=%s' % san ]
107
110
108
- if platform .system () == 'Darwin' :
111
+ build_target = get_build_target (swift_exec , args , cross_compile = (True if args .cross_compile_config else False ))
112
+ build_arch = build_target .split ('-' )[0 ]
113
+ build_os = build_target .split ('-' )[2 ]
114
+ if re .search ('-apple-macosx' , build_target ):
109
115
swiftpm_args += [
110
116
'-Xlinker' , '-rpath' , '-Xlinker' , '/usr/lib/swift' ,
111
117
'-Xlinker' , '-rpath' , '-Xlinker' , '@executable_path/../lib/swift/macosx' ,
@@ -121,21 +127,19 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
121
127
os .path .join (args .toolchain , 'lib' , 'swift' , 'Block' ),
122
128
]
123
129
124
- if 'ANDROID_DATA' in os .environ or (args .cross_compile_host and re .match (
125
- 'android-' , args .cross_compile_host )):
130
+ if re .search ('-android' , build_target ):
126
131
swiftpm_args += [
127
- '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/android' ,
132
+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/android/' + build_arch ,
128
133
# SwiftPM will otherwise try to compile against GNU strerror_r on
129
134
# Android and fail.
130
135
'-Xswiftc' , '-Xcc' , '-Xswiftc' , '-U_GNU_SOURCE' ,
131
136
]
132
- elif platform . system () == 'Linux' :
137
+ elif not re . search ( '-apple-macosx' , build_target ) :
133
138
# Library rpath for swift, dispatch, Foundation, etc. when installing
134
139
swiftpm_args += [
135
- '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/linux' ,
140
+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/' + build_os + '/' + build_arch ,
136
141
]
137
142
138
- build_target = get_build_target (swift_exec , args )
139
143
if args .cross_compile_host :
140
144
if re .search ('-apple-macosx' , build_target ) and re .match ('macosx-' , args .cross_compile_host ):
141
145
swiftpm_args += ["--arch" , "x86_64" , "--arch" , "arm64" ]
0 commit comments