@@ -3123,9 +3123,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
31233123}
31243124
31253125fn add_apple_sdk ( cmd : & mut dyn Linker , sess : & Session , flavor : LinkerFlavor ) -> Option < PathBuf > {
3126- let arch = & sess. target . arch ;
31273126 let os = & sess. target . os ;
3128- let llvm_target = & sess. target . llvm_target ;
31293127 if sess. target . vendor != "apple"
31303128 || !matches ! ( os. as_ref( ) , "ios" | "tvos" | "watchos" | "visionos" | "macos" )
31313129 || !matches ! ( flavor, LinkerFlavor :: Darwin ( ..) )
@@ -3137,30 +3135,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) ->
31373135 return None ;
31383136 }
31393137
3140- let sdk_name = match ( arch. as_ref ( ) , os. as_ref ( ) ) {
3141- ( "aarch64" , "tvos" ) if llvm_target. ends_with ( "-simulator" ) => "appletvsimulator" ,
3142- ( "aarch64" , "tvos" ) => "appletvos" ,
3143- ( "x86_64" , "tvos" ) => "appletvsimulator" ,
3144- ( "arm" , "ios" ) => "iphoneos" ,
3145- ( "aarch64" , "ios" ) if llvm_target. contains ( "macabi" ) => "macosx" ,
3146- ( "aarch64" , "ios" ) if llvm_target. ends_with ( "-simulator" ) => "iphonesimulator" ,
3147- ( "aarch64" , "ios" ) => "iphoneos" ,
3148- ( "x86" , "ios" ) => "iphonesimulator" ,
3149- ( "x86_64" , "ios" ) if llvm_target. contains ( "macabi" ) => "macosx" ,
3150- ( "x86_64" , "ios" ) => "iphonesimulator" ,
3151- ( "x86_64" , "watchos" ) => "watchsimulator" ,
3152- ( "arm64_32" , "watchos" ) => "watchos" ,
3153- ( "aarch64" , "watchos" ) if llvm_target. ends_with ( "-simulator" ) => "watchsimulator" ,
3154- ( "aarch64" , "watchos" ) => "watchos" ,
3155- ( "aarch64" , "visionos" ) if llvm_target. ends_with ( "-simulator" ) => "xrsimulator" ,
3156- ( "aarch64" , "visionos" ) => "xros" ,
3157- ( "arm" , "watchos" ) => "watchos" ,
3158- ( _, "macos" ) => "macosx" ,
3159- _ => {
3160- sess. dcx ( ) . emit_err ( errors:: UnsupportedArch { arch, os } ) ;
3161- return None ;
3162- }
3163- } ;
3138+ let sdk_name = rustc_target:: spec:: apple_sdk_name ( & sess. target ) ;
3139+
31643140 let sdk_root = match get_apple_sdk_root ( sdk_name) {
31653141 Ok ( s) => s,
31663142 Err ( e) => {
@@ -3197,7 +3173,7 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
31973173 // can fall back to checking for xcrun on PATH.)
31983174 if let Ok ( sdkroot) = env:: var ( "SDKROOT" ) {
31993175 let p = Path :: new ( & sdkroot) ;
3200- match sdk_name {
3176+ match & * sdk_name. to_lowercase ( ) {
32013177 // Ignore `SDKROOT` if it's clearly set for the wrong platform.
32023178 "appletvos"
32033179 if sdkroot. contains ( "TVSimulator.platform" )
@@ -3228,18 +3204,21 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
32283204 _ => return Ok ( sdkroot) ,
32293205 }
32303206 }
3231- let res =
3232- Command :: new ( "xcrun" ) . arg ( "--show-sdk-path" ) . arg ( "-sdk" ) . arg ( sdk_name) . output ( ) . and_then (
3233- |output| {
3234- if output. status . success ( ) {
3235- Ok ( String :: from_utf8 ( output. stdout ) . unwrap ( ) )
3236- } else {
3237- let error = String :: from_utf8 ( output. stderr ) ;
3238- let error = format ! ( "process exit with error: {}" , error. unwrap( ) ) ;
3239- Err ( io:: Error :: new ( io:: ErrorKind :: Other , & error[ ..] ) )
3240- }
3241- } ,
3242- ) ;
3207+
3208+ let res = Command :: new ( "xcrun" )
3209+ . arg ( "--show-sdk-path" )
3210+ . arg ( "-sdk" )
3211+ . arg ( sdk_name. to_lowercase ( ) )
3212+ . output ( )
3213+ . and_then ( |output| {
3214+ if output. status . success ( ) {
3215+ Ok ( String :: from_utf8 ( output. stdout ) . unwrap ( ) )
3216+ } else {
3217+ let error = String :: from_utf8 ( output. stderr ) ;
3218+ let error = format ! ( "process exit with error: {}" , error. unwrap( ) ) ;
3219+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , & error[ ..] ) )
3220+ }
3221+ } ) ;
32433222
32443223 match res {
32453224 Ok ( output) => Ok ( output. trim ( ) . to_string ( ) ) ,
0 commit comments