streamline msrv #1943
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: checks | |
permissions: | |
contents: read | |
on: | |
push: | |
branches: | |
- main | |
- 'release/**' | |
pull_request: | |
branches-ignore: | |
- 'release/**' | |
schedule: | |
- cron: '0 4 * * *' | |
merge_group: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Build and test | |
runs-on: "${{ matrix.os }}" | |
env: | |
RUST_BACKTRACE: 1 | |
# i686-unknown-linux-gnu | |
CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER: i686-linux-gnu-gcc | |
# s390x-unknown-linux-gnu | |
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER: s390x-linux-gnu-gcc | |
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER: qemu-s390x -L /usr/s390x-linux-gnu | |
# wasm32-wasip1 (std for wasip2 is unstable) | |
WASI_SDK_PATH: /tmp/wasi-sdk-24.0-x86_64-linux | |
CC_wasm32_wasip1: /tmp/wasi-sdk-24.0-x86_64-linux/bin/clang | |
AR_wasm32_wasip1: /tmp/wasi-sdk-24.0-x86_64-linux/bin/llvm-ar | |
CARGO_TARGET_WASM32_WASIP1_RUNNER: "wasmtime --dir /home/runner/work/zlib-rs/zlib-rs/test-libz-rs-sys --dir /tmp/" | |
CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS: "-Ctarget-feature=+simd128" | |
BINDGEN_EXTRA_CLANG_ARGS_wasm32_wasip1: "--sysroot=/tmp/wasi-sdk-24.0-x86_64-linux/share/wasi-sysroot" | |
strategy: | |
matrix: | |
include: | |
- rust: stable | |
target: "x86_64-unknown-linux-gnu" | |
os: ubuntu-latest | |
codecov: true | |
- rust: msrv | |
target: "x86_64-unknown-linux-gnu" | |
os: ubuntu-latest | |
codecov: false | |
- rust: beta | |
target: "x86_64-unknown-linux-gnu" | |
os: ubuntu-latest | |
codecov: false | |
- target: "aarch64-unknown-linux-gnu" | |
os: ubuntu-24.04-arm | |
codecov: true | |
- target: "i686-unknown-linux-gnu" | |
os: ubuntu-latest | |
codecov: true | |
packages: gcc-i686-linux-gnu | |
- target: "s390x-unknown-linux-gnu" | |
os: ubuntu-latest | |
codecov: false | |
packages: gcc-s390x-linux-gnu qemu-user qemu-user-static | |
- target: "wasm32-wasip1" | |
os: ubuntu-latest | |
flags: "-p zlib-rs -p libz-rs-sys -p test-libz-rs-sys" | |
codecov: false | |
- target: "x86_64-apple-darwin" | |
os: macos-latest | |
codecov: true | |
- target: "aarch64-apple-darwin" | |
os: macos-14 | |
codecov: true | |
- target: "x86_64-pc-windows-gnu" | |
os: windows-2022 | |
codecov: false | |
- target: "aarch64-pc-windows-msvc" | |
os: windows-11-arm | |
codecov: false | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
# Install the correct rust toolchain/version | |
- name: Set target rust version | |
run: echo "MSRV=$(grep rust-version Cargo.toml | grep MSRV | awk -F '\"' '{print $2}')" >> $GITHUB_ENV | |
if: ${{ matrix.rust == 'msrv' }} | |
- name: Install toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: ${{ env.MSRV || matrix.rust || 'stable' }} | |
targets: "${{ matrix.target }}" | |
# Install dependencies | |
- name: Install cargo-llvm-cov & cargo-nextest | |
uses: taiki-e/install-action@d12e869b89167df346dd0ff65da342d1fb1202fb # v2.53.2 | |
with: | |
tool: cargo-llvm-cov,cargo-nextest | |
- name: Cache apt packages | |
if: matrix.packages != '' | |
uses: awalsh128/cache-apt-pkgs-action@v1 | |
with: | |
packages: "${{ matrix.packages }}" | |
version: 2 | |
- name: Download wasmtime & wasi-sdk | |
if: ${{ contains(matrix.target, 'wasm') }} | |
run: | | |
curl https://wasmtime.dev/install.sh -sSf | bash | |
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH | |
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-x86_64-linux.tar.gz | tar xz --directory /tmp | |
# build | |
- name: cargo build | |
run: cargo build --target ${{matrix.target}} ${{ matrix.flags }} | |
# run tests | |
- name: cargo llvm-cov nextest | |
if: matrix.codecov | |
run: cargo llvm-cov nextest --lcov --output-path lcov.info --ignore-filename-regex "test-libz|dynamic-libz" --target ${{matrix.target}} ${{ matrix.flags }} --no-fail-fast | |
- name: cargo nextest | |
if: matrix.codecov == false | |
run: cargo nextest run --target ${{matrix.target}} ${{ matrix.flags }} --no-fail-fast | |
- name: cargo nextest cdylib | |
if: matrix.codecov | |
working-directory: libz-rs-sys-cdylib | |
run: cargo llvm-cov nextest --target ${{matrix.target}} --features="gz,__internal-test" --lcov --output-path cdylib.lcov.info --ignore-filename-regex "test-libz|dynamic-libz" | |
- name: cargo nextest cdylib | |
if: matrix.codecov == false | |
working-directory: libz-rs-sys-cdylib | |
run: cargo nextest run --target ${{matrix.target}} --features="gz,__internal-test" --no-fail-fast | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0 | |
if: matrix.codecov | |
with: | |
files: | | |
./lcov.info | |
./cdylib.lcov.info | |
fail_ci_if_error: false | |
flags: test-${{matrix.target}} | |
token: ${{ secrets.CODECOV_TOKEN }} | |
name: test | |
verbose: true | |
clippy: | |
name: Clippy | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
features: | |
- "" | |
- '--no-default-features --features="c-allocator"' | |
- '--no-default-features --features="rust-allocator"' | |
- '--no-default-features --features="gz" --features="c-allocator"' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Install rust toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: stable | |
components: clippy, rustfmt | |
targets: ${{matrix.target}} | |
- name: Rust cache | |
uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 | |
with: | |
shared-key: "stable-${{matrix.target}}" | |
- name: Run rustfmt and clippy | |
run: | | |
cargo fmt --all --check | |
cargo clippy --target ${{matrix.target}} ${{matrix.features}} --workspace --all-targets -- -D warnings | |
- name: Run rustfmt and clippy (cdylib) | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
cargo fmt --all --check | |
cargo clippy --target ${{matrix.target}} ${{matrix.features}} --workspace --all-targets -- -D warnings | |
- name: Run clippy (fuzzers) | |
if: ${{ !contains(matrix.features, 'gz') }} | |
run: cargo clippy --target ${{matrix.target}} ${{matrix.features}} --manifest-path ./fuzz/Cargo.toml --all-targets -- -D warnings | |
- name: Run cargo doc, deny warnings | |
env: | |
RUSTDOCFLAGS: "-D warnings" | |
run: | | |
cargo doc --target ${{matrix.target}} -p libz-rs-sys | |
fuzz: | |
name: Smoke-test fuzzing targets | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
features: | |
- 'default' | |
- 'c-allocator' | |
- 'rust-allocator' | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Install nightly toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: nightly | |
- name: Install cargo fuzz | |
run: cargo install cargo-fuzz | |
- name: Smoke-test fuzz targets | |
run: | | |
cargo fuzz build --no-default-features --features="${{ matrix.features }}" | |
for target in $(cargo fuzz list); do | |
if [ "$target" = "uncompress" ]; then | |
features="${{ matrix.features }} disable-checksum" | |
else | |
features="${{ matrix.features }}" | |
fi | |
RUST_BACKTRACE=1 cargo fuzz run --no-default-features --features="$features" $target -- -max_total_time=10 | |
done | |
fuzz-aarch64: | |
name: Smoke-test fuzzing targets | |
runs-on: macos-latest | |
strategy: | |
matrix: | |
include: | |
- rust: "stable" | |
os: macos-14 | |
features: "" | |
target: "aarch64-apple-darwin" | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Install nightly toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: nightly | |
- name: Install cargo fuzz | |
run: cargo install cargo-fuzz | |
- name: Smoke-test fuzz targets | |
run: | | |
cargo fuzz build --no-default-features --features="${{ matrix.features }}" | |
for target in $(cargo fuzz list); do | |
if [ "$target" = "uncompress" ]; then | |
features="${{ matrix.features }} disable-checksum" | |
else | |
features="${{ matrix.features }}" | |
fi | |
RUST_BACKTRACE=1 cargo fuzz run --no-default-features --features="$features" $target -- -max_total_time=10 | |
done | |
fuzz-code-coverage: | |
name: Fuzz with code coverage | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- fuzz_target: uncompress | |
corpus: "gzip-files/compressed" | |
features: '--no-default-features --features="disable-checksum,keep-invalid-in-corpus"' | |
flags: fuzz-decompress | |
- fuzz_target: compress | |
corpus: "" | |
features: '' | |
flags: fuzz-compress | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Install nightly toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: nightly | |
components: llvm-tools-preview | |
- name: Install cargo fuzz | |
run: cargo install cargo-fuzz | |
- name: Install rustfilt | |
uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8 | |
with: | |
tool: rustfilt | |
- name: Download custom decompression corpus | |
if: ${{ contains(matrix.corpus, 'gzip-files') }} | |
run: | | |
wget https://github.com/trifectatechfoundation/compression-corpus/releases/download/2025-04-14-103007/gzip-files.zip | |
unzip gzip-files.zip -d gzip-files | |
- name: Run `cargo fuzz` | |
env: | |
RUST_BACKTRACE: "1" | |
# prevents `cargo fuzz coverage` from rebuilding everything | |
RUSTFLAGS: "-C instrument-coverage" | |
run: | | |
cargo fuzz run ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}} -- -max_total_time=10 | |
- name: Fuzz codecov | |
run: | | |
cargo fuzz coverage ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}} | |
$(rustc --print sysroot)/lib/rustlib/$(rustc --print host-tuple)/bin/llvm-cov export -Xdemangler=rustfilt \ | |
target/$(rustc --print host-tuple)/coverage/$(rustc --print host-tuple)/release/${{matrix.fuzz_target}} \ | |
-instr-profile=fuzz/coverage/${{matrix.fuzz_target}}/coverage.profdata \ | |
--format=lcov \ | |
-ignore-filename-regex="\.cargo|\.rustup|fuzz_targets" > lcov.info | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d | |
with: | |
files: ./lcov.info | |
fail_ci_if_error: false | |
flags: ${{ matrix.flags }} | |
token: ${{ secrets.CODECOV_TOKEN }} | |
name: fuzz | |
link-c-dynamic-library: | |
name: vanilla dynamic library | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
features: | |
- '' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Install rust toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: stable | |
targets: ${{matrix.target}} | |
- name: "cdylib: default settings" | |
working-directory: libz-rs-sys-cdylib | |
env: | |
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps" | |
run: | | |
cargo build --release --target ${{matrix.target}} | |
cc -o zpipe zpipe.c target/${{matrix.target}}/release/deps/libz_rs.so | |
./zpipe < Cargo.toml | ./zpipe -d > out.txt | |
cmp -s Cargo.toml out.txt | |
- name: "cdylib: rust-allocator" | |
env: | |
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps" | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
cargo build --release --target ${{matrix.target}} --no-default-features --features="rust-allocator" | |
cc -o zpipe zpipe.c target/${{matrix.target}}/release/deps/libz_rs.so | |
./zpipe < Cargo.toml | ./zpipe -d > out.txt | |
cmp -s Cargo.toml out.txt | |
- name: "cdylib: no_std" | |
env: | |
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps" | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
cargo build --release --target ${{matrix.target}} --no-default-features | |
cc -DNO_STD -o zpipe zpipe.c target/${{matrix.target}}/release/deps/libz_rs.so | |
./zpipe < Cargo.toml | ./zpipe -d > out.txt | |
cmp -s Cargo.toml out.txt | |
- name: "cdylib: custom-prefix" | |
working-directory: libz-rs-sys-cdylib | |
env: | |
LIBZ_RS_SYS_PREFIX: "MY_CUSTOM_PREFIX_" | |
run: | | |
cargo build --release --target ${{matrix.target}} --features=custom-prefix | |
objdump -tT target/${{matrix.target}}/release/deps/libz_rs.so | grep -q "MY_CUSTOM_PREFIX_uncompress" || (echo "symbol not found!" && exit 1) | |
- name: "cdylib: semver-prefix" | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
cargo build --release --target ${{matrix.target}} --features=semver-prefix | |
objdump -tT target/${{matrix.target}}/release/deps/libz_rs.so | grep -q -E "LIBZ_RS_SYS_v0.[0-9]+.x_uncompress" || (echo "symbol not found!" && exit 1) | |
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends valgrind | |
- name: "cdylib: example.c" | |
env: | |
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps" | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
rustup toolchain install nightly | |
cargo +nightly build --release --target ${{matrix.target}} --no-default-features --features=gz,gzprintf,c-allocator | |
cc -o example example.c target/${{matrix.target}}/release/deps/libz_rs.so | |
./example | |
valgrind --track-origins=yes --error-exitcode=1 ./example | |
- name: "cdylib: example.c with our .h files" | |
env: | |
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps" | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
cc -o example example.c target/${{matrix.target}}/release/deps/libz_rs.so -I../libz-rs-sys/include/ | |
./example | |
valgrind --track-origins=yes --error-exitcode=1 ./example | |
cargo-c-dynamic-library: | |
name: cargo-c dynamic library | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
features: | |
- '' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: Install rust toolchain | |
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 | |
with: | |
toolchain: stable | |
targets: ${{matrix.target}} | |
- name: Install cargo-c | |
env: | |
LINK: https://github.com/lu-zero/cargo-c/releases/download/v0.10.5 | |
run: | | |
curl -L "$LINK/cargo-c-x86_64-unknown-linux-musl.tar.gz" | | |
tar xz -C $HOME/.cargo/bin | |
- name: build with and test the result of cargo-c | |
working-directory: libz-rs-sys-cdylib | |
run: | | |
# build using cargo-c this time | |
cargo cinstall --release --destdir=/tmp/cargo-cbuild-libz-rs | |
tree /tmp/cargo-cbuild-libz-rs | |
# verify that the SONAME is set and includes a version | |
objdump -p target/x86_64-unknown-linux-gnu/release/libz_rs.so | awk '/SONAME/{print $2}' | grep -E 'libz_rs\.so\.1' | |
# build zpipe with our library | |
cc -o zpipe zpipe.c -L/tmp/cargo-cbuild-libz-rs/usr/local/lib/x86_64-linux-gnu -lz_rs | |
export LD_LIBRARY_PATH=/tmp/cargo-cbuild-libz-rs/usr/local/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH | |
./zpipe < Cargo.toml | ./zpipe -d > out.txt | |
cmp -s Cargo.toml out.txt | |
miri: | |
name: "Miri" | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
- target: x86_64-pc-windows-gnu | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Miri | |
run: | | |
rustup target add ${{ matrix.target }} | |
rustup toolchain install nightly --component miri | |
cargo +nightly miri setup | |
- name: Install gcc | |
if: ${{ contains(matrix.target, 'windows') }} | |
run: | | |
sudo apt-get install gcc-mingw-w64-x86-64 | |
x86_64-w64-mingw32-gcc --help | |
- name: Install cargo-nextest | |
uses: taiki-e/install-action@d12e869b89167df346dd0ff65da342d1fb1202fb # v2.53.2 | |
with: | |
tool: cargo-nextest | |
- name: Test public C api with NULL arguments | |
run: "cargo +nightly miri nextest run -j4 -p test-libz-rs-sys --target ${{ matrix.target }} null::" | |
env: | |
RUSTFLAGS: "-Ctarget-feature=+avx2,+bmi2,+bmi1" | |
- name: Test allocator with miri | |
run: "cargo +nightly miri nextest run -j4 -p zlib-rs --target ${{ matrix.target }} allocate::" | |
- name: Test gz logic with miri | |
working-directory: libz-rs-sys-cdylib | |
run: "cargo +nightly miri nextest run -j4 -p libz-rs-sys-cdylib --target ${{ matrix.target }} --features=gz" | |
env: | |
MIRIFLAGS: "-Zmiri-tree-borrows -Zmiri-disable-isolation" | |
run-flate2-test-suite: | |
name: run flate2 test suite | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
features: | |
- '' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
with: | |
persist-credentials: false | |
- name: run | |
run: | | |
cd .. | |
git clone https://github.com/rust-lang/flate2-rs.git | |
cd flate2-rs | |
sed -i '/^libz-rs-sys =/c\libz-rs-sys = { path = "../zlib-rs/libz-rs-sys", optional = true, default-features = false, features = ["std", "rust-allocator"] }' Cargo.toml | |
cargo test --no-default-features --features="zlib-rs" | |