Skip to content

Commit 6d9a9ed

Browse files
committed
Add -isysroot for xctoolchain cc
1 parent daab924 commit 6d9a9ed

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ impl Build {
24272427
_ => {
24282428
return Err(Error::new(
24292429
ErrorKind::ArchitectureInvalid,
2430-
"Unknown architecture for iOS simulator target.",
2430+
"Unknown architecture for simulator target.",
24312431
));
24322432
}
24332433
}
@@ -2485,7 +2485,8 @@ impl Build {
24852485
ArchSpec::Catalyst(_) => "macosx".to_owned(),
24862486
};
24872487

2488-
if !is_mac {
2488+
// AppleClang sometimes requires sysroot even for darwin
2489+
if cmd.is_xctoolchain_clang() || !target.ends_with("-darwin") {
24892490
self.print(&format_args!("Detecting {:?} SDK path for {}", os, sdk));
24902491
let sdk_path = if let Some(sdkroot) = env::var_os("SDKROOT") {
24912492
sdkroot
@@ -2495,7 +2496,10 @@ impl Build {
24952496

24962497
cmd.args.push("-isysroot".into());
24972498
cmd.args.push(sdk_path);
2498-
// TODO: Remove this once Apple stops accepting apps built with Xcode 13
2499+
}
2500+
2501+
// TODO: Remove this once Apple stops accepting apps built with Xcode 13
2502+
if !is_mac {
24992503
cmd.args.push("-fembed-bitcode".into());
25002504
}
25012505

@@ -3684,6 +3688,17 @@ impl Tool {
36843688
self.family == ToolFamily::Clang
36853689
}
36863690

3691+
/// Whether the tool is AppleClang under .xctoolchain
3692+
#[cfg(target_vendor = "apple")]
3693+
fn is_xctoolchain_clang(&self) -> bool {
3694+
let path = self.path.to_str().unwrap();
3695+
path.contains(".xctoolchain/")
3696+
}
3697+
#[cfg(not(target_vendor = "apple"))]
3698+
fn is_xctoolchain_clang(&self) -> bool {
3699+
false
3700+
}
3701+
36873702
/// Whether the tool is MSVC-like.
36883703
pub fn is_like_msvc(&self) -> bool {
36893704
match self.family {

tests/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ 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
}

0 commit comments

Comments
 (0)