Skip to content

Commit e4ccc1c

Browse files
committed
Switch to zlib-rs by default and drop other zlib backends
As of zlib-rs 0.5.0 (depended on by flate2 1.1.1), zlib-rs no longer exports C symbols by default, so it doesn't conflict with any other zlib that might be loaded into the address space. This removed the primary issue that made zlib selection a challenge that needed to be exposed to users: users may already have some other particular preference on zlib implementations, or want to use a system library, or want to ensure C dependencies use a particular zlib. Since zlib-rs 0.5.0 no longer conflicts with other zlib implementations, gix can make this choice independently and not create issues for the user. Given that, use zlib-rs by default, for performance out of the box with no C compiler requirement, and deprecate all the feature flags for other variations. A future major version bump can drop all of these features. This also means that (for instance) max-performance becomes the same as max-performance-safe, so such features are deprecated as well. Depend on flate2 with `default-features = false`, which brings us closer to eliminating the `miniz_oxide` dependency, which will improve build time for everyone. Currently, the `gix-archive` dependency on `zip` still activates the `zip/deflate` feature which enables `flate2/rust_backend`; this can be fixed to use `deflate-flate2` as soon as zip-rs/zip2#340 is fixed upstream. Fixes: #1961
1 parent f3684a4 commit e4ccc1c

File tree

11 files changed

+52
-142
lines changed

11 files changed

+52
-142
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ jobs:
402402
- name: features of gix-features
403403
run: |
404404
set +x
405-
for feature in progress parallel io-pipe crc32 zlib zlib-rust-backend cache-efficiency-debug; do
405+
for feature in progress parallel io-pipe crc32 zlib cache-efficiency-debug; do
406406
(cd gix-features && cargo build --features "$feature" --target "$TARGET")
407407
done
408408
- name: crates with 'wasm' feature

.github/workflows/release.yml

-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ jobs:
231231
- name: Install packages (Ubuntu)
232232
# Because openssl doesn't work on musl by default, we resort to max-pure.
233233
# And that won't need any dependency, so we can skip this or use `continue-on-error`.
234-
# Once we want to support better zlib performance, we might have to re-add it.
235234
if: matrix.os == 'ubuntu-latest-disabled'
236235
run: |
237236
sudo apt-get update
@@ -541,8 +540,6 @@ jobs:
541540
msystem: MINGW${{ startsWith(matrix.target, 'i686-') && '32' || '64' }}
542541
pacboy: cc:p
543542
path-type: inherit
544-
- name: Install prerequisites
545-
run: vcpkg install zlib:x64-windows-static-md
546543
- name: 'Installation from crates.io: gitoxide'
547544
run: cargo +${{ matrix.rust }} install --target ${{ matrix.target }} --no-default-features --features max-pure --target-dir install-artifacts --debug --force gitoxide
548545
shell: msys2 {0}

Cargo.lock

