Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "libcsp"]
path = libcsp
url = https://github.com/xarantolus/libcsp.git
url = https://github.com/unexcellent/libcsp.git
[submodule "libcsp-sys/mini-scanf"]
path = libcsp-sys/mini-scanf
url = https://github.com/MuratovAS/mini-scanf.git
32 changes: 30 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,36 @@ version 2.1 of the License, or (at your option) any later version.
// On some systems libclang cannot locate GCC's built-in headers
// (stddef.h, stdint.h, …) on its own. Ask the C compiler where they live
// and forward that as a -isystem path to clang.
for gcc_include in gcc_builtin_include() {
builder = builder.clang_arg(format!("-isystem{gcc_include}"));
//
// NOT on macOS: `cc -print-file-name=include` returns the Xcode
// toolchain's clang builtin dir there, and mixing a second clang builtin
// dir into libclang's search breaks include_next chaining — both stdint.h
// copies share the __CLANG_STDINT_H guard, so the second one is skipped
// and the SDK's stdint.h (with the actual typedefs) is never reached.
// libclang finds its own builtin headers on macOS.
if env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("macos") {
for gcc_include in gcc_builtin_include() {
builder = builder.clang_arg(format!("-isystem{gcc_include}"));
}
}

// On macOS the system headers live in the SDK, not /usr/include, and
// libclang doesn't find the sysroot on its own — ask xcrun. A sysroot
// already provided via BINDGEN_EXTRA_CLANG_ARGS (e.g. a cross build)
// takes precedence since bindgen appends those args after these.
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") {
if let Ok(output) = std::process::Command::new("xcrun")
.args(["--show-sdk-path"])
.output()
{
let sdk = std::str::from_utf8(&output.stdout)
.unwrap_or_default()
.trim()
.to_owned();
if !sdk.is_empty() {
builder = builder.clang_arg(format!("-isysroot{sdk}"));
}
}
}

// SocketCAN header is Linux-only — skip for embedded/non-Linux targets
Expand Down