Skip to content

Commit

Permalink
Rename feature
Browse files Browse the repository at this point in the history
Also make it so that --all-features works
  • Loading branch information
Jake-Shadle committed Feb 1, 2024
1 parent 9239a52 commit c0b2e5f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ default = ["libc", "stock-zlib"]
# This allows higher-level crates depending on your library to opt into zlib-ng
# if desired.
zlib-ng = ["libc", "cmake"]
# Builds zlib-ng from source using cc instead of cmake
zlib-ng-no-cmake = ["libc"]
# Builds zlib-ng from source using cc instead of cmake with all target features
# enabled, meaning compilation may not work depending on your target and host
# toolchain (eg very old compilers won't have some flags)
#
# This feature is not maintained by the repo maintainers and can break at any time
# or be completely removed in the future
zlib-ng-no-cmake-experimental-community-maintained- = ["libc"]
stock-zlib = []
# Deprecated: the assembly routines are outdated, and either reduce performance
# or cause segfaults.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ libz-sys = { version = "1.1", default-features = false, features = ["libc"] }
This allows higher-level crates depending on your library to opt into zlib-ng
if desired.

Building zlib-ng requires `cmake` unless the `zlib-ng-no-cmake` feature is enabled,
Building zlib-ng requires `cmake` unless the
`zlib-ng-no-cmake-experimental-community-maintained` feature is enabled,
in which case `cc` is used instead. Note that this option enables _all_ compiler
features that are supported for the given target, which may not compile on older
compilers or targets without certain headers.
Expand Down
24 changes: 19 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ fn main() {

let host_and_target_contain = |s| host.contains(s) && target.contains(s);

let want_ng = cfg!(any(feature = "zlib-ng", feature = "zlib-ng-no-cmake"))
&& !cfg!(feature = "stock-zlib");
let want_ng = cfg!(any(
feature = "zlib-ng",
feature = "zlib-ng-no-cmake-experimental-community-maintained"
)) && !cfg!(feature = "stock-zlib");

if want_ng && target != "wasm32-unknown-unknown" {
return build_zlib_ng(&target, true);
Expand Down Expand Up @@ -165,17 +167,29 @@ fn build_zlib(cfg: &mut cc::Build, target: &str) {
println!("cargo:include={}/include", dst.to_str().unwrap());
}

#[cfg(any(feature = "zlib-ng", feature = "zlib-ng-no-cmake"))]
#[cfg(any(
feature = "zlib-ng",
feature = "zlib-ng-no-cmake-experimental-community-maintained"
))]
mod zng {
#[cfg_attr(feature = "zlib-ng", path = "cmake.rs")]
#[cfg_attr(feature = "zlib-ng-no-cmake", path = "cc.rs")]
#[cfg_attr(
all(
feature = "zlib-ng-no-cmake-experimental-community-maintained",
not(feature = "zlib-ng")
),
path = "cc.rs"
)]
mod build_zng;

pub(super) use build_zng::build_zlib_ng;
}

fn build_zlib_ng(_target: &str, _compat: bool) {
#[cfg(any(feature = "zlib-ng", feature = "zlib-ng-no-cmake"))]
#[cfg(any(
feature = "zlib-ng",
feature = "zlib-ng-no-cmake-experimental-community-maintained"
))]
zng::build_zlib_ng(_target, _compat);
}

Expand Down
4 changes: 2 additions & 2 deletions ci/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ echo '::endgroup::'
skip_triples=("x86_64-unknown-linux-gnu" "i686-unknown-linux-gnu" "aarch64-unknown-linux-gnu" "arm-unknown-linux-gnueabihf")
if [[ -z $CI ]] || ! [[ ${skip_triples[@]} =~ "${TARGET_TRIPLE}" ]]; then
echo '::group::=== zlib-ng-no-cmake build ==='
$CROSS test --target "$TARGET_TRIPLE" --no-default-features --features zlib-ng-no-cmake
$CROSS run --target "$TARGET_TRIPLE" --manifest-path systest/Cargo.toml --no-default-features --features zlib-ng-no-cmake
$CROSS test --target "$TARGET_TRIPLE" --no-default-features --features zlib-ng-no-cmake-experimental-community-maintained
$CROSS run --target "$TARGET_TRIPLE" --manifest-path systest/Cargo.toml --no-default-features --features zlib-ng-no-cmake-experimental-community-maintained
echo '::endgroup::'
fi

Expand Down
4 changes: 3 additions & 1 deletion systest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ ctest2 = "0.4.4"
[features]
libz-static = ["libz-sys/static"]
zlib-ng = ["libz-sys/zlib-ng"]
zlib-ng-no-cmake = ["libz-sys/zlib-ng-no-cmake"]
zlib-ng-no-cmake-experimental-community-maintained = [
"libz-sys/zlib-ng-no-cmake-experimental-community-maintained",
]

0 comments on commit c0b2e5f

Please sign in to comment.