Skip to content

Commit 38c763f

Browse files
authored
fix(bindings): exclude preserve_none instruction from bindings (#620)
1 parent 62c1aa7 commit 38c763f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ path = "tests/module.rs"
7878
[[test]]
7979
name = "sapi_tests"
8080
path = "tests/sapi.rs"
81+
82+
# Patch clang-sys and bindgen for preserve_none calling convention support (libclang 19/20)
83+
# Required for PHP 8.5+ on macOS ARM64 which uses TAILCALL VM mode
84+
# - clang-sys: Adds libclang 19/20 bindings (https://github.com/KyleMayes/clang-sys/pull/195)
85+
# - bindgen: Maps CXCallingConv_PreserveNone to C ABI
86+
[patch.crates-io]
87+
clang-sys = { git = "https://github.com/extphprs/clang-sys.git", branch = "preserve-none-support" }
88+
bindgen = { git = "https://github.com/extphprs/rust-bindgen.git", branch = "preserve-none-support" }

build.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,27 @@ fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<S
226226
.iter()
227227
.map(|inc| format!("-I{}", inc.to_string_lossy())),
228228
)
229-
.clang_args(defines.iter().map(|(var, val)| format!("-D{var}={val}")))
229+
.clang_args(defines.iter().map(|(var, val)| format!("-D{var}={val}")));
230+
231+
// Add macOS SDK path for system headers (stdlib.h, etc.)
232+
// Required for libclang 19+ with preserve_none calling convention support
233+
#[cfg(target_os = "macos")]
234+
{
235+
if let Ok(sdk_path) = std::process::Command::new("xcrun")
236+
.args(["--show-sdk-path"])
237+
.output()
238+
{
239+
if sdk_path.status.success() {
240+
let path = String::from_utf8_lossy(&sdk_path.stdout);
241+
let path = path.trim();
242+
bindgen = bindgen
243+
.clang_arg(format!("-isysroot{}", path))
244+
.clang_arg(format!("-I{}/usr/include", path));
245+
}
246+
}
247+
}
248+
249+
bindgen = bindgen
230250
.formatter(bindgen::Formatter::Rustfmt)
231251
.no_copy("php_ini_builder")
232252
.no_copy("_zval_struct")

0 commit comments

Comments
 (0)