diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ebe1ed..9b8c76d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,8 @@ jobs: - "" - "--no-default-features --features deflate" - "--no-default-features --features zstd" + - "--no-default-features --features zstd-rust" + - "--features zstd-rust" steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -52,7 +54,7 @@ jobs: default: true - name: assert deps don't exist with --no-default-features run: | - for DEP in libflate zstd; do + for DEP in libflate zstd structured-zstd; do if cargo tree --no-default-features --invert $DEP; then echo "Dependency $DEP should not exist with --no-default-features" exit 1 @@ -70,3 +72,11 @@ jobs: echo "Feature `zstd` should not create dep on `libflate`" exit 1 fi + - name: assert `zstd-rust` feature doesn't create dep on the C zstd bindings + run: | + for DEP in zstd zstd-sys libflate; do + if cargo tree --no-default-features --features zstd-rust --invert $DEP; then + echo "Feature `zstd-rust` should not create dep on $DEP" + exit 1 + fi + done diff --git a/Cargo.toml b/Cargo.toml index 81fe4fc..bd61fa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ license = "Apache-2.0" [workspace.dependencies] libflate = "2.3.0" zstd = "0.14.0" +structured-zstd = "0.0.56" [package] name = "include-flate" @@ -34,4 +35,7 @@ include-flate-compress = { version = "0.3.4", path = "compress", default-feature default = ["deflate", "zstd"] deflate = ["include-flate-codegen/deflate", "include-flate-compress/deflate"] zstd = ["include-flate-codegen/zstd", "include-flate-compress/zstd"] +# Zstandard through the pure-Rust `structured-zstd`, with no C toolchain. The +# `with zstd` syntax and the compressed format are the same as with `zstd`. +zstd-rust = ["include-flate-codegen/zstd-rust", "include-flate-compress/zstd-rust"] no-compression-warnings = ["include-flate-codegen/no-compression-warnings"] diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 0f0f4b3..889a2ce 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -22,4 +22,5 @@ proc-macro-error3 = "3.0.2" default = ["deflate", "zstd"] deflate = ["include-flate-compress/deflate"] zstd = ["include-flate-compress/zstd"] +zstd-rust = ["include-flate-compress/zstd-rust"] no-compression-warnings = [] diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index bfd379d..ddae492 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -98,13 +98,16 @@ impl syn::parse::Parse for FlateArgs { "Please enable the `deflate` feature", )); } else if lookahead.peek(kw::zstd) { - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] { input.parse::()?; Some(CompressionMethodTy(CompressionMethod::Zstd)) } - #[cfg(not(feature = "zstd"))] - return Err(Error::new(input.span(), "Please enable the `zstd` feature")); + #[cfg(not(any(feature = "zstd", feature = "zstd-rust")))] + return Err(Error::new( + input.span(), + "Please enable the `zstd` or `zstd-rust` feature", + )); } else { return Err(lookahead.error()); } diff --git a/compress/Cargo.toml b/compress/Cargo.toml index 2e6a4f5..89c7cfe 100644 --- a/compress/Cargo.toml +++ b/compress/Cargo.toml @@ -11,8 +11,12 @@ description = "Compression algorithm provider" [dependencies] libflate = { workspace = true, optional = true } zstd = { workspace = true, optional = true } +structured-zstd = { workspace = true, optional = true } [features] default = ["deflate", "zstd"] deflate = ["dep:libflate"] zstd = ["dep:zstd"] +# Zstandard through the pure-Rust `structured-zstd` instead of the C library. +# Same frame format; takes precedence when `zstd` is enabled as well. +zstd-rust = ["dep:structured-zstd"] diff --git a/compress/src/lib.rs b/compress/src/lib.rs index e6b0a47..ca46241 100644 --- a/compress/src/lib.rs +++ b/compress/src/lib.rs @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(not(any(feature = "zstd", feature = "deflate")))] -compile_error!("You must enable either the `deflate` or `zstd` feature."); +#[cfg(not(any(feature = "zstd", feature = "zstd-rust", feature = "deflate")))] +compile_error!("You must enable either the `deflate`, `zstd` or `zstd-rust` feature."); use std::{ fmt, @@ -25,16 +25,55 @@ use std::{ use libflate::deflate::Decoder as DeflateDecoder; #[cfg(feature = "deflate")] use libflate::deflate::Encoder as DeflateEncoder; -#[cfg(feature = "zstd")] -use zstd::Decoder as ZstdDecoder; -#[cfg(feature = "zstd")] -use zstd::Encoder as ZstdEncoder; + +// Zstandard has two interchangeable backends producing and reading the same +// frame format: the `zstd` crate (bindings to the C library) and the pure-Rust +// `structured-zstd`. When both features are enabled, `zstd-rust` is used: a +// dependency that asks for it opts out of the C toolchain. +// +// The pure-Rust coder keeps its state inline (the C one holds a pointer to +// it), so it is boxed to keep the enums below the size of their other +// variants. +#[cfg(feature = "zstd-rust")] +type ZstdEncoder = Box>; +#[cfg(all(feature = "zstd", not(feature = "zstd-rust")))] +type ZstdEncoder = zstd::Encoder<'static, W>; +#[cfg(feature = "zstd-rust")] +type ZstdDecoder = + Box>; +#[cfg(all(feature = "zstd", not(feature = "zstd-rust")))] +type ZstdDecoder = zstd::Decoder<'static, std::io::BufReader>; + +#[cfg(feature = "zstd-rust")] +fn zstd_encoder(write: W) -> io::Result> { + // `Default` is this backend's counterpart of zstd level 3, which the C + // backend selects through level 0. + Ok(Box::new(structured_zstd::encoding::StreamingEncoder::new( + write, + structured_zstd::encoding::CompressionLevel::Default, + ))) +} +#[cfg(all(feature = "zstd", not(feature = "zstd-rust")))] +fn zstd_encoder(write: W) -> io::Result> { + ZstdEncoder::new(write, 0) +} + +#[cfg(feature = "zstd-rust")] +fn zstd_decoder(read: R) -> io::Result> { + structured_zstd::decoding::StreamingDecoder::new(read) + .map(Box::new) + .map_err(io::Error::other) +} +#[cfg(all(feature = "zstd", not(feature = "zstd-rust")))] +fn zstd_decoder(read: R) -> io::Result> { + ZstdDecoder::new(read) +} #[derive(Debug)] pub enum CompressionError { #[cfg(feature = "deflate")] DeflateError(io::Error), - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] ZstdError(io::Error), IoError(io::Error), } @@ -50,7 +89,7 @@ impl fmt::Display for CompressionError { match self { #[cfg(feature = "deflate")] CompressionError::DeflateError(err) => write!(f, "Deflate error: {}", err), - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] CompressionError::ZstdError(err) => write!(f, "Zstd error: {}", err), CompressionError::IoError(err) => write!(f, "I/O error: {}", err), } @@ -61,7 +100,7 @@ impl fmt::Display for CompressionError { pub enum CompressionMethod { #[cfg(feature = "deflate")] Deflate, - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] Zstd, } @@ -79,14 +118,14 @@ impl CompressionMethod { clippy::derivable_impls, reason = "cfg_attr on defaults could be confusing" )] -#[cfg(any(feature = "deflate", feature = "zstd"))] +#[cfg(any(feature = "deflate", feature = "zstd", feature = "zstd-rust"))] impl Default for CompressionMethod { fn default() -> Self { #[cfg(feature = "deflate")] { Self::Deflate } - #[cfg(all(not(feature = "deflate"), feature = "zstd"))] + #[cfg(all(not(feature = "deflate"), any(feature = "zstd", feature = "zstd-rust")))] { Self::Zstd } @@ -98,7 +137,7 @@ impl fmt::Display for CompressionMethod { f.write_str(match self { #[cfg(feature = "deflate")] Self::Deflate => "deflate", - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] Self::Zstd => "zstd", }) } @@ -107,8 +146,8 @@ impl fmt::Display for CompressionMethod { pub enum FlateEncoder { #[cfg(feature = "deflate")] Deflate(DeflateEncoder), - #[cfg(feature = "zstd")] - Zstd(ZstdEncoder<'static, W>), + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] + Zstd(ZstdEncoder), } impl FlateEncoder { @@ -116,8 +155,8 @@ impl FlateEncoder { match method { #[cfg(feature = "deflate")] CompressionMethod::Deflate => Ok(FlateEncoder::Deflate(DeflateEncoder::new(write))), - #[cfg(feature = "zstd")] - CompressionMethod::Zstd => ZstdEncoder::new(write, 0) + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] + CompressionMethod::Zstd => zstd_encoder(write) .map(FlateEncoder::Zstd) .map_err(CompressionError::ZstdError), } @@ -129,7 +168,7 @@ impl Write for FlateEncoder { match self { #[cfg(feature = "deflate")] FlateEncoder::Deflate(encoder) => encoder.write(buf), - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] FlateEncoder::Zstd(encoder) => encoder.write(buf), } } @@ -138,7 +177,7 @@ impl Write for FlateEncoder { match self { #[cfg(feature = "deflate")] FlateEncoder::Deflate(encoder) => encoder.flush(), - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] FlateEncoder::Zstd(encoder) => encoder.flush(), } } @@ -152,17 +191,19 @@ impl FlateEncoder { .finish() .into_result() .map_err(CompressionError::DeflateError), - #[cfg(feature = "zstd")] + #[cfg(feature = "zstd-rust")] + FlateEncoder::Zstd(encoder) => (*encoder).finish().map_err(CompressionError::ZstdError), + #[cfg(all(feature = "zstd", not(feature = "zstd-rust")))] FlateEncoder::Zstd(encoder) => encoder.finish().map_err(CompressionError::ZstdError), } } } -pub enum FlateDecoder { +pub enum FlateDecoder { #[cfg(feature = "deflate")] Deflate(DeflateDecoder), - #[cfg(feature = "zstd")] - Zstd(ZstdDecoder<'static, std::io::BufReader>), + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] + Zstd(ZstdDecoder), } impl FlateDecoder { @@ -170,9 +211,9 @@ impl FlateDecoder { match method { #[cfg(feature = "deflate")] CompressionMethod::Deflate => Ok(FlateDecoder::Deflate(DeflateDecoder::new(read))), - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] CompressionMethod::Zstd => { - let decoder = ZstdDecoder::new(read)?; + let decoder = zstd_decoder(read)?; Ok(FlateDecoder::Zstd(decoder)) } } @@ -184,7 +225,7 @@ impl Read for FlateDecoder { match self { #[cfg(feature = "deflate")] FlateDecoder::Deflate(decoder) => decoder.read(buf), - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] FlateDecoder::Zstd(decoder) => decoder.read(buf), } } diff --git a/compress/tests/zstd_interop.rs b/compress/tests/zstd_interop.rs new file mode 100644 index 0000000..74c80b7 --- /dev/null +++ b/compress/tests/zstd_interop.rs @@ -0,0 +1,53 @@ +// include-flate +// Copyright (C) SOFe +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! The two Zstandard backends read each other's output: a crate built with +//! `zstd-rust` decodes what a `zstd` build embedded, and the reverse. + +#![cfg(all(feature = "zstd", feature = "zstd-rust"))] + +use std::io::Read; + +use include_flate_compress::{CompressionMethod, apply_compression, apply_decompression}; + +fn sample() -> Vec { + (0..200_000u32) + .flat_map(|i| format!("{} {} ", i % 977, i % 13).into_bytes()) + .collect() +} + +#[test] +fn a_c_zstd_frame_decodes_with_the_rust_backend() { + let data = sample(); + let frame = zstd::encode_all(&data[..], 0).unwrap(); + + let mut decoded = Vec::new(); + apply_decompression(&frame[..], &mut decoded, CompressionMethod::Zstd).unwrap(); + assert_eq!(decoded, data); +} + +#[test] +fn a_rust_backend_frame_decodes_with_c_zstd() { + let data = sample(); + let mut frame = Vec::new(); + apply_compression(&mut &data[..], &mut frame, CompressionMethod::Zstd).unwrap(); + + let mut decoded = Vec::new(); + zstd::Decoder::new(&frame[..]) + .unwrap() + .read_to_end(&mut decoded) + .unwrap(); + assert_eq!(decoded, data); +} diff --git a/src/lib.rs b/src/lib.rs index 764310b..aa6aa64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,11 @@ pub use include_flate_compress::CompressionMethod; /// - If `$type` is `str` but the file is not fully valid UTF-8 /// /// # Algorithm -/// Compression and decompression use the DEFLATE algorithm from [`libflate`][5]. +/// Compression and decompression use the DEFLATE algorithm from [`libflate`][5] by default, +/// or Zstandard with `with zstd`. Zstandard is provided by the C library through the `zstd` +/// feature, or by the pure-Rust [`structured-zstd`][7] through the `zstd-rust` feature, which +/// needs no C toolchain and takes precedence when both are enabled. The two produce and read +/// the same format. /// /// # Examples /// Below are some basic examples. For actual compiled examples, see the [`tests`][6] directory. @@ -88,6 +92,7 @@ pub use include_flate_compress::CompressionMethod; /// [4]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates /// [5]: https://docs.rs/libflate/0.1.26/libflate/ /// [6]: https://github.com/SOF3/include-flate/tree/master/tests +/// [7]: https://docs.rs/structured-zstd #[macro_export] macro_rules! flate { ($(#[$meta:meta])* diff --git a/test_util.rs b/test_util.rs index eb42d06..9314a9f 100644 --- a/test_util.rs +++ b/test_util.rs @@ -60,7 +60,7 @@ pub fn verify_compression>(name: P, data: &[u8], method: Compress pub fn verify>(name: P, data: &[u8]) { #[cfg(feature = "deflate")] verify_compression(&name, data, CompressionMethod::Deflate); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_compression(&name, data, CompressionMethod::Zstd); assert_eq!(read_file(&name), data); } diff --git a/tests/009f.rs b/tests/009f.rs index 72cc022..134f0db 100644 --- a/tests/009f.rs +++ b/tests/009f.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: [u8] from "assets/009f.dat"); #[cfg(feature = "deflate")] flate!(pub static DATA2: [u8] from "assets/009f.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: [u8] from "assets/009f.dat" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/009f.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/009f.dat" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify("009f.dat", &DATA1); #[cfg(feature = "deflate")] verify("009f.dat", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify("009f.dat", &DATA3); #[cfg(feature = "deflate")] verify_iflate("009f.dat", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("009f.dat", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/ascii-control.rs b/tests/ascii-control.rs index bbf9b0e..772b595 100644 --- a/tests/ascii-control.rs +++ b/tests/ascii-control.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: str from "assets/ascii-control.txt"); #[cfg(feature = "deflate")] flate!(pub static DATA2: str from "assets/ascii-control.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: str from "assets/ascii-control.txt" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/ascii-control.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/ascii-control.txt" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify_str("ascii-control.txt", &DATA1); #[cfg(feature = "deflate")] verify_str("ascii-control.txt", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_str("ascii-control.txt", &DATA3); #[cfg(feature = "deflate")] verify_iflate("ascii-control.txt", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("ascii-control.txt", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/ascii-printable.rs b/tests/ascii-printable.rs index db46312..f8a6500 100644 --- a/tests/ascii-printable.rs +++ b/tests/ascii-printable.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: str from "assets/ascii-printable.txt"); #[cfg(feature = "deflate")] flate!(pub static DATA2: str from "assets/ascii-printable.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: str from "assets/ascii-printable.txt" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/ascii-printable.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/ascii-printable.txt" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify_str("ascii-printable.txt", &DATA1); #[cfg(feature = "deflate")] verify_str("ascii-printable.txt", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_str("ascii-printable.txt", &DATA3); #[cfg(feature = "deflate")] verify_iflate("ascii-printable.txt", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("ascii-printable.txt", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/base64.rs b/tests/base64.rs index 5171c3f..41e62b5 100644 --- a/tests/base64.rs +++ b/tests/base64.rs @@ -23,11 +23,11 @@ pub static DATA_RAW: &[u8] = flate!(pub static DATA1: str from "assets/base64.txt"); #[cfg(feature = "deflate")] flate!(pub static DATA2: str from "assets/base64.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: str from "assets/base64.txt" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/base64.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/base64.txt" with zstd); #[test] @@ -35,10 +35,10 @@ fn test() { verify_str("base64.txt", &DATA1); #[cfg(feature = "deflate")] verify_str("base64.txt", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_str("base64.txt", &DATA3); #[cfg(feature = "deflate")] verify_iflate("base64.txt", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("base64.txt", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/chinese.rs b/tests/chinese.rs index a092f05..5afa30e 100644 --- a/tests/chinese.rs +++ b/tests/chinese.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: str from "assets/chinese.txt"); #[cfg(feature = "deflate")] flate!(pub static DATA2: str from "assets/chinese.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: str from "assets/chinese.txt" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/chinese.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/chinese.txt" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify_str("chinese.txt", &DATA1); #[cfg(feature = "deflate")] verify_str("chinese.txt", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_str("chinese.txt", &DATA3); #[cfg(feature = "deflate")] verify_iflate("chinese.txt", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("chinese.txt", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/emoji.rs b/tests/emoji.rs index 24efc71..964879c 100644 --- a/tests/emoji.rs +++ b/tests/emoji.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: str from "assets/emoji.txt"); #[cfg(feature = "deflate")] flate!(pub static DATA2: str from "assets/emoji.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: str from "assets/emoji.txt" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/emoji.txt" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/emoji.txt" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify_str("emoji.txt", &DATA1); #[cfg(feature = "deflate")] verify_str("emoji.txt", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_str("emoji.txt", &DATA3); #[cfg(feature = "deflate")] verify_iflate("emoji.txt", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("emoji.txt", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/ff.rs b/tests/ff.rs index 8bc13e1..e09635f 100644 --- a/tests/ff.rs +++ b/tests/ff.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: [u8] from "assets/ff.dat"); #[cfg(feature = "deflate")] flate!(pub static DATA2: [u8] from "assets/ff.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: [u8] from "assets/ff.dat" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/ff.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/ff.dat" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify("ff.dat", &DATA1); #[cfg(feature = "deflate")] verify("ff.dat", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify("ff.dat", &DATA3); #[cfg(feature = "deflate")] verify_iflate("ff.dat", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("ff.dat", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/random.rs b/tests/random.rs index e1254e0..e89f08d 100644 --- a/tests/random.rs +++ b/tests/random.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: [u8] from "assets/random.dat"); #[cfg(feature = "deflate")] flate!(pub static DATA2: [u8] from "assets/random.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: [u8] from "assets/random.dat" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/random.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/random.dat" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify("random.dat", &DATA1); #[cfg(feature = "deflate")] verify("random.dat", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify("random.dat", &DATA3); #[cfg(feature = "deflate")] verify_iflate("random.dat", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("random.dat", CompressionMethod::Zstd, &DATA5); } diff --git a/tests/zero.rs b/tests/zero.rs index add2ea9..8a3eff0 100644 --- a/tests/zero.rs +++ b/tests/zero.rs @@ -20,11 +20,11 @@ use include_flate::flate; flate!(pub static DATA1: [u8] from "assets/zero.dat"); #[cfg(feature = "deflate")] flate!(pub static DATA2: [u8] from "assets/zero.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA3: [u8] from "assets/zero.dat" with zstd); #[cfg(feature = "deflate")] flate!(pub static DATA4: IFlate from "assets/zero.dat" with deflate); -#[cfg(feature = "zstd")] +#[cfg(any(feature = "zstd", feature = "zstd-rust"))] flate!(pub static DATA5: IFlate from "assets/zero.dat" with zstd); #[test] @@ -32,10 +32,10 @@ fn test() { verify("zero.dat", &DATA1); #[cfg(feature = "deflate")] verify("zero.dat", &DATA2); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify("zero.dat", &DATA3); #[cfg(feature = "deflate")] verify_iflate("zero.dat", CompressionMethod::Deflate, &DATA4); - #[cfg(feature = "zstd")] + #[cfg(any(feature = "zstd", feature = "zstd-rust"))] verify_iflate("zero.dat", CompressionMethod::Zstd, &DATA5); }