Unlike most other cargo tools, cargo metadata counter-intuitively defaults to downloading all dependencies for all targets unless the argument --filter-platform is passed. This means that with the current logic, cbindgen ends up downloading potentially a very large number of dependencies whenever this is invoked:
https://github.com/eqrion/cbindgen/blob/93eed3aaf3a6ed94ae5bdf59e5df4c508fe05a5b/src/bindgen/cargo/cargo_metadata.rs#L189-L194
Since cbindgen doesn't actually need the dependencies themselves (I don't think), I believe cbindgen should probably always specify --filter-platform, and just specify the host platform. Cargo finds the host platform by running rustc -Vv and extracing the host: line, which cbindgen could probably also do pretty easily:
https://github.com/rust-lang/cargo/blob/fde8ee3ba0cba4eef75f197d42586ef4664f057b/src/cargo/util/rustc.rs#L48-L68
This is also what rust-analyzer recently switch to doing: rust-lang/rust-analyzer#6912
There's also precedent for relying on rustc to determine these kinds of things, such as using it to find the sysroot:
https://github.com/rust-analyzer/rust-analyzer/blob/48802e54d1669c68fd27b007533dd6aa5221d089/crates/project_model/src/sysroot.rs#L126-L127
One way to make this nicer would be if cargo metadata supported a "special" value for --filter-platform called host. I'll look at submitting that as a PR upstream, but the more immediate fix (and also one that would continue to work for older compiler releases) would be to just use rustc -Vv.
Unlike most other cargo tools,
cargo metadatacounter-intuitively defaults to downloading all dependencies for all targets unless the argument--filter-platformis passed. This means that with the current logic,cbindgenends up downloading potentially a very large number of dependencies whenever this is invoked:https://github.com/eqrion/cbindgen/blob/93eed3aaf3a6ed94ae5bdf59e5df4c508fe05a5b/src/bindgen/cargo/cargo_metadata.rs#L189-L194
Since
cbindgendoesn't actually need the dependencies themselves (I don't think), I believecbindgenshould probably always specify--filter-platform, and just specify the host platform. Cargo finds the host platform by runningrustc -Vvand extracing thehost:line, whichcbindgencould probably also do pretty easily:https://github.com/rust-lang/cargo/blob/fde8ee3ba0cba4eef75f197d42586ef4664f057b/src/cargo/util/rustc.rs#L48-L68
This is also what
rust-analyzerrecently switch to doing: rust-lang/rust-analyzer#6912There's also precedent for relying on
rustcto determine these kinds of things, such as using it to find the sysroot:https://github.com/rust-analyzer/rust-analyzer/blob/48802e54d1669c68fd27b007533dd6aa5221d089/crates/project_model/src/sysroot.rs#L126-L127
One way to make this nicer would be if
cargo metadatasupported a "special" value for--filter-platformcalledhost. I'll look at submitting that as a PR upstream, but the more immediate fix (and also one that would continue to work for older compiler releases) would be to just userustc -Vv.