I'm in a situation where I want to patch a particular dependency with a local copy but cargo
doesn't seem to want to use it because the local copy has a -dev
suffix.
Given the following:
- One of my dependencies has
target-crate = "^0.9.0"
in itsCargo.toml
- the most recently released version of
target-crate
is0.9.2
- I want to override this with
target-crate = { path = "./path/to/local/version" }
, where the local version is0.9.3-dev
- the
-dev
suffix is automatically added bycargo release
, and I don't want to remove the-dev
suffix to make it0.9.3
- we get the
0.9.3-dev
version number from aconst VERSION: &str = env!("CARGO_PKG_VERSION")
insidetarget-crate
Here are some things I've tried...
[package]
name = "generated-crate"
[dependencies]
some-dependency = "..."
target-crate = "0.9.3-dev"
[patch.crates-io]
target-crate = { path = "./path/to/local/version" }
Fails with
error: failed to select a version for the requirement `target-crate = "^0.9.3-dev"`
candidate versions found which didn't match: 0.9.2, 0.9.1, 0.9.0, ...
location searched: crates.io index
required by package `generated-crate v0.0.0 (...)`
I also tried replacing the version under [dependencies]
with the override itself.
[dependencies]
some-dependency = "..."
target-crate = { path = "./path/to/local/version" }
[patch.crates-io]
target-crate = { path = "./path/to/local/version" }
But that results in compile errors because the generated code expects an object implementing target_crate::SomeTrait
from target-crate v0.9.3-dev
, but it finds an object implementing target_crate::SomeTrait
from the incompatible target-crate v0.9.2
... That implies the version used by some-dependency
is still 0.9.2
and wasn't patched.
Has anyone else tried using the [patch]
section like this?
To add a bit more context, "my crate" is a Rust crate I'm generating and compiling dynamically, target-crate
contains common code that all generated crates use, and all this version trickery is to allow developers to hack on target-crate
locally without needing to publish their changes to crates.io.