-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12-28
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ max = ["max-control", "fast", "gitoxide-core-tools-query", "gitoxide-core-tools-
4141

4242
## Like `max`, but only Rust is allowed.
4343
##
44-
## This is the most compatible build as it won't need a C compiler or C toolchains to build. It's also not the fastest as or the most feature-rich in terms of available
45-
## transports as it uses Rust's HTTP implementation.
44+
## This is the most compatible build as it won't need a C compiler or C toolchains to build. Thanks to zlib-rs, you don't have to trade off between compatibility and performance.
45+
##
46+
## This uses Rust's HTTP implementation.
4647
##
4748
## As fast as possible, with TUI progress, progress line rendering with auto-configuration, all transports available but less mature pure Rust HTTP implementation, all `ein` tools, CLI colors and local-time support, JSON output, regex support for rev-specs.
48-
max-pure = ["max-control", "gix-features/zlib-rust-backend", "http-client-reqwest", "gitoxide-core-blocking-client"]
49+
max-pure = ["max-control", "http-client-reqwest", "gitoxide-core-blocking-client"]
4950

5051
## Like `max`, but with more control for configuration. See the *Package Maintainers* headline for more information.
51-
max-control = ["tracing", "fast-safe", "pretty-cli", "gitoxide-core-tools", "prodash-render-line", "prodash-render-tui", "prodash/render-line-autoconfigure", "gix/revparse-regex"]
52+
max-control = ["tracing", "fast", "pretty-cli", "gitoxide-core-tools", "prodash-render-line", "prodash-render-tui", "prodash/render-line-autoconfigure", "gix/revparse-regex"]
5253

5354
## All the good stuff, with less fanciness for smaller binaries.
5455
##
@@ -60,7 +61,7 @@ lean = ["fast", "tracing", "pretty-cli", "http-client-curl", "gitoxide-core-tool
6061
## This build is essentially limited to local operations without any fanciness.
6162
##
6263
## Optimized for size, no parallelism thus much slower, progress line rendering.
63-
small = ["pretty-cli", "gix-features/zlib-rust-backend", "prodash-render-line", "is-terminal"]
64+
small = ["pretty-cli", "prodash-render-line", "is-terminal"]
6465

6566
## Like lean, but uses Rusts async implementations for networking.
6667
##
@@ -74,37 +75,20 @@ small = ["pretty-cli", "gix-features/zlib-rust-backend", "prodash-render-line",
7475
lean-async = ["fast", "tracing", "pretty-cli", "gitoxide-core-tools", "gitoxide-core-tools-query", "gitoxide-core-tools-corpus", "gitoxide-core-async-client", "prodash-render-line"]
7576

7677
#! ### Package Maintainers
77-
#! `*-control` features leave it to you to configure C libraries, involving choices for `zlib` and transport implementation.
78+
#! `*-control` features leave it to you to configure C libraries, involving choices for HTTP transport implementation.
7879
#!
7980
#! Additional features *can* be provided with `--features` and are handled by the [`gix-features` crate](https://docs.rs/gix-features/latest).
80-
#! If nothing else is specified, the Rust implementation is used. ! Note that only one feature of each section can be enabled at a time.
81-
#!
82-
#! * **zlib**
83-
#! - `gix-features/zlib-ng`
84-
#! - `gix-features/zlib-ng-compat`
85-
#! - `gix-features/zlib-stock`
86-
#! - `gix-features/zlib-rust-backend` (*default if no choice is made*)
87-
#! * **HTTP** - see the *Building Blocks for mutually exclusive networking* headline
88-
#!
89-
#! #### Examples
90-
#!
91-
#! * `cargo build --release --no-default-features --features max-control,gix-features/zlib-stock,gitoxide-core-blocking-client,http-client-curl`
92-
#! - Create a build just like `max`, but using the stock `zlib` library instead of `zlib-ng`
93-
#! * `cargo build --release --no-default-features --features max-control,http-client-reqwest,gitoxide-core-blocking-client,gix-features/zlib-ng`
94-
#! - Create a build just like `max-pure`, but with faster compression due to `zlib-ng`.
81+
#! Note that only one HTTP transport can be enabled at a time. See the *Building Blocks for mutually exclusive networking* headline.
9582

9683
#! ### Building Blocks
9784
#! Typical combinations of features of our dependencies, some of which are referred to in the `gitoxide` crate's code for conditional compilation.
9885

99-
## Makes the crate execute as fast as possible by supporting parallel computation of otherwise long-running functions
100-
## as well as a faster zlib backend.
86+
## Makes the crate execute as fast as possible by supporting parallel computation of otherwise long-running functions.
10187
## If disabled, the binary will be visibly smaller.
10288
fast = ["gix/max-performance", "gix/comfort"]
10389

104-
## Makes the crate execute as fast as possible by supporting parallel computation of otherwise long-running functions
105-
## as well as a faster zlib backend.
106-
## If disabled, the binary will be visibly smaller.
107-
fast-safe = ["gix/max-performance-safe", "gix/comfort"]
90+
## Deprecated: identical to `fast`, as the fastest zlib backend is now the pure-Rust zlib-rs.
91+
fast-safe = ["fast"]
10892

10993
## Enable tracing in `gitoxide-core`.
11094
tracing = ["dep:tracing-forest", "dep:tracing-subscriber", "dep:tracing", "gix-features/tracing", "gix-features/tracing-detail"]
@@ -201,8 +185,8 @@ gix-ref = { opt-level = 3 }
201185
gix-hash = { opt-level = 3 }
202186
gix-actor = { opt-level = 3 }
203187
gix-config = { opt-level = 3 }
204-
miniz_oxide = { opt-level = 3 }
205188
sha1-checked = { opt-level = 3 }
189+
zlib-rs = { opt-level = 3 }
206190

207191
[profile.release]
208192
overflow-checks = false

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ Please take a look at the [`SHORTCOMINGS.md` file](https://github.com/GitoxideLa
418418

419419
* **itertools** _(MIT Licensed)_
420420
* We use the `izip!` macro in code
421-
* **deflate2** _(MIT Licensed)_
422-
* We use various abstractions to implement decompression and compression directly on top of the rather low-level `miniz_oxide` crate
421+
* **flate2** _(MIT Licensed)_
422+
* We use the high-level `flate2` library to implement decompression and compression, which builds on the high-performance `zlib-rs` crate.
423423

424424
## 🙏 Special Thanks 🙏
425425

etc/docker/Dockerfile.alpine

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ ARG GITOXIDE_VERSION=0.36.0
44
FROM rust:alpine AS bootstrap_os
55
# hadolint ignore=DL3018
66
RUN apk upgrade --update-cache --available \
7-
&& apk add --no-cache --virtual .runtime-gitoxide libressl zlib-ng \
8-
libressl3.8-libcrypto
7+
&& apk add --no-cache --virtual .runtime-gitoxide libressl libressl3.8-libcrypto
98

109

1110
FROM bootstrap_os AS bootstrap_build_deps
1211
# hadolint ignore=DL3018
1312
RUN apk add --no-cache --virtual .rust-builder cmake gcc musl-dev make pkgconfig \
14-
&& apk add --no-cache --virtual .bootstrap-gitoxide libressl-dev zlib-ng \
15-
libressl3.8-libcrypto
13+
&& apk add --no-cache --virtual .bootstrap-gitoxide libressl-dev libressl3.8-libcrypto
1614

1715

1816
FROM bootstrap_build_deps AS bootstrap_builder

gix-archive/Cargo.toml

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ tar = ["dep:tar", "dep:gix-path"]
2323
tar_gz = ["tar", "dep:flate2"]
2424

2525
## Enable the `zip` archive format.
26-
zip = ["dep:zip"]
26+
## This also enables the `flate2` dependency in order to enable `zlib-rs` on it.
27+
zip = ["dep:flate2", "dep:zip"]
2728

2829

2930
[dependencies]
@@ -32,10 +33,8 @@ gix-object = { version = "^0.48.0", path = "../gix-object" }
3233
gix-path = { version = "^0.10.15", path = "../gix-path", optional = true }
3334
gix-date = { version = "^0.9.4", path = "../gix-date" }
3435

35-
flate2 = { version = "1.1.1", optional = true }
36-
zip = { version = "2.6.1", optional = true, default-features = false, features = [
37-
"deflate",
38-
] }
36+
flate2 = { version = "1.1.1", optional = true, default-features = false, features = ["zlib-rs"] }
37+
zip = { version = "2.6.1", optional = true, default-features = false, features = ["deflate"] }
3938
jiff = { version = "0.2.6", default-features = false, features = ["std"] }
4039

4140
thiserror = "2.0.0"

gix-features/Cargo.toml

+18-25
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,23 @@ io-pipe = ["dep:bytes"]
5454
## provide a proven and fast `crc32` implementation.
5555
crc32 = ["dep:crc32fast"]
5656

57-
#! ### Mutually Exclusive ZLIB
58-
59-
## Enable the usage of zlib related utilities to compress or decompress data.
60-
## The base `zlib` feature uses the `flate2` Rust crate; the other mutually exclusive features select the `flate2 backend.
61-
## Note that a competitive Zlib implementation is critical to `gitoxide's` object database performance.
62-
## Enabling this without enabling one of the other features below will use a low-performance pure-Rust backend.
63-
zlib = ["dep:flate2", "flate2?/rust_backend", "dep:thiserror"]
64-
## Use the C-based zlib-ng backend, which can compress and decompress significantly faster.
65-
zlib-ng = ["zlib", "flate2?/zlib-ng"]
66-
## Use the high-performance rust-based zlib backend on par with zlib-ng.
67-
## As of zlib-rs 0.5.0 (used by flate2 1.1.1), this no longer exports C symbols
68-
## by default, so it doesn't conflict with any other zlib library that might be
69-
## loaded into the same address space.
70-
zlib-rs = ["zlib", "flate2?/zlib-rs"]
71-
## Use zlib-ng via its zlib-compat API. Useful if you already need zlib for C
72-
## code elsewhere in your dependencies. Otherwise, use zlib-ng.
73-
zlib-ng-compat = ["zlib", "flate2?/zlib-ng-compat"]
74-
## Use a slower C-based backend which can compress and decompress significantly faster than the rust version.
75-
## Unlike `zlib-ng-compat`, this allows using dynamic linking with system `zlib` libraries and doesn't require cmake.
76-
zlib-stock = ["zlib", "flate2?/zlib"]
77-
## Pure Rust backend, available for completeness even though it's the default
78-
## if neither of the above options are set. Low performance, but pure Rust, so it
79-
## may build in environments where other backends don't.
80-
zlib-rust-backend = ["zlib", "flate2?/rust_backend"]
57+
## Enable the usage of zlib-related utilities to compress or decompress data.
58+
## This enables the `flate2` crate, and always uses the high-performance `zlib-rs` backend.
59+
## Note that the various past features for selecting zlib backends are now deprecated and do nothing.
60+
zlib = ["dep:flate2", "dep:thiserror"]
61+
## Deprecated: gix always uses zlib-rs.
62+
zlib-ng = ["zlib"]
63+
## Deprecated: gix always uses zlib-rs now. As of zlib-rs 0.5.0 (used by flate2
64+
## 1.1.1), this no longer exports C symbols # by default, so it doesn't
65+
## conflict with any other zlib library that might be loaded into the same
66+
## address space.
67+
zlib-rs = ["zlib"]
68+
## Deprecated: gix always uses zlib-rs.
69+
zlib-ng-compat = ["zlib"]
70+
## Deprecated: gix always uses zlib-rs.
71+
zlib-stock = ["zlib"]
72+
## Deprecated: gix always uses zlib-rs.
73+
zlib-rust-backend = ["zlib"]
8174

8275
#! ### Other
8376

@@ -128,7 +121,7 @@ bytesize = { version = "2.0.1", optional = true }
128121
bytes = { version = "1.0.0", optional = true }
129122

130123
# zlib module
131-
flate2 = { version = "1.1.1", optional = true, default-features = false }
124+
flate2 = { version = "1.1.1", optional = true, default-features = false, features = ["zlib-rs"] }
132125
thiserror = { version = "2.0.0", optional = true }
133126

134127
once_cell = { version = "1.21.3", optional = true }

gix/Cargo.toml

+12-20
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,11 @@ blocking-http-transport-reqwest-native-tls = [
220220
#! ZIP might not compile on all platforms, so it depends on the end-user who compiles the application to chose these based on their needs.
221221

222222
## Activate features that maximize performance, like using threads, but leave everything else that might affect compatibility out to allow users more fine-grained
223-
## control over performance features like which `zlib*` implementation to use.
223+
## control.
224224
## No C toolchain is involved.
225225
max-control = ["parallel", "pack-cache-lru-static", "pack-cache-lru-dynamic"]
226226

227-
## Activate features that maximize performance, like usage of threads, `and access to caching in object databases, skipping the ones known to cause compile failures
228-
## on some platforms.
229-
## Note that this configuration still uses a pure Rust zlib implementation which isn't the fastest compared to its C-alternatives.
230-
## No C toolchain is involved.
227+
## Deprecated: gix always uses zlib-rs, so this is equivalent to `max-performance`
231228
max-performance-safe = ["max-control"]
232229

233230
## The tempfile registry uses a better implementation of a thread-safe hashmap, relying on an external crate.
@@ -247,25 +244,20 @@ pack-cache-lru-static = ["gix-pack/pack-cache-lru-static"]
247244
## Provide a hash-map based LRU cache whose eviction is based a memory cap calculated from object data.
248245
pack-cache-lru-dynamic = ["gix-pack/pack-cache-lru-dynamic"]
249246

250-
## Activate other features that maximize performance, like usage of threads, `zlib-ng` and access to caching in object databases.
251-
## Note that some platforms might suffer from compile failures, which is when `max-performance-safe` should be used.
252-
max-performance = ["max-performance-safe", "zlib-ng"]
247+
## Enable all features required for performance. Currently, this is equivalent to `max-control`, as gix always uses zlib-rs.
248+
max-performance = ["max-control"]
253249

254-
## Use the C-based zlib-ng backend, which can compress and decompress significantly faster.
255-
## Note that this will cause duplicate symbol errors if the application also depends on `zlib` - use `zlib-ng-compat` in that case.
256-
zlib-ng = ["gix-features/zlib-ng"]
250+
## Deprecated: gix always uses zlib-rs.
251+
zlib-ng = ["gix-features/zlib"]
257252

258-
## Use the high-performance rust-based zlib backend en par with zlib-ng.
259-
## Note that this will cause duplicate symbol errors if the application also depends on `zlib`, without remedy.
260-
zlib-rs = ["gix-features/zlib-rs"]
253+
## Deprecated: gix always uses zlib-rs.
254+
zlib-rs = ["gix-features/zlib"]
261255

262-
## Use zlib-ng via its zlib-compat API. Useful if you already need zlib for C
263-
## code elsewhere in your dependencies. Otherwise, use `zlib-ng`.
264-
zlib-ng-compat = ["gix-features/zlib-ng-compat"]
256+
## Deprecated: gix always uses zlib-rs.
257+
zlib-ng-compat = ["gix-features/zlib"]
265258

266-
## Use a slower C-based backend which can compress and decompress significantly faster than the rust version.
267-
## Unlike `zlib-ng-compat`, this allows using dynamic linking with system `zlib` libraries and doesn't require cmake.
268-
zlib-stock = ["gix-features/zlib-stock"]
259+
## Deprecated: gix always uses zlib-rs.
260+
zlib-stock = ["gix-features/zlib"]
269261

270262
#! #### Other
271263
#!

justfile

-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ check:
103103
cargo check -p gix-features --features io-pipe
104104
cargo check -p gix-features --features crc32
105105
cargo check -p gix-features --features zlib
106-
cargo check -p gix-features --features zlib,zlib-ng
107-
cargo check -p gix-features --features zlib,zlib-ng-compat
108-
cargo check -p gix-features --features zlib-stock
109-
cargo check -p gix-features --features zlib,zlib-stock
110106
cargo check -p gix-features --features cache-efficiency-debug
111107
cd gix-commitgraph; \
112108
set -ex; \

tests/journey/gix.sh

+1-8
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,8 @@ title "gix commit-graph"
551551
expect_run $WITH_FAILURE test -e "${PACK_FILE}".idx
552552
}
553553

554-
if test "$kind" = "small" ; then
555-
suffix=miniz-oxide
556-
elif test "$kind" = "max-pure"; then
557-
suffix=miniz-oxide-max
558-
else
559-
suffix=zlib-ng
560-
fi
561554
it "creates all pack objects, but the broken ones" && {
562-
WITH_SNAPSHOT="$snapshot/broken-with-objects-dir-skip-checks-success-tree-$suffix" \
555+
WITH_SNAPSHOT="$snapshot/broken-with-objects-dir-skip-checks-success-tree" \
563556
expect_run_sh $SUCCESSFULLY 'find . -type f | sort'
564557
}
565558
)

0 commit comments

Comments
 (0)