Consider the following cargo tree
output:
myproj v0.1.0 (Z:\repos\myproj)
├── win32job v2.0.0
│ ├── thiserror v1.0.58
│ │ └── thiserror-impl v1.0.58 (proc-macro)
│ │ ├── proc-macro2 v1.0.81
│ │ │ └── unicode-ident v1.0.12
│ │ ├── quote v1.0.36
│ │ │ └── proc-macro2 v1.0.81 (*)
│ │ └── syn v2.0.59
│ │ ├── proc-macro2 v1.0.81 (*)
│ │ ├── quote v1.0.36 (*)
│ │ └── unicode-ident v1.0.12
│ └── windows v0.52.0
│ ├── windows-core v0.52.0
│ │ └── windows-targets v0.52.5
│ │ └── windows_x86_64_msvc v0.52.5
│ └── windows-targets v0.52.5 (*)
└── windows v0.56.0
├── windows-core v0.56.0
│ ├── windows-implement v0.56.0 (proc-macro)
│ │ ├── proc-macro2 v1.0.81 (*)
│ │ ├── quote v1.0.36 (*)
│ │ └── syn v2.0.59 (*)
│ ├── windows-interface v0.56.0 (proc-macro)
│ │ ├── proc-macro2 v1.0.81 (*)
│ │ ├── quote v1.0.36 (*)
│ │ └── syn v2.0.59 (*)
│ ├── windows-result v0.1.1
│ │ └── windows-targets v0.52.5 (*)
│ └── windows-targets v0.52.5 (*)
└── windows-targets v0.52.5 (*)
As you can see win32job
requires windows
but has pegged it to version 0.52
. I went with version = "*"
for the direct dependency.
After reading this, I thought I'd give the [patch]
section a try and added the following in my .cargo/config.toml
(local to the project):
[patch.crates-io.windows]
version = "*"
Most subsequent cargo
invocations will then, however, give me an error such as this:
$ cargo tree
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
Caused by:
patch for `windows` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
This appears to make sense (see full .cargo/config.toml
below), but on the other hand it raises the question how to override the version
key for a transient dependency in such a scenario.
Does anyone know?
PS: my full .cargo/config.toml
looks like this, because I am using cargo vendor
:
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
[patch.crates-io.windows]
version = "*"