diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 7385bdbd..cd8e40d7 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -192,3 +192,37 @@ jobs: for target in $(cargo fuzz list ${{ matrix.features }}) ; do RUST_BACKTRACE=1 cargo fuzz run ${{ matrix.features }} $target -- -max_total_time=10 done + + link-c-dynamic-library: + name: 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: Rust cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 + with: + shared-key: "stable-${{matrix.target}}" + - name: get zpipe.c + run: wget https://www.zlib.net/zpipe.c + - name: cargo build + run: cargo build --target ${{matrix.target}} -p libz-rs-sys --release + - name: cc + run: cc -o zpipe zpipe.c target/${{matrix.target}}/release/deps/liblibz_rs_sys.so + - name: execute + run: cat Cargo.toml | ./zpipe | ./zpipe -d > out.txt + - name: compare + run: cmp -s Cargo.toml out.txt diff --git a/libz-rs-sys/src/lib.rs b/libz-rs-sys/src/lib.rs index 4e205c48..a6788253 100644 --- a/libz-rs-sys/src/lib.rs +++ b/libz-rs-sys/src/lib.rs @@ -650,16 +650,18 @@ pub unsafe extern "C" fn deflateTune( } } -const LIBZ_RS_SYS_VERSION: &str = env!("CARGO_PKG_VERSION"); +// the first part of this version specifies the zlib that we're compatible with (in terms of +// supported functions). In practice in most cases only the major version is checked, unless +// specific functions that were added later are used. +const LIBZ_RS_SYS_VERSION: &str = concat!("1.3.0-zlib-rs-", env!("CARGO_PKG_VERSION"), "\0"); unsafe fn is_version_compatible(version: *const c_char, stream_size: i32) -> bool { if version.is_null() { return false; } - let cstr = core::ffi::CStr::from_ptr(version); - - if LIBZ_RS_SYS_VERSION.as_bytes()[0] != cstr.to_bytes()[0] { + let expected_major_version = core::ptr::read(version); + if expected_major_version as u8 != LIBZ_RS_SYS_VERSION.as_bytes()[0] { return false; } @@ -667,19 +669,5 @@ unsafe fn is_version_compatible(version: *const c_char, stream_size: i32) -> boo } pub const extern "C" fn zlibVersion() -> *const c_char { - const BUF: [u8; 16] = { - let mut buf = [0; 16]; - - let mut i = 0; - while i < LIBZ_RS_SYS_VERSION.len() { - buf[i] = LIBZ_RS_SYS_VERSION.as_bytes()[i]; - i += 1; - } - - assert!(matches!(buf.last(), Some(0))); - - buf - }; - - BUF.as_ptr() as *const c_char + LIBZ_RS_SYS_VERSION.as_ptr() as *const c_char }