@@ -97,28 +97,39 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
9797 _ => os. into ( ) ,
9898 } ;
9999
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 ( ) ;
110111
111112 let mut args = TargetOptions :: link_args (
112113 LinkerFlavor :: Darwin ( Cc :: No , Lld :: No ) ,
113- & [ "-arch" , arch, "-platform_version" ] ,
114+ & [ "-arch" , arch. target_name ( ) , "-platform_version" ] ,
114115 ) ;
115116 add_link_args_iter (
116117 & mut args,
117118 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 ( ) ,
119120 ) ;
120121 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+ ) ;
122133 }
123134
124135 args
@@ -131,7 +142,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
131142 abi : abi. into ( ) ,
132143 os : os. into ( ) ,
133144 cpu : arch. target_cpu ( ) . into ( ) ,
134- link_env_remove : link_env_remove ( arch , os) ,
145+ link_env_remove : link_env_remove ( os) ,
135146 vendor : "apple" . into ( ) ,
136147 linker_flavor : LinkerFlavor :: Darwin ( Cc :: Yes , Lld :: No ) ,
137148 // macOS has -dead_strip, which doesn't rely on function_sections
@@ -220,16 +231,13 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
220231 } ;
221232 macos_deployment_target ( arch)
222233 }
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+ }
233241 "watchos" => watchos_deployment_target ( ) ,
234242 "tvos" => tvos_deployment_target ( ) ,
235243 _ => return None ,
@@ -260,17 +268,12 @@ fn macos_deployment_target(arch: Arch) -> (u32, u32) {
260268 . unwrap_or_else ( || macos_default_deployment_target ( arch) )
261269}
262270
263- fn macos_lld_platform_version ( arch : Arch ) -> String {
264- let ( major, minor) = macos_deployment_target ( arch) ;
265- format ! ( "{major}.{minor}" )
266- }
267-
268271pub fn macos_llvm_target ( arch : Arch ) -> String {
269272 let ( major, minor) = macos_deployment_target ( arch) ;
270273 format ! ( "{}-apple-macosx{}.{}.0" , arch. target_name( ) , major, minor)
271274}
272275
273- fn link_env_remove ( arch : Arch , os : & ' static str ) -> StaticCow < [ StaticCow < str > ] > {
276+ fn link_env_remove ( os : & ' static str ) -> StaticCow < [ StaticCow < str > ] > {
274277 // Apple platforms only officially support macOS as a host for any compilation.
275278 //
276279 // 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>]>
298301 env_remove. push ( "TVOS_DEPLOYMENT_TARGET" . into ( ) ) ;
299302 env_remove. into ( )
300303 } 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
302305 // 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" ]
310307 }
311308}
312309
313- fn ios_deployment_target ( arch : Arch ) -> ( u32 , u32 ) {
310+ fn ios_deployment_target ( arch : Arch , abi : & str ) -> ( u32 , u32 ) {
314311 // 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+ } ;
316318 from_set_deployment_target ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( major, minor) )
317319}
318320
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-
324321pub fn ios_llvm_target ( arch : Arch ) -> String {
325322 // Modern iOS tooling extracts information about deployment target
326323 // from LC_BUILD_VERSION. This load command will only be emitted when
327324 // we build with a version specific `llvm_target`, with the version
328325 // set high enough. Luckily one LC_BUILD_VERSION is enough, for Xcode
329326 // to pick it up (since std and core are still built with the fallback
330327 // 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, "" ) ;
332329 format ! ( "{}-apple-ios{}.{}.0" , arch. target_name( ) , major, minor)
333330}
334331
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 )
338335}
339336
340337pub 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" ) ;
342339 format ! ( "{}-apple-ios{}.{}.0-simulator" , arch. target_name( ) , major, minor)
343340}
344341
@@ -347,11 +344,6 @@ fn tvos_deployment_target() -> (u32, u32) {
347344 from_set_deployment_target ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 10 , 0 ) )
348345}
349346
350- fn tvos_lld_platform_version ( ) -> String {
351- let ( major, minor) = tvos_deployment_target ( ) ;
352- format ! ( "{major}.{minor}" )
353- }
354-
355347pub fn tvos_llvm_target ( arch : Arch ) -> String {
356348 let ( major, minor) = tvos_deployment_target ( ) ;
357349 format ! ( "{}-apple-tvos{}.{}.0" , arch. target_name( ) , major, minor)
@@ -367,11 +359,6 @@ fn watchos_deployment_target() -> (u32, u32) {
367359 from_set_deployment_target ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 5 , 0 ) )
368360}
369361
370- fn watchos_lld_platform_version ( ) -> String {
371- let ( major, minor) = watchos_deployment_target ( ) ;
372- format ! ( "{major}.{minor}" )
373- }
374-
375362pub fn watchos_sim_llvm_target ( arch : Arch ) -> String {
376363 let ( major, minor) = watchos_deployment_target ( ) ;
377364 format ! ( "{}-apple-watchos{}.{}.0-simulator" , arch. target_name( ) , major, minor)
0 commit comments