Skip to content

Commit

Permalink
Rollup merge of rust-lang#62903 - swolchok:ios-sdkroot, r=alexcrichton
Browse files Browse the repository at this point in the history
Support SDKROOT env var on iOS

Following what clang does (https://github.com/llvm/llvm-project/blob/296a80102a9b72c3eda80558fb78a3ed8849b341/clang/lib/Driver/ToolChains/Darwin.cpp#L1661-L1678), allow allow SDKROOT to tell us where the Apple SDK lives so we don't have to invoke xcrun.

Replaces rust-lang#62551.
  • Loading branch information
Centril authored Jul 24, 2019
2 parents 5a7db0e + 287db19 commit 6e1ed3a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/librustc_target/spec/apple_ios_base.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::env;
use std::io;
use std::path::Path;
use std::process::Command;
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};

Expand Down Expand Up @@ -27,6 +29,18 @@ impl Arch {
}

pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
// Following what clang does
// (https://github.com/llvm/llvm-project/blob/
// 296a80102a9b72c3eda80558fb78a3ed8849b341/clang/lib/Driver/ToolChains/Darwin.cpp#L1661-L1678)
// to allow the SDK path to be set. (For clang, xcrun sets
// 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 res = Command::new("xcrun")
.arg("--show-sdk-path")
.arg("-sdk")
Expand Down

0 comments on commit 6e1ed3a

Please sign in to comment.