Context
IIUC the zip crate supports using either zopfli or flate2 backend for compressing using the deflate algorithm/format. I assume that only one of those backends is required - I would like to avoid depending on both to minimize binary size, maintenance overhead, etc. The desire to minimize the dependency tree came up when discussing importing the zip crate into the Chromium project here.
Problem
Using the zip crate with only the deflate-flate2 feature enabled leads to build errors.
Repro steps:
$ cargo new zip-test
$ cd zip-test
$ vim Cargo.toml
$ cat Cargo.toml
[package]
name = "zip-test"
version = "0.1.0"
edition = "2024"
[dependencies.zip]
version = "2.6.1"
default-features = false
features = ["deflate-flate2"]
$ cargo build
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `flate2`
--> /usr/local/google/home/lukasza/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/zip-2.6.1/src/write.rs:33:5
|
33 | use flate2::{write::DeflateEncoder, Compression};
| ^^^^^^ use of unresolved module or unlinked crate `flate2`
|
= help: if you wanted to use a crate named `flate2`, use `cargo add flate2` to add it to your `Cargo.toml`
...
Proposed fix
I assume that we just need to explicitly say in zip crate's Cargo.toml that the deflate-flate2 feature depends on the flate2 crate:
$ git diff
diff --git a/Cargo.toml b/Cargo.toml
index fae78e29..ed45ac1b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -73,8 +73,8 @@ aes-crypto = ["aes", "constant_time_eq", "hmac", "pbkdf2", "sha1", "getrandom",
chrono = ["chrono/default"]
_deflate-any = []
_all-features = [] # Detect when --all-features is used
-deflate = ["flate2/rust_backend", "deflate-zopfli", "deflate-flate2"]
-deflate-flate2 = ["_deflate-any"]
+deflate = ["deflate-zopfli", "deflate-flate2"]
+deflate-flate2 = ["_deflate-any", "flate2/rust_backend"]
# DEPRECATED: previously enabled `flate2/miniz_oxide` which is equivalent to `flate2/rust_backend`
deflate-miniz = ["deflate", "deflate-flate2"]
deflate-zlib = ["flate2/zlib", "deflate-flate2"]
I don't understand why the deflate feature transitively enabled both deflate-zopfli and deflate-flate2, but this is somewhat secondary, since I can just use the deflate-flate2 feature explicitly.
Context
IIUC the
zipcrate supports using eitherzopfliorflate2backend for compressing using the deflate algorithm/format. I assume that only one of those backends is required - I would like to avoid depending on both to minimize binary size, maintenance overhead, etc. The desire to minimize the dependency tree came up when discussing importing thezipcrate into the Chromium project here.Problem
Using the
zipcrate with only thedeflate-flate2feature enabled leads to build errors.Repro steps:
Proposed fix
I assume that we just need to explicitly say in
zipcrate'sCargo.tomlthat thedeflate-flate2feature depends on theflate2crate:I don't understand why the
deflatefeature transitively enabled bothdeflate-zopflianddeflate-flate2, but this is somewhat secondary, since I can just use thedeflate-flate2feature explicitly.