11use  std:: { borrow:: Cow ,  env} ; 
22
33use  crate :: spec:: { cvs,  Cc ,  DebuginfoKind ,  FramePointer ,  LinkArgs } ; 
4- use  crate :: spec:: { LinkerFlavor ,  Lld ,  SplitDebuginfo ,  StaticCow ,  TargetOptions } ; 
4+ use  crate :: spec:: { LinkerFlavor ,  Lld ,  SplitDebuginfo ,  StaticCow ,  Target ,   TargetOptions } ; 
55
66#[ cfg( test) ]  
77#[ path = "apple/tests.rs" ]  
@@ -179,12 +179,28 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
179179    } 
180180} 
181181
182- fn  deployment_target ( var_name :  & str )  -> Option < ( u32 ,  u32 ) >  { 
183-     let  deployment_target = env:: var ( var_name) . ok ( ) ; 
184-     deployment_target
185-         . as_ref ( ) 
186-         . and_then ( |s| s. split_once ( '.' ) ) 
187-         . and_then ( |( a,  b) | a. parse :: < u32 > ( ) . and_then ( |a| b. parse :: < u32 > ( ) . map ( |b| ( a,  b) ) ) . ok ( ) ) 
182+ pub  fn  deployment_target ( target :  & Target )  -> Option < String >  { 
183+     let  ( major,  minor)  = match  & * target. os  { 
184+         "macos"  => { 
185+             // This does not need to be specific. It just needs to handle x86 vs M1. 
186+             let  arch = if  target. arch  == "x86"  || target. arch  == "x86_64"  {  X86_64  }  else  {  Arm64  } ; 
187+             macos_deployment_target ( arch) 
188+         } 
189+         "ios"  => ios_deployment_target ( ) , 
190+         "watchos"  => watchos_deployment_target ( ) , 
191+         "tvos"  => tvos_deployment_target ( ) , 
192+         _ => return  None , 
193+     } ; 
194+ 
195+     Some ( format ! ( "{major}.{minor}" ) ) 
196+ } 
197+ 
198+ fn  from_set_deployment_target ( var_name :  & str )  -> Option < ( u32 ,  u32 ) >  { 
199+     let  deployment_target = env:: var ( var_name) . ok ( ) ?; 
200+     let  ( unparsed_major,  unparsed_minor)  = deployment_target. split_once ( '.' ) ?; 
201+     let  ( major,  minor)  = ( unparsed_major. parse ( ) . ok ( ) ?,  unparsed_minor. parse ( ) . ok ( ) ?) ; 
202+ 
203+     Some ( ( major,  minor) ) 
188204} 
189205
190206fn  macos_default_deployment_target ( arch :  Arch )  -> ( u32 ,  u32 )  { 
@@ -198,7 +214,8 @@ fn macos_default_deployment_target(arch: Arch) -> (u32, u32) {
198214} 
199215
200216fn  macos_deployment_target ( arch :  Arch )  -> ( u32 ,  u32 )  { 
201-     deployment_target ( "MACOSX_DEPLOYMENT_TARGET" ) 
217+     // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. 
218+     from_set_deployment_target ( "MACOSX_DEPLOYMENT_TARGET" ) 
202219        . unwrap_or_else ( || macos_default_deployment_target ( arch) ) 
203220} 
204221
@@ -247,7 +264,8 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
247264} 
248265
249266fn  ios_deployment_target ( )  -> ( u32 ,  u32 )  { 
250-     deployment_target ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 7 ,  0 ) ) 
267+     // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. 
268+     from_set_deployment_target ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 7 ,  0 ) ) 
251269} 
252270
253271pub  fn  ios_llvm_target ( arch :  Arch )  -> String  { 
@@ -272,7 +290,8 @@ pub fn ios_sim_llvm_target(arch: Arch) -> String {
272290} 
273291
274292fn  tvos_deployment_target ( )  -> ( u32 ,  u32 )  { 
275-     deployment_target ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 7 ,  0 ) ) 
293+     // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. 
294+     from_set_deployment_target ( "TVOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 7 ,  0 ) ) 
276295} 
277296
278297fn  tvos_lld_platform_version ( )  -> String  { 
@@ -281,7 +300,8 @@ fn tvos_lld_platform_version() -> String {
281300} 
282301
283302fn  watchos_deployment_target ( )  -> ( u32 ,  u32 )  { 
284-     deployment_target ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 5 ,  0 ) ) 
303+     // If you are looking for the default deployment target, prefer `rustc --print deployment-target`. 
304+     from_set_deployment_target ( "WATCHOS_DEPLOYMENT_TARGET" ) . unwrap_or ( ( 5 ,  0 ) ) 
285305} 
286306
287307fn  watchos_lld_platform_version ( )  -> String  { 
0 commit comments