Skip to content

Commit 6e1ed3a

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#62551.
2 parents 5a7db0e + 287db19 commit 6e1ed3a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/librustc_target/spec/apple_ios_base.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use std::env;
12
use std::io;
3+
use std::path::Path;
24
use std::process::Command;
35
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
46

@@ -27,6 +29,18 @@ impl Arch {
2729
}
2830

2931
pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
32+
// Following what clang does
33+
// (https://github.com/llvm/llvm-project/blob/
34+
// 296a80102a9b72c3eda80558fb78a3ed8849b341/clang/lib/Driver/ToolChains/Darwin.cpp#L1661-L1678)
35+
// to allow the SDK path to be set. (For clang, xcrun sets
36+
// SDKROOT; for rustc, the user or build system can set it, or we
37+
// can fall back to checking for xcrun on PATH.)
38+
if let Some(sdkroot) = env::var("SDKROOT").ok() {
39+
let sdkroot_path = Path::new(&sdkroot);
40+
if sdkroot_path.is_absolute() && sdkroot_path != Path::new("/") && sdkroot_path.exists() {
41+
return Ok(sdkroot);
42+
}
43+
}
3044
let res = Command::new("xcrun")
3145
.arg("--show-sdk-path")
3246
.arg("-sdk")

0 commit comments

Comments
 (0)