@@ -38,9 +38,18 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
3838 // SDKROOT; for rustc, the user or build system can set it, or we
3939 // can fall back to checking for xcrun on PATH.)
4040 if let Some ( sdkroot) = env:: var ( "SDKROOT" ) . ok ( ) {
41- let sdkroot_path = Path :: new ( & sdkroot) ;
42- if sdkroot_path. is_absolute ( ) && sdkroot_path != Path :: new ( "/" ) && sdkroot_path. exists ( ) {
43- return Ok ( sdkroot) ;
41+ let p = Path :: new ( & sdkroot) ;
42+ match sdk_name {
43+ // Ignore `SDKROOT` if it's clearly set for the wrong platform.
44+ "iphoneos" if sdkroot. contains ( "iPhoneSimulator.platform" )
45+ || sdkroot. contains ( "MacOSX.platform" ) => ( ) ,
46+ "iphonesimulator" if sdkroot. contains ( "iPhoneOS.platform" )
47+ || sdkroot. contains ( "MacOSX.platform" ) => ( ) ,
48+ "macosx10.15" if sdkroot. contains ( "iPhoneOS.platform" )
49+ || sdkroot. contains ( "iPhoneSimulator.platform" ) => ( ) ,
50+ // Ignore `SDKROOT` if it's not a valid path.
51+ _ if !p. is_absolute ( ) || p == Path :: new ( "/" ) || !p. exists ( ) => ( ) ,
52+ _ => return Ok ( sdkroot) ,
4453 }
4554 }
4655 let res = Command :: new ( "xcrun" )
@@ -100,13 +109,21 @@ fn target_cpu(arch: Arch) -> String {
100109 } . to_string ( )
101110}
102111
112+ fn link_env_remove ( arch : Arch ) -> Vec < String > {
113+ match arch {
114+ Armv7 | Armv7s | Arm64 | I386 | X86_64 => vec ! [ "MACOSX_DEPLOYMENT_TARGET" . to_string( ) ] ,
115+ X86_64_macabi => vec ! [ "IPHONEOS_DEPLOYMENT_TARGET" . to_string( ) ] ,
116+ }
117+ }
118+
103119pub fn opts ( arch : Arch ) -> Result < TargetOptions , String > {
104120 let pre_link_args = build_pre_link_args ( arch) ?;
105121 Ok ( TargetOptions {
106122 cpu : target_cpu ( arch) ,
107123 dynamic_linking : false ,
108124 executables : true ,
109125 pre_link_args,
126+ link_env_remove : link_env_remove ( arch) ,
110127 has_elf_tls : false ,
111128 eliminate_frame_pointer : false ,
112129 .. super :: apple_base:: opts ( )
0 commit comments