Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cc as an optional alternative to cmake #174

Merged
merged 33 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0aadb3e
Checkpoint
Jake-Shadle Jan 17, 2024
02042e0
Switch to cc in Cargo-zng.toml
Jake-Shadle Jan 17, 2024
ca67f9f
What
Jake-Shadle Jan 17, 2024
0e7025b
Fix version read
Jake-Shadle Jan 17, 2024
d2709ad
Fix compilation in non-compat
Jake-Shadle Jan 17, 2024
84e9eb7
Oops
Jake-Shadle Jan 17, 2024
08380a4
Target features may not be present in some cases
Jake-Shadle Jan 17, 2024
9bbe8be
Sigh
Jake-Shadle Jan 17, 2024
892409b
Fix windows
Jake-Shadle Jan 17, 2024
1176816
More fixes
Jake-Shadle Jan 17, 2024
1d0f949
Fix off_t
Jake-Shadle Jan 17, 2024
d82ff40
Fix harder
Jake-Shadle Jan 17, 2024
36284c9
Why
Jake-Shadle Jan 17, 2024
6afbe08
Fix zconf
Jake-Shadle Jan 17, 2024
78abd4e
Minor cleanup
Jake-Shadle Jan 17, 2024
47a44ef
Address feedback
Jake-Shadle Jan 17, 2024
6bae6f8
Further cleanup
Jake-Shadle Jan 17, 2024
70cb64a
Add zlib-ng-no-cmake feature
Jake-Shadle Jan 31, 2024
c5d869f
Fix arm
Jake-Shadle Jan 31, 2024
6fdef27
Print compiler version if compilation fails
Jake-Shadle Jan 31, 2024
032c708
Oops
Jake-Shadle Jan 31, 2024
fe92fcb
Don't build i686/x86_64 linux-gnu on CI
Jake-Shadle Jan 31, 2024
8b4d3be
Don't set ARM_NEON_HASLD4
Jake-Shadle Jan 31, 2024
6e62175
Fix arm
Jake-Shadle Jan 31, 2024
b2d285a
Skip more old/broken targets
Jake-Shadle Jan 31, 2024
0f188f3
Mabye this isn't set inside container?
Jake-Shadle Jan 31, 2024
0f599ad
Use log groups in CI
Jake-Shadle Jan 31, 2024
79c4d4c
Add s390x support, flesh out powerpc/risv todo
Jake-Shadle Feb 1, 2024
66a0e1d
Rename feature
Jake-Shadle Feb 1, 2024
23d3369
Add CI job
Jake-Shadle Feb 1, 2024
cb5b895
Skip s390x as well, compiler is too old
Jake-Shadle Feb 1, 2024
4d68d13
Print warning to github actions if cc test/systest run fail
Jake-Shadle Feb 3, 2024
3fbea9f
Address feedback
Jake-Shadle Feb 3, 2024
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
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ jobs:
target:
- x86_64-apple-darwin

cc:
runs-on: ubuntu-22.04
env:
TARGET_TRIPLE: x86_64-unknown-linux-gnu
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: true
# Ensures --all-features builds correctly, the current logic will mean it
# uses stock zlib, not cmake nor cc
- run: |
cargo test --target $TARGET_TRIPLE --all-features
cargo run --target $TARGET_TRIPLE --manifest-path systest/Cargo.toml --all-features
# Ensures zlib-ng builds and runs, though zlib-ng _could_ change internally
# and not use all optimizations available to the CI runner, we do this here
# just for x86_64-unknown-linux-gnu to validate a common target compiles
# on a more recent compiler than the incredibly ancient one currently used by cross
- run: |
Jake-Shadle marked this conversation as resolved.
Show resolved Hide resolved
cargo test --target $TARGET_TRIPLE --no-default-features --features zlib-ng-no-cmake-experimental-community-maintained || echo "::warning::failed to build libz-ng with --features zlib-ng-no-cmake-experimental-community-maintained"
cargo run --target $TARGET_TRIPLE --manifest-path systest/Cargo.toml --no-default-features --features zlib-ng-no-cmake-experimental-community-maintained || echo "::warning::failed to run systest with --features zlib-ng-no-cmake-experimental-community-maintained"

linux:
runs-on: ubuntu-latest
needs: install-cross
Expand Down
10 changes: 7 additions & 3 deletions Cargo-zng.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[package]
name = "libz-ng-sys"
version = "1.1.15"
authors = ["Alex Crichton <alex@alexcrichton.com>", "Josh Triplett <josh@joshtriplett.org>", "Sebastian Thiel <sebastian.thiel@icloud.com>"]
authors = [
"Alex Crichton <alex@alexcrichton.com>",
"Josh Triplett <josh@joshtriplett.org>",
"Sebastian Thiel <sebastian.thiel@icloud.com>",
]
links = "z-ng"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/libz-sys"
Expand All @@ -22,7 +26,7 @@ exclude = [
"/systest",
]

build = "build_zng.rs"
build = "zng/cmake.rs"
readme = "README-zng.md"

[workspace]
Expand All @@ -32,4 +36,4 @@ members = ["systest"]
libc = "0.2.43"

