Skip to content
Open
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
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ fn main() {
// Apple platforms have libz.1.dylib, and it's usually available even when
// cross compiling (via fat binary or in the target's Xcode SDK)
let cross_compiling = target != host;
let try_link_with_shared =
env::var("LIB_SYS_TRY_SHARED").unwrap_or(String::new()) == "1";
Comment on lines +85 to +86
Copy link
Contributor

@polarathene polarathene Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. Use the existing ENV:

libz-sys/build.rs

Lines 37 to 38 in 80c597a

let want_static =
cfg!(feature = "static") || env::var("LIBZ_SYS_STATIC").unwrap_or(String::new()) == "1";

So something like the below function would work just fine to support an optional ENV (0/1) for overriding a dependency that vendors a lib in via the static feature? (which would otherwise be respected if no override ENV exists at build-time)

fn should_link_static() -> bool {
  let want_static_env: Option<&'static str> = option_env!("LIBZ_SYS_STATIC");
  let want_static_cfg = cfg!(feature = "static");

  want_static_env
    .and_then(|value: &str| value.parse::<u8>().ok())
    .and_then(|b| match b {
      0 => Some(false),
      1 => Some(true),
      _ => None,
    })
    .unwrap_or(want_static_cfg)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting the logic into the clear, to me that makes sense and allows to override cargo features using environment variables.

if target.contains("msvc")
|| target.contains("pc-windows-gnu")
|| want_static
|| (cross_compiling && !target.contains("-apple-"))
|| !try_link_with_shared && (cross_compiling && !target.contains("-apple-"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is no longer relevant, and should be left alone as it is now currently:

libz-sys/build.rs

Lines 81 to 86 in 80c597a

if target.contains("msvc")
|| target.contains("pc-windows-gnu")
|| want_static
{
return build_zlib(&mut cfg, &target);
}

{
return build_zlib(&mut cfg, &target);
}
Expand Down