Skip to content

Commit 1117b6d

Browse files
committed
Add -isysroot for xctoolchain cc
1 parent 3cf8f41 commit 1117b6d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ impl Build {
21112111
None => false,
21122112
};
21132113

2114-
let is_sim = match target.split('-').nth(3) {
2114+
let is_arm_sim = match target.split('-').nth(3) {
21152115
Some(v) => v == "sim",
21162116
None => false,
21172117
};
@@ -2139,14 +2139,14 @@ impl Build {
21392139
));
21402140
}
21412141
}
2142-
} else if is_sim {
2142+
} else if is_arm_sim {
21432143
match arch {
21442144
"arm64" | "aarch64" => ArchSpec::Simulator("-arch arm64"),
21452145
"x86_64" => ArchSpec::Simulator("-m64"),
21462146
_ => {
21472147
return Err(Error::new(
21482148
ErrorKind::ArchitectureInvalid,
2149-
"Unknown architecture for iOS simulator target.",
2149+
"Unknown architecture for simulator target.",
21502150
));
21512151
}
21522152
}
@@ -2210,11 +2210,15 @@ impl Build {
22102210
ArchSpec::Catalyst(_) => "macosx".to_owned(),
22112211
};
22122212

2213-
if !is_mac {
2213+
// AppleClang sometimes needs sysroot even for darwin
2214+
if cmd.is_xctoolchain_clang() || !target.ends_with("-darwin") {
22142215
self.print(&format!("Detecting {} SDK path for {}", os, sdk));
22152216
let sdk_path = self.apple_sdk_root(sdk.as_str())?;
22162217
cmd.args.push("-isysroot".into());
22172218
cmd.args.push(sdk_path);
2219+
}
2220+
2221+
if !is_mac {
22182222
cmd.args.push("-fembed-bitcode".into());
22192223
}
22202224
/*
@@ -3112,6 +3116,17 @@ impl Tool {
31123116
self.family == ToolFamily::Clang
31133117
}
31143118

3119+
/// Whether the tool is AppleClang under .xctoolchain
3120+
#[cfg(target_vendor = "apple")]
3121+
fn is_xctoolchain_clang(&self) -> bool {
3122+
let path = self.path.to_str().unwrap();
3123+
path.contains(".xctoolchain/")
3124+
}
3125+
#[cfg(not(target_vendor = "apple"))]
3126+
fn is_xctoolchain_clang(&self) -> bool {
3127+
false
3128+
}
3129+
31153130
/// Whether the tool is MSVC-like.
31163131
pub fn is_like_msvc(&self) -> bool {
31173132
match self.family {

tests/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ fn gnu_apple_darwin() {
439439
.file("foo.c")
440440
.compile("foo");
441441

442-
test.cmd(0).must_have("-mmacosx-version-min=10.4");
442+
let cmd = test.cmd(0);
443+
cmd.must_have("-mmacosx-version-min=10.4");
444+
cmd.must_not_have("-isysroot");
443445
}
444446
}

0 commit comments

Comments
 (0)