[build-dependencies]
cmake = "0.1.44"
cmake = "0.1"
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ libc = { version = "0.2.43", optional = true }
[build-dependencies]
pkg-config = "0.3.9"
cc = "1.0.18"
cmake = { version = "0.1.44", optional = true }
cmake = { version = "0.1.50", optional = true }
vcpkg = "0.2"

[features]
Expand All @@ -56,9 +56,14 @@ 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 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)
#
# Building zlib-ng requires cmake.
zlib-ng = ["libc", "cmake"]
# 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
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ 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`.
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.

Crates that don't require compatibility with the zlib C API, and use zlib
exclusively from Rust or support the zlib-ng native C API (prefixed with
Expand All @@ -62,10 +66,10 @@ but we don't guarantee these will continue to work.

This project is licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
https://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
https://opensource.org/license/mit/)
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
<https://www.apache.org/licenses/LICENSE-2.0>)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
<https://opensource.org/license/mit/>)

at your option.

Expand Down
38 changes: 31 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-env-changed=LIBZ_SYS_STATIC");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=zng/cmake.rs");
println!("cargo:rerun-if-changed=zng/cc.rs");

let host = env::var("HOST").unwrap();
let target = env::var("TARGET").unwrap();

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

let want_ng = cfg!(feature = "zlib-ng") && !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 @@ -169,13 +175,31 @@ fn build_zlib(cfg: &mut cc::Build, target: &str) {
println!("cargo:include={}/include", dst.to_str().unwrap());
}

#[cfg(not(feature = "zlib-ng"))]
fn build_zlib_ng(_target: &str, _compat: bool) {}
#[cfg(any(
feature = "zlib-ng",
feature = "zlib-ng-no-cmake-experimental-community-maintained"
))]
mod zng {
Jake-Shadle marked this conversation as resolved.
Show resolved Hide resolved
#[cfg_attr(feature = "zlib-ng", path = "cmake.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;
}

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

fn try_vcpkg() -> bool {
// see if there is a vcpkg tree with zlib installed
Expand Down
25 changes: 21 additions & 4 deletions ci/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,32 @@ fi

$CROSS test --target $TARGET_TRIPLE
$CROSS run --target $TARGET_TRIPLE --manifest-path systest/Cargo.toml
echo === zlib-ng build ===

echo '::group::=== zlib-ng build ==='
$CROSS test --target $TARGET_TRIPLE --no-default-features --features zlib-ng
$CROSS run --target $TARGET_TRIPLE --manifest-path systest/Cargo.toml --no-default-features --features zlib-ng
echo === libz-ng-sys build ===
echo '::endgroup::'

# Note we skip compiling these targets on CI because the gcc version currently used in
# cross for them is 5.4, ~8 years old at this point, hopefully it will be updated...sometime
skip_triples=("x86_64-unknown-linux-gnu" "i686-unknown-linux-gnu" "aarch64-unknown-linux-gnu" "arm-unknown-linux-gnueabihf" "s390x-unknown-linux-gnu")
if [[ -z $CI ]] || ! [[ ${skip_triples[@]} =~ "${TARGET_TRIPLE}" ]]; then
echo '::group::=== zlib-ng-no-cmake-experimental-community-maintained build ==='

$CROSS test --target "$TARGET_TRIPLE" --no-default-features --features zlib-ng-no-cmake-experimental-community-maintained || echo "::warning file=$(basename $0),line=$LINENO::Failed to test zlib-ng with --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 "::warning file=$(basename $0),line=$LINENO::Failed to run systest with --features zlib-ng-no-cmake-experimental-community-maintained"

echo '::endgroup::'
fi

echo '::group::=== libz-ng-sys build ==='
mv Cargo-zng.toml Cargo.toml
mv systest/Cargo-zng.toml systest/Cargo.toml
$CROSS test --target $TARGET_TRIPLE
$CROSS run --target $TARGET_TRIPLE --manifest-path systest/Cargo.toml
echo '::endgroup::'

echo === flate2 validation ===
echo '::group::=== flate2 validation ==='
git clone https://github.com/rust-lang/flate2-rs flate2
git worktree add flate2/libz-sys
git worktree add flate2/libz-ng-sys
Expand All @@ -67,4 +83,5 @@ set -x
$CROSS test --features zlib --target $TARGET_TRIPLE
$CROSS test --features zlib-default --no-default-features --target $TARGET_TRIPLE
$CROSS test --features zlib-ng --no-default-features --target $TARGET_TRIPLE
$CROSS test --features zlib-ng-compat --no-default-features --target $TARGET_TRIPLE
$CROSS test --features zlib-ng-compat --no-default-features --target $TARGET_TRIPLE
echo '::endgroup::'
3 changes: 3 additions & 0 deletions systest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ ctest2 = "0.4.4"
[features]
libz-static = ["libz-sys/static"]
zlib-ng = ["libz-sys/zlib-ng"]
zlib-ng-no-cmake-experimental-community-maintained = [
"libz-sys/zlib-ng-no-cmake-experimental-community-maintained",
]
Loading
Loading