How do you patch a old version of a dependency

How do I patch an old version of a dependency when by overriding other crates that has a different version declared?

If I have a /project/crates/profile/src/Cargo.toml where I have declared

my_dep = "0.0.10"

But at root I have /project/Cargo.toml I have

[workspace]

members = [
  "crates/profile"
  ]
[patch.crates-io]
my_dep = {git = "https://github.com/dep", branch = "v0.0.1"}

How do I patch a 0.0.1 when the original crate pointed to 0.0.10?

Is your version really with 0.0. prefix? The double zero prefix is an exceptional case.

Cargo uses the first non-zero number as semver-major incompatible version, so crates that require 0.0.10 will get this and only this version, and nothing else. You can't make them use 0.0.1.

This would be different in case of 1.0.1 vs 1.0.10 or 0.9.1 vs 0.9.10. These would be semver-compatible, and get unified to one version.

When you patch, your repo has to have a version that is at least as high as the minimum required version. Cargo won't forcefully downgrade versions (you can make a git repo with older code and higher version number, but the version must satisfy patched crate's requirements).

1 Like

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.