rustdependency-managementrust-cargo

Patching version of transient dependencies Rust


I am trying to fix a dependency issue in Rust/Cargo. I have a dependency ctclib-pp which in turn depends on ctclib-kenlm-sys which finally depends on bindgen ^0.59.2. However, for compatibility reasons I need to use version 0.60.1 or higher of bindgen (because of this).

I tried the following changes in my Cargo.toml but that does not seem to work, as this seems to install both versions next to each other.

[dependencies]
ctclib-pp = "0.2.0"

[patch.crates-io]
bindgen = { git = "https://github.com/rust-lang/rust-bindgen", tag = "v0.60.1" }

When I run cargo update I get the following notice:

warning: Patch `bindgen v0.60.1 (https://github.com/rust-lang/rust-bindgen?tag=v0.60.1#9ca5f856)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.

and the lock file now contains an unused patch

[[patch.unused]]
name = "bindgen"
version = "0.60.1"
source = "git+https://github.com/rust-lang/rust-bindgen?tag=v0.60.1#9ca5f856a35deddde0575002d76d1db4430e6c42"

Any suggestions on how to override the sub-dependency?


Solution

  • You can fork the bindgen repository with the 0.60.1 version, edit the package version in its Cargo.toml down to 0.59.2, and use that within your [patch] section.