Skip to content

Commit 3261592

Browse files
committed
Add -isysroot for xctoolchain cc
1 parent 68d73ec commit 3261592

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/lib.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ impl Build {
21632163
_ => {
21642164
return Err(Error::new(
21652165
ErrorKind::ArchitectureInvalid,
2166-
"Unknown architecture for iOS simulator target.",
2166+
"Unknown architecture for simulator target.",
21672167
));
21682168
}
21692169
}
@@ -2233,7 +2233,8 @@ impl Build {
22332233
ArchSpec::Catalyst(_) => "macosx".to_owned(),
22342234
};
22352235

2236-
if !is_mac {
2236+
// AppleClang sometimes needs sysroot even for darwin
2237+
if cmd.is_xctoolchain_clang() || !target.ends_with("-darwin") {
22372238
self.print(&format!("Detecting {} SDK path for {}", os, sdk));
22382239
let sdk_path = if let Some(sdkroot) = env::var_os("SDKROOT") {
22392240
sdkroot
@@ -2242,6 +2243,9 @@ impl Build {
22422243
};
22432244
cmd.args.push("-isysroot".into());
22442245
cmd.args.push(sdk_path);
2246+
}
2247+
2248+
if !is_mac {
22452249
cmd.args.push("-fembed-bitcode".into());
22462250
}
22472251
/*
@@ -3155,6 +3159,17 @@ impl Tool {
31553159
self.family == ToolFamily::Clang
31563160
}
31573161

3162+
/// Whether the tool is AppleClang under .xctoolchain
3163+
#[cfg(target_vendor = "apple")]
3164+
fn is_xctoolchain_clang(&self) -> bool {
3165+
let path = self.path.to_str().unwrap();
3166+
path.contains(".xctoolchain/")
3167+
}
3168+
#[cfg(not(target_vendor = "apple"))]
3169+
fn is_xctoolchain_clang(&self) -> bool {
3170+
false
3171+
}
3172+
31583173
/// Whether the tool is MSVC-like.
31593174
pub fn is_like_msvc(&self) -> bool {
31603175
match self.family {

tests/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,9 @@ fn gnu_apple_darwin() {
439439
.file("foo.c")
440440
.compile("foo");
441441

442+
let cmd = test.cmd(0);
442443
test.cmd(0)
443444
.must_have(format!("-mmacosx-version-min={}", version));
445+
cmd.must_not_have("-isysroot");
444446
}
445447
}

0 commit comments

Comments
 (0)