@@ -97,28 +97,39 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
97
97
_ => os. into ( ) ,
98
98
} ;
99
99
100
- let platform_version: StaticCow < str > = match os {
101
- "ios" => ios_lld_platform_version ( arch) ,
102
- "tvos" => tvos_lld_platform_version ( ) ,
103
- "watchos" => watchos_lld_platform_version ( ) ,
104
- "macos" => macos_lld_platform_version ( arch) ,
105
- _ => unreachable ! ( ) ,
106
- }
107
- . into ( ) ;
108
-
109
- let arch = arch. target_name ( ) ;
100
+ let min_version: StaticCow < str > = {
101
+ let ( major, minor) = match os {
102
+ "ios" => ios_deployment_target ( arch, abi) ,
103
+ "tvos" => tvos_deployment_target ( ) ,
104
+ "watchos" => watchos_deployment_target ( ) ,
105
+ "macos" => macos_deployment_target ( arch) ,
106
+ _ => unreachable ! ( ) ,
107
+ } ;
108
+ format ! ( "{major}.{minor}" ) . into ( )
109
+ } ;
110
+ let sdk_version = min_version. clone ( ) ;
110
111
111
112
let mut args = TargetOptions :: link_args (
112
113
LinkerFlavor :: Darwin ( Cc :: No , Lld :: No ) ,
113
- & [ "-arch" , arch, "-platform_version" ] ,
114
+ & [ "-arch" , arch. target_name ( ) , "-platform_version" ] ,
114
115
) ;
115
116
add_link_args_iter (
116
117
& mut args,
117
118
LinkerFlavor :: Darwin ( Cc :: No , Lld :: No ) ,
118
- [ platform_name, platform_version . clone ( ) , platform_version ] . into_iter ( ) ,
119
+ [ platform_name, min_version , sdk_version ] . into_iter ( ) ,
119
120
) ;
120
121
if abi != "macabi" {
121
- add_link_args ( & mut args, LinkerFlavor :: Darwin ( Cc :: Yes , Lld :: No ) , & [ "-arch" , arch] ) ;
122
+ add_link_args (
123
+ & mut args,
124
+ LinkerFlavor :: Darwin ( Cc :: Yes , Lld :: No ) ,
125
+ & [ "-arch" , arch. target_name ( ) ] ,
126
+ ) ;
127
+ } else {
128
+ add_link_args_iter (
129
+ & mut args,
130
+ LinkerFlavor :: Darwin ( Cc :: Yes , Lld :: No ) ,
131
+ [ "-target" . into ( ) , mac_catalyst_llvm_target ( arch) . into ( ) ] . into_iter ( ) ,
132
+ ) ;
122
133
}
123
134
124
135
args
@@ -131,7 +142,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
131
142
abi : abi. into ( ) ,
132
143
os : os. into ( ) ,
133
144
cpu : arch. target_cpu ( ) . into ( ) ,
134
- link_env_remove : link_env_remove ( arch , os) ,
145
+ link_env_remove : link_env_remove ( os) ,
135
146
vendor : "apple" . into ( ) ,
136
147
linker_flavor : LinkerFlavor :: Darwin ( Cc :: Yes , Lld :: No ) ,
137
148
// macOS has -dead_strip, which doesn't rely on function_sections
@@ -220,16 +231,13 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
220
231
} ;
221
232
macos_deployment_target ( arch)
222
233
}
223
- "ios" => match & * target. abi {
224
- "macabi" => mac_catalyst_deployment_target ( ) ,
225
- _ => {
226
- let arch = match target. arch . as_ref ( ) {
227
- "arm64e" => Arm64e ,
228
- _ => Arm64 ,
229
- } ;
230
- ios_deployment_target ( arch)
231
- }
232
- } ,
234
+ "ios" => {
235
+ let arch = match target. arch . as_ref ( ) {
236
+ "arm64e" => Arm64e ,
237
+ _ => Arm64 ,
238
+ } ;
239
+ ios_deployment_target ( arch, & target. abi )
240
+ }
233
241
"watchos" => watchos_deployment_target ( ) ,
234
242
"tvos" => tvos_deployment_target ( ) ,
235
243
_ => return None ,
@@ -260,17 +268,12 @@ fn macos_deployment_target(arch: Arch) -> (u32, u32) {
260
268
. unwrap_or_else ( || macos_default_deployment_target ( arch) )
261
269
}
262
270
263
- fn macos_lld_platform_version ( arch : Arch ) -> String {
264
- let ( major, minor) = macos_deployment_target ( arch) ;
265
- format ! ( "{major}.{minor}" )
266
- }
267
-
268
271
pub fn macos_llvm_target ( arch : Arch ) -> String {
269
272
let ( major, minor) = macos_deployment_target ( arch) ;
270
273
format ! ( "{}-apple-macosx{}.{}.0" , arch. target_name( ) , major, minor)
271
274
}
272
275
273
- fn link_env_remove ( arch : Arch , os : & ' static str ) -> StaticCow < [ StaticCow < str > ] > {
276
+ fn link_env_remove ( os : & ' static str ) -> StaticCow < [ StaticCow < str > ] > {
274
277
// Apple platforms only officially support macOS as a host for any compilation.
275
278
//
276
279
// If building for macOS, we go ahead and remove any erroneous environment state
@@ -298,47 +301,41 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
298
301
env_remove. push ( "TVOS_DEPLOYMENT_TARGET" . into ( ) ) ;
299
302
env_remove. into ( )
300
303
} else {
301
- // Otherwise if cross-compiling for a different OS/SDK, remove any part
304
+ // Otherwise if cross-compiling for a different OS/SDK (including Mac Catalyst) , remove any part
302
305
// of the linking environment that's wrong and reversed.
303
- match arch {
304
- Armv7k | Armv7s | Arm64 | Arm64e | Arm64_32 | I386 | I386_sim | I686 | X86_64
305
- | X86_64_sim | X86_64h | Arm64_sim => {
306
- cvs ! [ "MACOSX_DEPLOYMENT_TARGET" ]
307
- }
308
- X86_64_macabi | Arm64_macabi => cvs ! [ "IPHONEOS_DEPLOYMENT_TARGET" ] ,
309
- }
306
+ cvs ! [ "MACOSX_DEPLOYMENT_TARGET" ]
310
307
}
311
308
}
312
309
313
- fn ios_deployment_target ( arch : Arch ) -> ( u32 , u32 ) {
310
+ fn ios_deployment_target ( arch : Arch , abi : & str ) -> ( u32 , u32 ) {
314
311
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
315
- let ( major, minor) = if arch == Arm64e { ( 14 , 0 ) } else { ( 10 , 0 ) } ;
312
+ let ( major, minor) = match ( arch, abi) {
313
+ ( Arm64e , _) => ( 14 , 0 ) ,
314
+ // Mac Catalyst defaults to 13.1 in Clang.
315
+ ( _, "macabi" ) => ( 13 , 1 ) ,
316
+ _ => ( 10 , 0 ) ,
317
+ } ;
316
318
from_set_deployment_target ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( major, minor) )
317
319
}
318
320
319
- fn mac_catalyst_deployment_target ( ) -> ( u32 , u32 ) {
320
- // If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
321
- from_set_deployment_target ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 14 , 0 ) )
322
- }
323
-
324
321
pub fn ios_llvm_target ( arch : Arch ) -> String {
325
322
// Modern iOS tooling extracts information about deployment target
326
323
// from LC_BUILD_VERSION. This load command will only be emitted when
327
324
// we build with a version specific `llvm_target`, with the version
328
325
// set high enough. Luckily one LC_BUILD_VERSION is enough, for Xcode
329
326
// to pick it up (since std and core are still built with the fallback
330
327
// of version 7.0 and hence emit the old LC_IPHONE_MIN_VERSION).
331
- let ( major, minor) = ios_deployment_target ( arch) ;
328
+ let ( major, minor) = ios_deployment_target ( arch, "" ) ;
332
329
format ! ( "{}-apple-ios{}.{}.0" , arch. target_name( ) , major, minor)
333
330
}
334
331
335
- fn ios_lld_platform_version ( arch : Arch ) -> String {
336
- let ( major, minor) = ios_deployment_target ( arch) ;
337
- format ! ( "{major}.{minor}" )
332
+ pub fn mac_catalyst_llvm_target ( arch : Arch ) -> String {
333
+ let ( major, minor) = ios_deployment_target ( arch, "macabi" ) ;
334
+ format ! ( "{}-apple-ios{}.{}.0-macabi" , arch . target_name ( ) , major , minor )
338
335
}
339
336
340
337
pub fn ios_sim_llvm_target ( arch : Arch ) -> String {
341
- let ( major, minor) = ios_deployment_target ( arch) ;
338
+ let ( major, minor) = ios_deployment_target ( arch, "sim" ) ;
342
339
format ! ( "{}-apple-ios{}.{}.0-simulator" , arch. target_name( ) , major, minor)
343
340
}
344
341
@@ -347,11 +344,6 @@ fn tvos_deployment_target() -> (u32, u32) {
347
344
from_set_deployment_target ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 10 , 0 ) )
348
345
}
349
346
350
- fn tvos_lld_platform_version ( ) -> String {
351
- let ( major, minor) = tvos_deployment_target ( ) ;
352
- format ! ( "{major}.{minor}" )
353
- }
354
-
355
347
pub fn tvos_llvm_target ( arch : Arch ) -> String {
356
348
let ( major, minor) = tvos_deployment_target ( ) ;
357
349
format ! ( "{}-apple-tvos{}.{}.0" , arch. target_name( ) , major, minor)
@@ -367,11 +359,6 @@ fn watchos_deployment_target() -> (u32, u32) {
367
359
from_set_deployment_target ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 5 , 0 ) )
368
360
}
369
361
370
- fn watchos_lld_platform_version ( ) -> String {
371
- let ( major, minor) = watchos_deployment_target ( ) ;
372
- format ! ( "{major}.{minor}" )
373
- }
374
-
375
362
pub fn watchos_sim_llvm_target ( arch : Arch ) -> String {
376
363
let ( major, minor) = watchos_deployment_target ( ) ;
377
364
format ! ( "{}-apple-watchos{}.{}.0-simulator" , arch. target_name( ) , major, minor)
0 commit comments