Skip to content

Commit fe6d626

Browse files
committed
Ignore linker env vars set for macOS on iOS targets
1 parent e715d03 commit fe6d626

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/librustc_target/spec/apple_ios_base.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
103119
pub 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

Comments
 (0)