Consider not changing the version in `Cargo.toml` before the release is cut
In order to depend on unreleased versions of libraries, cargo offers a way to patch a certain version of a dependency via the [patch.crates-io].
This however only works if the version mentioned in the project Cargo.toml file is the same one as the one set in the dependency's manifest.
I am currently depending on bdk 0.14 and trying to patch bdk across my dependency graph to latest HEAD. Unfortunately, that doesn't work:
❯ cargo t
Updating git repository `https://github.com/bitcoindevkit/bdk`
warning: Patch `bdk v0.14.1-dev (https://github.com/bitcoindevkit/bdk#64e88f0e)` 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.
Do people use the [patch.crates-io] feature? If yes, how are you dealing with pre-release version bumps in the manifest file?
If you just need to use the latest pre-released version then the patch method is a good way to go. But to use it you also need to specify the current version in the repo master branch, this will work:
[patch.crates-io]
bdk = { git = 'https://github.com/bitcoindevkit/bdk' }
[dependencies]
bdk = { version = "0.14.1-dev", default-features = false, features = ["all-keys"]}
This doesn't quite work unfortunately.
The point of [patch] is to replace dependencies across the entire dependency graph without changing the [dependencies] table. In my case, bdk is also a transitive dependency and I cannot change the version referenced in that dependency's manifest file (without forking / changing it).
So to apply your suggestion, I need to:
- Fork / change said dependency to a bdk version that does not exist yet (
0.14.1-dev) - Push that change
[patch]that dependency in my application- Change the bdk version in my application
[patch]bdk in my application
At that point, I might as well not use [patch] and modify the [dependencies] table of both crates to point to a specific revision :man_shrugging:
This however only works if the version mentioned in the project
Cargo.tomlfile is the same one as the one set in the dependency's manifest.
I don't have to be the same it just has to be compatible right? I would have expected 0.14.1-dev to be compatible with 0.14 in the dependency's Cargo.toml. Then cargo should use it after cargo update.
To me it looks like patch is just not behaving correctly here. See this post where the user does the same thing https://github.com/rust-lang/cargo/issues/2222#issuecomment-590616041 This should work. I think patch's behaviour is wrong.
I would have expected
0.14.1-devto be compatible with0.14in the dependency'sCargo.toml. Then cargo should use it aftercargo update.
From the spec:
A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version.
I think this says that 0.14.1-dev might not necessarily yield a 0.14.1 and is thus not safe to automatically upgrade from 0.14.0 like 0.14.1 would be.
I think you're right. I would expect patch to somehow relax this rule or provide a way of more powerfully overriding.
Yes, I've longed for a more "brutal" [patch] behaviour myself several times but it is unfortunately fairly restrictive :/
In chat with @LLFourn sounds like this will also be of use to his projects. I propose:
- After we create a new
release/0.x.0branch we bump the version in themasterbranch torelease/0.x+1.0. This lets someone[patch]to the next unreleased MINOR version. - After we
cargo releaseversion0.x.0from therelease/0.x.0branch, we then bump the to version in that branch to0.x.1. This lets you[patch]bdk to a possible next PATCH version.
I think this works @thomaseizinger? if so I guess this can be closed.
With changed proposed in #544 you should be able to use pre-release versions by pointing your [patch] to either the release/0.x or master branch and version.