Skip to content

Commit

Permalink
Ignore linker env vars set for macOS on iOS targets
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksijuvani committed Sep 12, 2019
1 parent e715d03 commit fe6d626
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/librustc_target/spec/apple_ios_base.rs
Expand Up @@ -38,9 +38,18 @@ pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
// SDKROOT; for rustc, the user or build system can set it, or we
// can fall back to checking for xcrun on PATH.)
if let Some(sdkroot) = env::var("SDKROOT").ok() {
let sdkroot_path = Path::new(&sdkroot);
if sdkroot_path.is_absolute() && sdkroot_path != Path::new("/") && sdkroot_path.exists() {
return Ok(sdkroot);
let p = Path::new(&sdkroot);
match sdk_name {
// Ignore `SDKROOT` if it's clearly set for the wrong platform.
"iphoneos" if sdkroot.contains("iPhoneSimulator.platform")
|| sdkroot.contains("MacOSX.platform") => (),
"iphonesimulator" if sdkroot.contains("iPhoneOS.platform")
|| sdkroot.contains("MacOSX.platform") => (),
"macosx10.15" if sdkroot.contains("iPhoneOS.platform")
|| sdkroot.contains("iPhoneSimulator.platform") => (),
// Ignore `SDKROOT` if it's not a valid path.
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => (),
_ => return Ok(sdkroot),
}
}
let res = Command::new("xcrun")
Expand Down Expand Up @@ -100,13 +109,21 @@ fn target_cpu(arch: Arch) -> String {
}.to_string()
}

fn link_env_remove(arch: Arch) -> Vec<String> {
match arch {
Armv7 | Armv7s | Arm64 | I386 | X86_64 => vec!["MACOSX_DEPLOYMENT_TARGET".to_string()],
X86_64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()],
}
}

pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
let pre_link_args = build_pre_link_args(arch)?;
Ok(TargetOptions {
cpu: target_cpu(arch),
dynamic_linking: false,
executables: true,
pre_link_args,
link_env_remove: link_env_remove(arch),
has_elf_tls: false,
eliminate_frame_pointer: false,
.. super::apple_base::opts()
Expand Down

0 comments on commit fe6d626

Please sign in to comment.