From ccb5d0a7c170434bb2ced860ec7139f4c6f964ce Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 16 Jul 2019 13:29:40 -0700 Subject: [PATCH] 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. --- src/librustc_target/spec/apple_ios_base.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc_target/spec/apple_ios_base.rs b/src/librustc_target/spec/apple_ios_base.rs index 3068ed8d206c..40cc7f420106 100644 --- a/src/librustc_target/spec/apple_ios_base.rs +++ b/src/librustc_target/spec/apple_ios_base.rs @@ -1,3 +1,4 @@ +use std::env; use std::io; use std::process::Command; use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions}; @@ -27,6 +28,12 @@ impl Arch { } pub fn get_sdk_root(sdk_name: &str) -> Result { + 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")