How can I get rid of vendored dependencies I am never going to use?

Consider the following cargo vendor output, which stems from a project whose sole dependencies are the windows crate and std:

$ cargo vendor
   Vendoring proc-macro2 v1.0.81 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\proc-macro2-1.0.81) to vendor\proc-macro2
   Vendoring quote v1.0.36 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\quote-1.0.36) to vendor\quote
   Vendoring syn v2.0.59 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\syn-2.0.59) to vendor\syn
   Vendoring unicode-ident v1.0.12 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\unicode-ident-1.0.12) to vendor\unicode-ident
   Vendoring windows v0.56.0 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.56.0) to vendor\windows
   Vendoring windows-core v0.56.0 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-core-0.56.0) to vendor\windows-core
   Vendoring windows-implement v0.56.0 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-implement-0.56.0) to vendor\windows-implement
   Vendoring windows-interface v0.56.0 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-interface-0.56.0) to vendor\windows-interface
   Vendoring windows-result v0.1.1 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-result-0.1.1) to vendor\windows-result
   Vendoring windows-targets v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-targets-0.52.5) to vendor\windows-targets
   Vendoring windows_aarch64_gnullvm v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_aarch64_gnullvm-0.52.5) to vendor\windows_aarch64_gnullvm
   Vendoring windows_aarch64_msvc v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_aarch64_msvc-0.52.5) to vendor\windows_aarch64_msvc
   Vendoring windows_i686_gnu v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_i686_gnu-0.52.5) to vendor\windows_i686_gnu
   Vendoring windows_i686_gnullvm v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_i686_gnullvm-0.52.5) to vendor\windows_i686_gnullvm
   Vendoring windows_i686_msvc v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_i686_msvc-0.52.5) to vendor\windows_i686_msvc
   Vendoring windows_x86_64_gnu v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_gnu-0.52.5) to vendor\windows_x86_64_gnu
   Vendoring windows_x86_64_gnullvm v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_gnullvm-0.52.5) to vendor\windows_x86_64_gnullvm
   Vendoring windows_x86_64_msvc v0.52.5 (C:\Users\username\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_msvc-0.52.5) to vendor\windows_x86_64_msvc

(I removed the hint about .cargo/config.toml at the bottom for brevity.)

The following vendored dependencies strike me as odd:

windows_aarch64_gnullvm
windows_aarch64_msvc
windows_i686_gnu
windows_i686_gnullvm
windows_i686_msvc
windows_x86_64_gnu
windows_x86_64_gnullvm
windows_x86_64_msvc

Suppose I was only ever going to use the stable-x86_64-pc-windows-msvc toolchain, couldn't I (and wouldn't I want to) get rid of everything other than windows_x86_64_msvc?

Or if I knew that I'll never build for 32-bit x86, couldn't I get rid of all the windows_i686_* items?

How would I go about it to get rid of those items that I know I won't ever use?

Thanks!

You just delete them. cargo vendor doesn't know which optional dependencies you need now or in the future. Its goal is to vendor everything that your project depends on, in case any dependencies become unavailable later. This includes optional dependencies for different platforms and targets.

3 Likes

Oh, I see. So this is not expressed in Cargo.toml or .cargo/config.toml but rather pruned by the developer. Thank you!

I'm not aware of any more advanced configuration options. In any case, cargo vendor isn't something you run often, so imho advanced configuration would just complicate it. One thing I'm personally missing is the ability to vendor just a single crate, in case I want to make a local patch.

2 Likes

You might like GitHub - coreos/cargo-vendor-filterer: Tool to `cargo vendor` with filtering

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.