@@ -68,10 +68,13 @@ 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
80
if platform .system () == 'Darwin' :
@@ -121,21 +124,23 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
121
124
os .path .join (args .toolchain , 'lib' , 'swift' , 'Block' ),
122
125
]
123
126
127
+ build_target = get_build_target (swift_exec , args , cross_compile = (True if args .cross_compile_config else False ))
128
+ build_arch = build_target .split ('-' )[0 ]
129
+ build_os = build_target .split ('-' )[2 ]
124
130
if 'ANDROID_DATA' in os .environ or (args .cross_compile_host and re .match (
125
131
'android-' , args .cross_compile_host )):
126
132
swiftpm_args += [
127
- '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/android' ,
133
+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/android/' + build_arch ,
128
134
# SwiftPM will otherwise try to compile against GNU strerror_r on
129
135
# Android and fail.
130
136
'-Xswiftc' , '-Xcc' , '-Xswiftc' , '-U_GNU_SOURCE' ,
131
137
]
132
- elif platform .system () == 'Linux ' :
138
+ elif platform .system () != 'Darwin ' :
133
139
# Library rpath for swift, dispatch, Foundation, etc. when installing
134
140
swiftpm_args += [
135
- '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/linux' ,
141
+ '-Xlinker' , '-rpath' , '-Xlinker' , '$ORIGIN/../lib/swift/' + build_os + '/' + build_arch ,
136
142
]
137
143
138
- build_target = get_build_target (swift_exec , args )
139
144
if args .cross_compile_host :
140
145
if re .search ('-apple-macosx' , build_target ) and re .match ('macosx-' , args .cross_compile_host ):
141
146
swiftpm_args += ["--arch" , "x86_64" , "--arch" , "arm64" ]
0 commit comments