about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-25 01:05:05 +0200
committerGitHub <noreply@github.com>2019-07-25 01:05:05 +0200
commit6e1ed3a116ca59b541d7a606c7e90593917b9d0d (patch)
treeb58836ae39c7f19fae2d2c86305a534c66682c5b
parent5a7db0e19a22795edd578c5ef308fc73c71b11e9 (diff)
parent287db19e9a480decb491d39c3c22357a7a68f102 (diff)
downloadrust-6e1ed3a116ca59b541d7a606c7e90593917b9d0d.tar.gz
rust-6e1ed3a116ca59b541d7a606c7e90593917b9d0d.zip
Rollup merge of #62903 - swolchok:ios-sdkroot, r=alexcrichton
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 #62551.
-rw-r--r--src/librustc_target/spec/apple_ios_base.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/librustc_target/spec/apple_ios_base.rs b/src/librustc_target/spec/apple_ios_base.rs
index 3068ed8d206..f46ad06ba43 100644
--- a/src/librustc_target/spec/apple_ios_base.rs
+++ b/src/librustc_target/spec/apple_ios_base.rs
@@ -1,4 +1,6 @@
+use std::env;
 use std::io;
+use std::path::Path;
 use std::process::Command;
 use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
 
@@ -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")