-
-
Notifications
You must be signed in to change notification settings - Fork 355
Add new feature zlib-rs #1873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new feature zlib-rs #1873
Conversation
438f5bf
to
34889b9
Compare
I need some help with the windows CI, not sure why it's pulling libz-sys and libz-ng-sys when it already has libz-rs Other CIs, except for MSRV, are not related to this PR |
Tried checking using I have no clue what's going on here |
cc @Byron I might need some help from you, since you also maintain flate2 |
This would be great for Jujutsu. We’ve held off on defaulting to I’m not sure what’s up with Windows, but it looks kind of like both the I think the Please let us know what we can do to help move this along, @Byron :) |
@@ -67,6 +66,8 @@ crc32 = ["dep:crc32fast"] | |||
zlib = ["dep:flate2", "flate2?/rust_backend", "dep:thiserror"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be turning on rust_backend
when using zlib-rs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rust_backend is another pure rust implementation that is much much slower than other backend, AFAIK it's only there as a fallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but the zlib-rs
feature pulls in the zlib
feature, and enables the other Rust backend, which we probably don’t want? I’m wondering if that might somehow be part of the CI problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this happen, and apologies for the late response.
I am still catching up with what accumulated over just 7 days, it's going to be a while.
Meantime, I think this PR needs changes, but nothing huge or in the way of a merge.
Unfortunately, I also don't know why 32bit ARM and Windows suffer from duplicate definitions. There is this one issue of the same happening on Linux, but there it seems to be about pulling in multiple versions of libz-sys
.
To get this PR going, I think the default performance backend should remain zlib-ng
, but jj
for instance could configure their unix builds to use zlib-rs
more easily in future.
@emilazy is cordially invited to help shape this PR so gitoxide
would work better for jj
.
What do you think?
gix-archive/Cargo.toml
Outdated
@@ -32,7 +32,7 @@ gix-object = { version = "^0.47.0", path = "../gix-object" } | |||
gix-path = { version = "^0.10.14", path = "../gix-path", optional = true } | |||
gix-date = { version = "^0.9.3", path = "../gix-date" } | |||
|
|||
flate2 = { version = "1.0.33", optional = true } | |||
flate2 = { version = "1.0.33", optional = true, default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that default-features
is a problem - these, i.e. the rust-backend
are superseded by any other choice.
@@ -67,6 +66,8 @@ crc32 = ["dep:crc32fast"] | |||
zlib = ["dep:flate2", "flate2?/rust_backend", "dep:thiserror"] | |||
## Use the C-based zlib-ng backend, which can compress and decompress significantly faster. | |||
zlib-ng = ["zlib", "flate2?/zlib-ng"] | |||
## Use the rust-based zlib backend, which can compress and decompress significantly faster and is on par with zlib-ng or even faster. | |||
zlib-rs = ["zlib", "flate2?/zlib-rs"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great to see this here!
gix/Cargo.toml
Outdated
## Note that some platforms might suffer from compile failures, which is when `max-performance-safe` should be used. | ||
max-performance = ["max-performance-safe", "zlib-ng", "fast-sha1"] | ||
max-performance = ["max-performance-safe", "zlib-rs", "fast-sha1"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to push my luck 😅, and would prefer to start by merely making the use of zlib-rs
easy with the provided feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe another feature then?
Yeah that seems fine, cargo-binstall could enable the feature separately.
In cargo-binstall we want to get rids of zlib-ng as we already pulled in zlib-rs, having zlib-ng actually makes cross compilation harder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Byron reverted this change
I agree that this is the conservative choice. However, in the future, I’d hope that |
And there even is a test for that, so it should be straightforward to validate that indeed no C-compiler is needed anymore. Also, I'd be happy to reach that goal, and if it can be achieved earlier, that's better, too. For now it seems the easiest way to pacify CI is to undo the default backend change. This buys time for figuring out what's actually going on there. My thinking is that ideally, |
I believe the problem is this
I suspect that is hard to work around (though using We do want to provide a nice rust interface. The brave rustls folks already use our rust interface, but we basically break it on every release, so it's not something I'd recommend. As it stands, creating a good rust interface would require some funding. |
Thanks for chiming in! This would mean |
Also bump flate2 to 1.1.0 to make sure it support zlib-rs Signed-off-by: Jiahao XU <[email protected]>
@Byron I'm the person at Trifecta Tech Foundation (where zlib-rs lives) blessed with fundraising duties. So far, funding zlib-rs has been difficult and only partly successful because |
- adjust feature docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, it's ready to go now!
@erikjee Will you be at RustWeek, because I am considering to go. If I go, I think with the right amount of support ("You can do it" [patting shoulder]) I could finally go through with the application for gitoxide
and just get it done while there. Applications might be closed already, but I'd hope they reopen in a couple of months.
Strangely, despite being in a good spot, the more successful gitoxide
is, the less time I have to actually work on it, and funded outside help could definitely fix that. And yes, why not make zlib-rs
a sub-project of that application.
I'm one of the organizers :) So, yes! |
Just a thought, but maybe you could provide a Rust API that is 1:1 with the C API first? That is, define the C API with non- |
I think this is the status quo? |
No, we don't do this part
That's an interesting idea, I'll have to think on that a bit |
Not quite. If you look at https://docs.rs/libz-rs-sys/latest/libz_rs_sys/fn.deflate.html, it’s pub unsafe fn deflate(strm: *mut z_stream, flush: i32) -> c_int {
…
}
#[cfg(feature = "c-api")]
#[export_name = "deflate"]
pub unsafe extern "C-unwind" fn export_deflate(strm: *mut z_stream, flush: i32) -> c_int {
deflate(strm, flush)
} (Actually I guess this very slightly changes semantics, because |
Hmm, actually it looks like there’s already a |
we've added a |
https://github.com/trifectatechfoundation/zlib-rs?tab=readme-ov-file#performance
zlib-rs is generally on par with zlib-ng and on sometimes faster https://trifectatech.org/blog/zlib-rs-is-faster-than-c/