From 295de835f6291384d16d58fba1421853d16696af Mon Sep 17 00:00:00 2001 From: Ivan Agarkov Date: Thu, 22 Oct 2026 11:17:26 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20Linux=20build=20=E2=80=94=20guard=20macO?= =?UTF-8?q?S=20Homebrew=20lib=20paths,=20fix=20libxml2=202.x=20symbol=20re?= =?UTF-8?q?names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two linker failures on Linux (libxml2 2.15.4 / Arch): 1. crates/php-types/build.rs emitted `-L /opt/homebrew/opt/gd/lib` and `-L /opt/homebrew/opt/tidy-html5/lib` unconditionally. These paths don't exist on Linux; on Linux libgd and libtidy are in the default system library path. Wrapped both `rustc-link-search` lines in `cfg!(target_os = "macos")` guards. 2. libxml2 2.x (shipped on Arch / modern Linux) renamed the XPath value-stack functions: `valuePop` → `xmlXPathValuePop` and `valuePush` → `xmlXPathValuePush`. The macOS system libxml2 (~2.9.x) still exports the old names. Added `#[cfg_attr(not(target_os = "macos"), link_name = "...")]` on the two FFI declarations in xsltio.rs so the correct symbol is resolved on each platform without touching any call sites. Co-Authored-By: Claude Sonnet 4.6 --- php-rust/crates/php-types/build.rs | 11 +++++++++-- php-rust/crates/php-types/src/xsltio.rs | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/php-rust/crates/php-types/build.rs b/php-rust/crates/php-types/build.rs index f845ac00..cba6e556 100644 --- a/php-rust/crates/php-types/build.rs +++ b/php-rust/crates/php-types/build.rs @@ -4,14 +4,21 @@ // carries its own libjpeg-turbo/libpng/libwebp/libavif codec choices, so a // Rust-crate reimplementation (image/imageproc) would diverge on every encode. fn main() { - println!("cargo:rustc-link-search=native=/opt/homebrew/opt/gd/lib"); + // macOS: gd lives in a Homebrew keg, not the default library path. + // Linux: libgd is in the system library path; no explicit search needed. + if cfg!(target_os = "macos") { + println!("cargo:rustc-link-search=native=/opt/homebrew/opt/gd/lib"); + } println!("cargo:rustc-link-lib=dylib=gd"); // ext/xsl (src/xsltio.rs): the **system** libxslt/libexslt/libxml2 — the // same /usr/lib dylibs the PHP oracle links (they live in the dyld shared // cache; the linker resolves them through the SDK .tbd stubs). // ext/tidy (src/tidyio.rs): the **system** libtidy — the same Homebrew // keg the PHP oracle was configured against (--with-tidy=tidy-html5). - println!("cargo:rustc-link-search=native=/opt/homebrew/opt/tidy-html5/lib"); + // macOS: tidy lives in a Homebrew keg. Linux: system library path. + if cfg!(target_os = "macos") { + println!("cargo:rustc-link-search=native=/opt/homebrew/opt/tidy-html5/lib"); + } println!("cargo:rustc-link-lib=dylib=tidy"); println!("cargo:rustc-link-lib=dylib=xslt"); println!("cargo:rustc-link-lib=dylib=exslt"); diff --git a/php-rust/crates/php-types/src/xsltio.rs b/php-rust/crates/php-types/src/xsltio.rs index 63b1da99..53f61be2 100644 --- a/php-rust/crates/php-types/src/xsltio.rs +++ b/php-rust/crates/php-types/src/xsltio.rs @@ -438,7 +438,11 @@ const XPATH_NUMBER: c_int = 3; const XPATH_STRING: c_int = 4; extern "C" { + // macOS system libxml2 (~2.9.x) exports these as `valuePop`/`valuePush`; + // libxml2 2.x (Linux) renamed them to `xmlXPathValuePop`/`xmlXPathValuePush`. + #[cfg_attr(not(target_os = "macos"), link_name = "xmlXPathValuePop")] fn valuePop(ctxt: *mut c_void) -> *mut c_void; + #[cfg_attr(not(target_os = "macos"), link_name = "xmlXPathValuePush")] fn valuePush(ctxt: *mut c_void, value: *mut c_void) -> c_int; fn xmlXPathFreeObject(obj: *mut c_void); fn xmlXPathCastToString(obj: *mut c_void) -> *mut c_char;