From ccb5d0a7c170434bb2ced860ec7139f4c6f964ce Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 16 Jul 2019 13:29:40 -0700 Subject: [PATCH 1/3] 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 3068ed8d206cd..40cc7f420106b 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") From a4ff823f5d7205a983461063d08902986c11d00d Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 23 Jul 2019 13:37:17 -0700 Subject: [PATCH 2/3] fix check --- src/librustc_target/spec/apple_ios_base.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_target/spec/apple_ios_base.rs b/src/librustc_target/spec/apple_ios_base.rs index 40cc7f420106b..d400bc62bfd07 100644 --- a/src/librustc_target/spec/apple_ios_base.rs +++ b/src/librustc_target/spec/apple_ios_base.rs @@ -1,5 +1,6 @@ use std::env; use std::io; +use std::path::Path; use std::process::Command; use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions}; @@ -29,7 +30,7 @@ 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); + let sdkroot_path = Path::new(&sdkroot); if sdkroot_path.is_absolute() && sdkroot_path != Path::new("/") && sdkroot_path.exists() { return Ok(sdkroot); } From 287db19e9a480decb491d39c3c22357a7a68f102 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Wed, 24 Jul 2019 10:28:14 -0700 Subject: [PATCH 3/3] Add comment --- src/librustc_target/spec/apple_ios_base.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustc_target/spec/apple_ios_base.rs b/src/librustc_target/spec/apple_ios_base.rs index d400bc62bfd07..f46ad06ba436a 100644 --- a/src/librustc_target/spec/apple_ios_base.rs +++ b/src/librustc_target/spec/apple_ios_base.rs @@ -29,6 +29,12 @@ impl Arch { } pub fn get_sdk_root(sdk_name: &str) -> Result { + // 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() {