Skip to content

Commit b681164

Browse files
committed
Add -isysroot for xctoolchain cc
1 parent a211d91 commit b681164

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,8 @@ impl Build {
25152515
ArchSpec::Catalyst(_) => "macosx".to_owned(),
25162516
};
25172517

2518-
if !is_mac {
2518+
// AppleClang sometimes requires sysroot even for darwin
2519+
if cmd.is_xctoolchain_clang() || !target.ends_with("-darwin") {
25192520
self.print(&format_args!("Detecting {:?} SDK path for {}", os, sdk));
25202521
let sdk_path = if let Some(sdkroot) = env::var_os("SDKROOT") {
25212522
sdkroot
@@ -2525,7 +2526,10 @@ impl Build {
25252526

25262527
cmd.args.push("-isysroot".into());
25272528
cmd.args.push(sdk_path);
2528-
// TODO: Remove this once Apple stops accepting apps built with Xcode 13
2529+
}
2530+
2531+
// TODO: Remove this once Apple stops accepting apps built with Xcode 13
2532+
if !is_mac {
25292533
cmd.args.push("-fembed-bitcode".into());
25302534
}
25312535

@@ -3718,6 +3722,17 @@ impl Tool {
37183722
self.family == ToolFamily::Clang
37193723
}
37203724

3725+
/// Whether the tool is AppleClang under .xctoolchain
3726+
#[cfg(target_vendor = "apple")]
3727+
fn is_xctoolchain_clang(&self) -> bool {
3728+
let path = self.path.to_string_lossy();
3729+
path.contains(".xctoolchain/")
3730+
}
3731+
#[cfg(not(target_vendor = "apple"))]
3732+
fn is_xctoolchain_clang(&self) -> bool {
3733+
false
3734+
}
3735+
37213736
/// Whether the tool is MSVC-like.
37223737
pub fn is_like_msvc(&self) -> bool {
37233738
match self.family {

tests/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,10 @@ fn gnu_apple_darwin() {
489489
.file("foo.c")
490490
.compile("foo");
491491

492+
let cmd = test.cmd(0);
492493
test.cmd(0)
493494
.must_have(format!("-mmacosx-version-min={}", version));
495+
cmd.must_not_have("-isysroot");
494496
}
495497
}
496498

0 commit comments

Comments
 (0)