frewsxcv / rust-crates-index

Rust library for retrieving and interacting with the crates.io index
https://docs.rs/crates-index/
Apache License 2.0
72 stars 37 forks source link

For 0.20.0: Make git2 dependency optional via new "git-index" feature #107

Closed Enselic closed 1 year ago

Enselic commented 1 year ago

To adapt to the sparse crates.io index, I have stopped using the git index code from crates-index, and only use the Crate code, in particular Crate::from_slice, since that works with the HTTP response of the sparse index:

$ curl https://index.crates.io/ex/am/example_api
{"name":"example_api","vers":"0.1.0","deps":[],"cksum":"d0f99c425515721620183a74993ebb809ca7f06c4e6b09b8c28668d56a2e78fd","features":{},"yanked":false}
{"name":"example_api","vers":"0.1.1","deps":[],"cksum":"3fc31d0e953c46287ea7ddb2f5cd93f0b8eae0ec9777f75569b9d3b7837c14bc","features":{},"yanked":false}
{"name":"example_api","vers":"0.2.0","deps":[],"cksum":"67c4a4db10e5e11217344e754b634eab454ee983a3123c576a2781baefc08bc8","features":{},"yanked":false}
{"name":"example_api","vers":"0.3.0","deps":[],"cksum":"8933479dd187e1d4d7de03e4dfd67e23d3ca494da830d1718710c779b5bd2156","features":{},"yanked":false}
{"name":"example_api","vers":"0.2.1","deps":[],"cksum":"2cb9ebe24cd5cdf18d63dd22cbc85fc6ad94aa10645038e8cfebead34186aaff","features":{"feature":[]},"yanked":false}

This means that I do not need the git2 dep at all. This PR makes the git2 dep of crates-index optional (but default).

In my project this reduces number of deps from 151 to 134 and reduces release build time from 260s to 190s, so the gain is quite substantial.

To reduce the number of #[cfg(feature = "git-index")] I had to add, I had to move the code around a bit, but not in a way that changes the public API:

$ cargo install cargo-public-api --locked
$ cargo public-api diff origin/master..optional-git-index
Removed items from the public API
=================================
(none)

Changed items in the public API
===============================
(none)

Added items to the public API
=============================
(none)

Related: #87

kornelski commented 1 year ago

I know git2 is a big fat dependency. However, this is a semver-breaking change (when used with default-features=false the functionality changes), and for now I don't want to cause churn.

Enselic commented 1 year ago

Understandable. But yes, git2 a heavy dep, and it would be nice to be able to avoid it when not needed, even in the 0.19.x series.

How about making getting rid of git2 opt-in then to avoid semver problems? In other words, we can introduce a "no-git-index" feature. Then in 0.20.0 we can turn it back into being opt-out and called "git-index".

Enselic commented 1 year ago

Silly me, enabling a feature can't result in the removal of a dependency.

Can we keep this PR open until it is time to bump to 0.20.0 so we don't forget about it? Please ping me then, and I'll rebase this PR on top of master. Thanks!