-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Consider the following Cargo.toml
.
[package]
name = "test-patch"
version = "0.1.0"
edition = "2021"
[dependencies]
wgpu = "0.18"
egui_wgpu_backend = "0.28"
[patch.crates-io]
wgpu = { git = "https://github.com/Imberflur/wgpu.git", tag = "0.18-with-fixes-for-veloren-v1" }
cargo check
works fine here. But running cargo patch
gives us this error:
Error: failed to select a version for `web-sys`.
... required by package `wgpu v0.18.0`
... which satisfies dependency `wgpu = "^0.18"` of package `test-patch v0.1.0 (/home/youser/src/test-patch)`
versions that meet the requirements `^0.3.64` (locked to 0.3.69) are: 0.3.69
the package `wgpu` depends on `web-sys`, with features: `GpuComputePassTimestampWrite` but `web-sys` does not have these features.
failed to select a version for `web-sys` which could resolve this conflict
We also get this error if we remove the [patch.crates-io]
section from the Cargo.toml
. The patch applied to wgpu
is critical in this case, in order for cargo to resolve dependencies, and in consequence, in order for it to do anything at all.
I see that in the resolve_ws
function, on lines 171-180, you have:
let resolve: Resolve = resolve_with_previous(
&mut registry,
ws,
&CliFeatures::new_all(true),
HasDevUnits::No,
prev.as_ref(),
None,
&[],
false,
)?;
That last false
is the problem. Of course, if you just change it to true
, that'll make the program fail on every project where a given target/patch/{PACKAGE}
directory pointed to in the [patch.crates-io]
section doesn't exist. Which is the situation you're probably in if you've freshly cloned a repository, or you ran cargo clean
in a repository, that uses this program.
A direct solution would be to change the false
to true
, but (somehow) filter [patch.*]
entries with a path
pointing to a directory in target/patch
out of the workspace
being passed into this function. That would work in this case, but not if the patch itself is needed to resolve dependencies correctly (like for example, using cargo patch
to apply the patches that make the wgpu fork work to wgpu). The only way to make that work would be to simply not resolve dependencies and just go grab the dependency from Cargo.toml
directly, in which case the only way to know for sure which package to pick from crates.io would be to require pinned exact versions (e.g. wgpu = "=0.18.0"
instead of wgpu = "0.18"
), since you don't know if some transitive dependency actually requires a patch version that's lower than the highest one available. This, of course, doesn't apply to git repositories, which you can just clone (and switch to the branch or tag or commit if specified).