Conversation
This change prevents libz-sys from building its own zlib by using zlibNX if available, which is an version of the zlib library that supports hardware accelerated data compression and decompression.
There was a problem hiding this comment.
Pull request overview
Updates libz-sys’s build script to prefer the AIX zlibNX installation when present, avoiding building a bundled zlib in that case.
Changes:
- Detect AIX targets and probe
/usr/opt/zlibNXforlibz.aandzlib.h. - When found, configure Cargo to link against
-lzfrom zlibNX and expose the include path, then exit early.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let zlibNX_lib = "/usr/opt/zlibNX/lib"; | ||
| let zlibNX_include = "/usr/opt/zlibNX/include"; | ||
| if std::path::Path::new(zlibNX_lib).join("libz.a").exists() && | ||
| std::path::Path::new(zlibNX_include).join("zlib.h").exists() { | ||
| println!("cargo:rustc-link-search=native={}", zlibNX_lib); | ||
| println!("cargo:rustc-link-lib=z"); | ||
| println!("cargo:include={}", zlibNX_include); |
There was a problem hiding this comment.
Local variable names zlibNX_lib/zlibNX_include don’t follow Rust’s usual snake_case naming used throughout this file (e.g., want_static, host_and_target_contain). Consider renaming to snake_case (e.g., zlibnx_lib, zlibnx_include or zlibnx_lib_dir, zlibnx_include_dir) for consistency.
| let zlibNX_lib = "/usr/opt/zlibNX/lib"; | |
| let zlibNX_include = "/usr/opt/zlibNX/include"; | |
| if std::path::Path::new(zlibNX_lib).join("libz.a").exists() && | |
| std::path::Path::new(zlibNX_include).join("zlib.h").exists() { | |
| println!("cargo:rustc-link-search=native={}", zlibNX_lib); | |
| println!("cargo:rustc-link-lib=z"); | |
| println!("cargo:include={}", zlibNX_include); | |
| let zlibnx_lib = "/usr/opt/zlibNX/lib"; | |
| let zlibnx_include = "/usr/opt/zlibNX/include"; | |
| if std::path::Path::new(zlibnx_lib).join("libz.a").exists() && | |
| std::path::Path::new(zlibnx_include).join("zlib.h").exists() { | |
| println!("cargo:rustc-link-search=native={}", zlibnx_lib); | |
| println!("cargo:rustc-link-lib=z"); | |
| println!("cargo:include={}", zlibnx_include); |
Byron
left a comment
There was a problem hiding this comment.
Thanks a lot. Here is a review by Codex, based on my hunch, which ended up P1. Please do also take a look at P2, which may or may not make sense.
Thanks
-
P1: Honor explicit static mode before preferring zlibNX
In build.rs, the new AIX fast-path returns as soon as/usr/opt/zlibNXexists, beforeshould_link_static()is evaluated. That changes existing behavior: callers using thestaticfeature orLIBZ_SYS_STATIC=1can no longer force the bundled static build when zlibNX is present. This regresses a supported build mode. -
P2: Validate zlibNX is actually linkable before skipping fallback
In build.rs, the AIX special case short-circuits based only on file existence. The current non-Windows system path only avoids the vendored build afterzlib_installed()successfully compiles and linkssrc/smoke.c. If/usr/opt/zlibNXexists but is unusable for the active compiler configuration, this change will fail later at link time instead of falling back to the bundled zlib.
This change addresses two issues with respect to AIX zlibNX support: 1. The zlibNX check is moved after should_link_static() to allow users to force static builds even when zlibNX is present. 2. zlibNX linkability is validated prior to using it. The zlibnx_installed() function is added and compiles/links a test program (similar to zlib_installed() validation).
Ah, those are good points. Thank you for the review, @Byron! Appreciate it! |
This change prevents libz-sys from building its own zlib by using zlibNX if available, which is an version of the zlib library that supports hardware accelerated data compression and decompression.