@@ -38,9 +38,18 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
38
38
// SDKROOT; for rustc, the user or build system can set it, or we
39
39
// can fall back to checking for xcrun on PATH.)
40
40
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) ,
44
53
}
45
54
}
46
55
let res = Command :: new ( "xcrun" )
@@ -100,13 +109,21 @@ fn target_cpu(arch: Arch) -> String {
100
109
} . to_string ( )
101
110
}
102
111
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
+
103
119
pub fn opts ( arch : Arch ) -> Result < TargetOptions , String > {
104
120
let pre_link_args = build_pre_link_args ( arch) ?;
105
121
Ok ( TargetOptions {
106
122
cpu : target_cpu ( arch) ,
107
123
dynamic_linking : false ,
108
124
executables : true ,
109
125
pre_link_args,
126
+ link_env_remove : link_env_remove ( arch) ,
110
127
has_elf_tls : false ,
111
128
eliminate_frame_pointer : false ,
112
129
.. super :: apple_base:: opts ( )
0 commit comments