Open bnjbvr opened 2 years ago
I applied it in a really large cargo workspace in our private repository and it detected like really many unused crates for us! Our workspace is around 122 crates, and we managed to remove ~187 unused dependencies :tada:!
However, the number of false positives was ~67.
The main problem is that we use a lot of code included from OUT_DIR
, which isn't analyzed.
Also, cargo-machete --with-metadata
doesn't analyze build.rs
tests and other rust files from examples/
directory (also, I am not sure but maybe benches/
directory is not analyzed either?) for some reason (is it broken?)
Also, looks like pub use ::crate_name
reference doesn't seem to be picked up by cargo-machete
✨ https://github.com/godot-rust/godot-rust/pull/890 (revision 84c99b1
)
Also, looks like pub use ::crate_name reference doesn't seem to be picked up by cargo-machete
Ah, looks like an oversight, will add a test and support for that, thanks!
I've used cargo-machete
alongside cargo-udeps
to quickly find and remove unneeded dependencies after splitting one crate into multiple crates. I had to manually add some exceptions for dependencies of code generated through build scripts as well but other than that worked great.
https://github.com/risingwavelabs/risingwave/pull/7816 It helped a lot! Thanks for the great tool. Tens of udeps are removed.
The commit history in this PR also shows how I used it and the problems I met:
workspace-hack
(managed by cargo hakari
), so I added the ignore to every Cargo.toml
. It might be better to have a global config file, e.g., .config/machete.toml
num_trails
and serde
.[target.'cfg(target_os = "linux")'.dependencies]
Also, cargo-machete --with-metadata
reports something like error: current package believes it's in a workspace when it's not
. It may be because we wrongly configured some crates, but I didn't bother to fix it. Fortunately it turns out there aren't many false-postives.
I'm facing difficulties while trying to install cargo-udeps
, as it seems to depend on libssl.so.1.1
. I've already installed several SSL-related dependencies on both Ubuntu 22.04 and Debian 12, but I haven't been successful so far.
As a last resort, I'm considering installing libssl.so.1.1
on an Arch container using Distrobox. However, I'm also open to exploring alternatives. Surprisingly, cargo-machete
managed to find what cargo-udeps
couldn't. 🏆
monorepo-services/alibaba on alibaba/refactor [!?] is 📦 v0.4.0 via 🦀 v1.71.0
# `cargo-udeps`
Checking hyosho v0.4.0 (/home/user/projects/monorepo-services/alibaba)
Finished dev [unoptimized + debuginfo] target(s) in 1.63s
info: Loading depinfo from "/home/user/projects/monorepo-services/alibaba/target/debug/deps/hyosho-14768cb6b
da7830f.d"
info: Loading depinfo from "/home/user/projects/monorepo-services/alibaba/target/debug/deps/hyosho-bc29a72ec
262bf2e.d"
All deps seem to have been used.
# `cargo-machete`
Analyzing dependencies of crates in this directory...
cargo-machete found the following unused dependencies in /home/user/projects/monorepo-services/alibaba:
hyosho -- /home/user/projects/monorepo-services/alibaba/Cargo.toml:
rand
url
Done!
A colleague used cargo machete
to remove dozens of unused dependencies from our project
https://github.com/dfinity/ic/commit/a3b6bebfe3ba5c296f964d51c771113fff47f575
Thank you!!
No public code to show off but cargo machete
worked like a charm and managed to find 2 unused deps (including one on an internal crate) which let me remove a build-script, always nice for small compile times wins 🎉
I finished cleaning up Zed - https://github.com/zed-industries/zed/pull/8468
In a series of 4 PR, around 600 LOC were removed from Cargo.lock
with many unused dependencies.
In the meantime,
And cargo-udeps shows me that All deps seem to have been used., now I'm convinced to remove it.
I has been useful, yes: https://github.com/ruffle-rs/ruffle/pull/15774 :)
Been using cargo machete for https://github.com/IgnisDa/ryot for over a year. Really useful tool.
Also love the name!
If
cargo-machete
has been useful for you and has helped removing dependencies in your project, feel free to add a comment to this issue :)