@@ -45,6 +45,7 @@ use rustc_target::spec::{
4545use tempfile:: Builder as TempFileBuilder ;
4646use tracing:: { debug, info, warn} ;
4747
48+ use super :: apple;
4849use super :: archive:: { ArchiveBuilder , ArchiveBuilderBuilder } ;
4950use super :: command:: Command ;
5051use super :: linker:: { self , Linker } ;
@@ -3125,9 +3126,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
31253126}
31263127
31273128fn add_apple_sdk ( cmd : & mut dyn Linker , sess : & Session , flavor : LinkerFlavor ) -> Option < PathBuf > {
3128- let arch = & sess. target . arch ;
31293129 let os = & sess. target . os ;
3130- let llvm_target = & sess. target . llvm_target ;
31313130 if sess. target . vendor != "apple"
31323131 || !matches ! ( os. as_ref( ) , "ios" | "tvos" | "watchos" | "visionos" | "macos" )
31333132 || !matches ! ( flavor, LinkerFlavor :: Darwin ( ..) )
@@ -3139,30 +3138,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) ->
31393138 return None ;
31403139 }
31413140
3142- let sdk_name = match ( arch. as_ref ( ) , os. as_ref ( ) ) {
3143- ( "aarch64" , "tvos" ) if llvm_target. ends_with ( "-simulator" ) => "appletvsimulator" ,
3144- ( "aarch64" , "tvos" ) => "appletvos" ,
3145- ( "x86_64" , "tvos" ) => "appletvsimulator" ,
3146- ( "arm" , "ios" ) => "iphoneos" ,
3147- ( "aarch64" , "ios" ) if llvm_target. contains ( "macabi" ) => "macosx" ,
3148- ( "aarch64" , "ios" ) if llvm_target. ends_with ( "-simulator" ) => "iphonesimulator" ,
3149- ( "aarch64" , "ios" ) => "iphoneos" ,
3150- ( "x86" , "ios" ) => "iphonesimulator" ,
3151- ( "x86_64" , "ios" ) if llvm_target. contains ( "macabi" ) => "macosx" ,
3152- ( "x86_64" , "ios" ) => "iphonesimulator" ,
3153- ( "x86_64" , "watchos" ) => "watchsimulator" ,
3154- ( "arm64_32" , "watchos" ) => "watchos" ,
3155- ( "aarch64" , "watchos" ) if llvm_target. ends_with ( "-simulator" ) => "watchsimulator" ,
3156- ( "aarch64" , "watchos" ) => "watchos" ,
3157- ( "aarch64" , "visionos" ) if llvm_target. ends_with ( "-simulator" ) => "xrsimulator" ,
3158- ( "aarch64" , "visionos" ) => "xros" ,
3159- ( "arm" , "watchos" ) => "watchos" ,
3160- ( _, "macos" ) => "macosx" ,
3161- _ => {
3162- sess. dcx ( ) . emit_err ( errors:: UnsupportedArch { arch, os } ) ;
3163- return None ;
3164- }
3165- } ;
3141+ let sdk_name = apple:: sdk_name ( & sess. target ) ;
3142+
31663143 let sdk_root = match get_apple_sdk_root ( sdk_name) {
31673144 Ok ( s) => s,
31683145 Err ( e) => {
@@ -3199,7 +3176,7 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
31993176 // can fall back to checking for xcrun on PATH.)
32003177 if let Ok ( sdkroot) = env:: var ( "SDKROOT" ) {
32013178 let p = Path :: new ( & sdkroot) ;
3202- match sdk_name {
3179+ match & * sdk_name. to_lowercase ( ) {
32033180 // Ignore `SDKROOT` if it's clearly set for the wrong platform.
32043181 "appletvos"
32053182 if sdkroot. contains ( "TVSimulator.platform" )
@@ -3230,18 +3207,21 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
32303207 _ => return Ok ( sdkroot) ,
32313208 }
32323209 }
3233- let res =
3234- Command :: new ( "xcrun" ) . arg ( "--show-sdk-path" ) . arg ( "-sdk" ) . arg ( sdk_name) . output ( ) . and_then (
3235- |output| {
3236- if output. status . success ( ) {
3237- Ok ( String :: from_utf8 ( output. stdout ) . unwrap ( ) )
3238- } else {
3239- let error = String :: from_utf8 ( output. stderr ) ;
3240- let error = format ! ( "process exit with error: {}" , error. unwrap( ) ) ;
3241- Err ( io:: Error :: new ( io:: ErrorKind :: Other , & error[ ..] ) )
3242- }
3243- } ,
3244- ) ;
3210+
3211+ let res = Command :: new ( "xcrun" )
3212+ . arg ( "--show-sdk-path" )
3213+ . arg ( "-sdk" )
3214+ . arg ( sdk_name. to_lowercase ( ) )
3215+ . output ( )
3216+ . and_then ( |output| {
3217+ if output. status . success ( ) {
3218+ Ok ( String :: from_utf8 ( output. stdout ) . unwrap ( ) )
3219+ } else {
3220+ let error = String :: from_utf8 ( output. stderr ) ;
3221+ let error = format ! ( "process exit with error: {}" , error. unwrap( ) ) ;
3222+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , & error[ ..] ) )
3223+ }
3224+ } ) ;
32453225
32463226 match res {
32473227 Ok ( output) => Ok ( output. trim ( ) . to_string ( ) ) ,
0 commit comments