Rust patch overrides not being applied

One of those hard cases with [patch...].

Excerpts from Cargo.toml:

[dependencies]
rend3 = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
rend3-egui = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
rend3-framework = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
rend3-routine = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }

[workspace.dependencies]
wgpu = { git = "https://github.com/John-Nagle/wgpu.git"}

[patch."https://github.com/BVE-Reborn/rend3.git"]
wgpu = { git = "https://github.com/John-Nagle/wgpu.git"}

[patch.crates-io]
wgpu = { git = "https://github.com/John-Nagle/wgpu.git"}

rend3 = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
rend3-egui = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
rend3-framework = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
rend3-routine = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
range-alloc = { git = "https://github.com/gfx-rs/range-alloc.git" }

This pulls in two copies of wgpu - one from crates.io, and one from my own repository, where I'm testing. Surprisingly, it compiles and runs, but is using the wrong version of wgpu for rend3 and for . I'm doing something wrong with the patches to "rend3", etc.
The documentation for "patch" seems to indicate that this should work. I recall having problems in the past patching specific revs, though.

Is it possible to force the version I want?

Do both wgpu copies have different crate versions? A patch only overrides a crate with the same crate version as the patch.

Can you show cargo tree maybe?

I get:

warning: Patch wgpu v0.20.0 (https://github.com/John-Nagle/wgpu.git#d9c054c6) was not used in the crate graph.
Patch wgpu v0.20.0 (https://github.com/John-Nagle/wgpu.git#d9c054c6) 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.

This patch doesn't make sense (as the cargo warning is telling you cryptically). It is saying: β€œif you would use a wgpu package whose source code is found in rend3.git, then use one in wgpu.git instead”. But there is no wgpu package in rend3.git, so it does not apply.

Patches don't apply to specific dependency graph edges β€” you can't patch β€œthe version of wgpu used by rend3”. They apply to entire packages, saying β€œwhenever this package is depended on, replace it with this other package”. The X in [patch.X] says what namespace you're identifying the package in.

What you should probably do is write your dependencies to refer to crates.io normally, and write one patch, which will affect the use of wgpu by all packages in the dependency graph, including yours:

[workspace.dependencies]
wgpu = "0.20.0"

[patch.crates-io]
# This affects every mention of wgpu, including the above
wgpu = { git = "https://github.com/John-Nagle/wgpu.git" }
3 Likes

Tried that. See branch "hp" of GitHub - John-Nagle/render-bench

Result is warning: Patch wgpu v0.20.0 (GitHub - John-Nagle/wgpu: Wgpu, test version for bug and performance fixes.) was not used in the crate graph.

Also tried wgpu = "0.19.0" since Rend3 requests that version. No effect.

And, indeed, it isn't. I wrote above about a version I hadn't pushed to Github, but now Github is in sync on branch hp, so others can see exactly what I did.

If I add

[dependencies]
wgpu = { git = "https://github.com/John-Nagle/wgpu.git"}

the Cargo error message goes away, but I get two versions of wgpu.

You can't use a patch to replace a package with another package that has an incompatible version. Major versions essentially act as part of the name of the package.

If you're using a rend3 package that depends on wgpu ~0.19 and you want to replace wgpu, you need to supply a wgpu package whose version number is compatible with ~0.19.

If you have two packages which depend on wgpu ~0.19 and wgpu ~0.20, and you want them to use the same wgpu, then you must patch one of those packages to change its [dependencies] table.

1 Like

confirmed, it works with:

[patch.crates-io]
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", branch="v0.19"}
$ cargo tree|grep ' wgpu '
β”‚   β”œβ”€β”€ wgpu v0.19.4 (https://github.com/gfx-rs/wgpu.git?branch=v0.19#87576b72)
β”‚       └── wgpu v0.19.4 (https://github.com/gfx-rs/wgpu.git?branch=v0.19#87576b72) (*)
β”‚   β”‚   └── wgpu v0.19.4 (https://github.com/gfx-rs/wgpu.git?branch=v0.19#87576b72) (*)
β”‚   β”œβ”€β”€ wgpu v0.19.4 (https://github.com/gfx-rs/wgpu.git?branch=v0.19#87576b72) (*)
β”‚   β”‚   β”œβ”€β”€ wgpu v0.19.4 (https://github.com/gfx-rs/wgpu.git?branch=v0.19#87576b72) (*)
β”‚   β”œβ”€β”€ wgpu v0.19.4 (https://github.com/gfx-rs/wgpu.git?branch=v0.19#87576b72) (*)
diff --git a/Cargo.toml b/Cargo.toml
index c047ddd..b8b16fe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -65,10 +65,11 @@ indoc = "1.0"
 cfg-if = "1.0"
 
 [workspace.dependencies]
-wgpu = "0.19.0"
+#wgpu = "0.19.0"
+wgpu = "0.20.0"
 
 [patch.crates-io]
-wgpu = { git = "https://github.com/John-Nagle/wgpu.git"}
+wgpu = { git = "https://github.com/gfx-rs/wgpu.git", branch="v0.19"}
 
 rend3 = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }
 rend3-egui = { version = "^0.3.0", git = 'https://github.com/BVE-Reborn/rend3.git', rev = "d088a84" }

Ah. I didn't make myself clear. The whole point here is that I need to
use my own fork of WGPU. (I'm looking for a locking delay. I can see it in profiling, but I need to add more profiling scopes to determine which of three locks is causing the stall.)

But I can't do that, because Rend3 uses WGPU 0.19, and my fork only has WGPU 0.20 in it. I need to re-fork, keeping all versions, and force the use of an old version of WGPU.

Bleah.

git clone https://github.com/John-Nagle/wgpu.git
cd wgpu

find . -type f \( -name 'Cargo.toml' -o -name 'Cargo.lock' \) -print0 | xargs -0 sed -i 's/0\.20\.0/0.19.4/g'

cd ../render-bench
cargo update

seems to work for me, but I didn't try to compile:

$ cargo tree | grep ' wgpu '
β”‚   β”œβ”€β”€ wgpu v0.19.4 (/tmp/wgpu/wgpu)
β”‚       └── wgpu v0.19.4 (/tmp/wgpu/wgpu) (*)
β”‚   β”‚   └── wgpu v0.19.4 (/tmp/wgpu/wgpu) (*)
β”‚   β”œβ”€β”€ wgpu v0.19.4 (/tmp/wgpu/wgpu) (*)
β”‚   β”‚   β”œβ”€β”€ wgpu v0.19.4 (/tmp/wgpu/wgpu) (*)
β”‚   β”œβ”€β”€ wgpu v0.19.4 (/tmp/wgpu/wgpu) (*)

I used this in render-bench's Cargo.toml:
wgpu = { path = "../wgpu/wgpu" }

Ouch! When it's necessary to run sed on Cargo.lock, it's getting too messy.

you're right, touching Cargo.lock in wgpu was definitely not needed as it's not used when doing stuff in render-bench, as wgpu is a dep of it, only its Cargo.toml is used

this is what changed thusly:

diff --git a/Cargo.toml b/Cargo.toml
index dfaa21eb6..4754c2a13 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -47,27 +47,27 @@ keywords = ["graphics"]
 license = "MIT OR Apache-2.0"
 homepage = "https://wgpu.rs/"
 repository = "https://github.com/gfx-rs/wgpu"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 
 [workspace.dependencies.wgc]
 package = "wgpu-core"
 path = "./wgpu-core"
-version = "0.20.0"
+version = "0.19.4"
 
 [workspace.dependencies.wgt]
 package = "wgpu-types"
 path = "./wgpu-types"
-version = "0.20.0"
+version = "0.19.4"
 
 [workspace.dependencies.hal]
 package = "wgpu-hal"
 path = "./wgpu-hal"
-version = "0.20.0"
+version = "0.19.4"
 
 [workspace.dependencies.naga]
 path = "./naga"
-version = "0.20.0"
+version = "0.19.4"
 
 [workspace.dependencies]
 anyhow = "1.0.86"
@@ -123,12 +123,12 @@ smallvec = "1"
 static_assertions = "1.1.0"
 tracy-client = "0.17"
 thiserror = "1"
-wgpu = { version = "0.20.0", path = "./wgpu" }
-wgpu-core = { version = "0.20.0", path = "./wgpu-core" }
-wgpu-example = { version = "0.20.0", path = "./examples/common" }
-wgpu-macros = { version = "0.20.0", path = "./wgpu-macros" }
-wgpu-test = { version = "0.20.0", path = "./tests" }
-wgpu-types = { version = "0.20.0", path = "./wgpu-types" }
+wgpu = { version = "0.19.4", path = "./wgpu" }
+wgpu-core = { version = "0.19.4", path = "./wgpu-core" }
+wgpu-example = { version = "0.19.4", path = "./examples/common" }
+wgpu-macros = { version = "0.19.4", path = "./wgpu-macros" }
+wgpu-test = { version = "0.19.4", path = "./tests" }
+wgpu-types = { version = "0.19.4", path = "./wgpu-types" }
 winit = { version = "0.29", features = ["android-native-activity"] }
 
 # Metal dependencies
@@ -149,7 +149,7 @@ gpu-allocator = { version = "0.26", default-features = false, features = [
     "d3d12",
     "public-winapi",
 ] }
-d3d12 = { version = "0.20.0", path = "./d3d12/" }
+d3d12 = { version = "0.19.4", path = "./d3d12/" }
 range-alloc = "0.1"
 winapi = "0.3"
 hassle-rs = "0.11.0"
diff --git a/d3d12/Cargo.toml b/d3d12/Cargo.toml
index 2c3f72152..ab48d8f7d 100644
--- a/d3d12/Cargo.toml
+++ b/d3d12/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "d3d12"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 description = "Low level D3D12 API wrapper"
 repository = "https://github.com/gfx-rs/wgpu/tree/trunk/d3d12"
diff --git a/naga-cli/Cargo.toml b/naga-cli/Cargo.toml
index 9ffe6e937..06e044089 100644
--- a/naga-cli/Cargo.toml
+++ b/naga-cli/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "naga-cli"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 edition = "2021"
 description = "Shader translation command line tool"
@@ -25,7 +25,7 @@ argh = "0.1.5"
 anyhow.workspace = true
 
 [dependencies.naga]
-version = "0.20.0"
+version = "0.19.4"
 path = "../naga"
 features = [
     "compact",
diff --git a/naga/Cargo.toml b/naga/Cargo.toml
index d9d032509..68a9c3616 100644
--- a/naga/Cargo.toml
+++ b/naga/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "naga"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 edition = "2021"
 description = "Shader translation infrastructure"
diff --git a/naga/fuzz/Cargo.toml b/naga/fuzz/Cargo.toml
index 196919e44..c7ed8e9aa 100644
--- a/naga/fuzz/Cargo.toml
+++ b/naga/fuzz/Cargo.toml
@@ -15,7 +15,7 @@ libfuzzer-sys = "0.4"
 
 [target.'cfg(not(any(target_arch = "wasm32", target_os = "ios")))'.dependencies.naga]
 path = ".."
-version = "0.20.0"
+version = "0.19.4"
 features = ["arbitrary", "spv-in", "wgsl-in", "glsl-in"]
 
 [[bin]]
diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml
index c18a5066a..b92f15c79 100644
--- a/wgpu-core/Cargo.toml
+++ b/wgpu-core/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "wgpu-core"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 edition = "2021"
 description = "WebGPU core logic on wgpu-hal"
@@ -120,17 +120,17 @@ thiserror = "1"
 
 [dependencies.naga]
 path = "../naga"
-version = "0.20.0"
+version = "0.19.4"
 
 [dependencies.wgt]
 package = "wgpu-types"
 path = "../wgpu-types"
-version = "0.20.0"
+version = "0.19.4"
 
 [dependencies.hal]
 package = "wgpu-hal"
 path = "../wgpu-hal"
-version = "0.20.0"
+version = "0.19.4"
 default-features = false
 
 [build-dependencies]
diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml
index 96ee7ff95..937050277 100644
--- a/wgpu-hal/Cargo.toml
+++ b/wgpu-hal/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "wgpu-hal"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 edition = "2021"
 description = "WebGPU hardware abstraction layer"
@@ -116,7 +116,7 @@ glow = { version = "0.13.1", optional = true }
 [dependencies.wgt]
 package = "wgpu-types"
 path = "../wgpu-types"
-version = "0.20.0"
+version = "0.19.4"
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 # backend: Vulkan
@@ -152,7 +152,7 @@ winapi = { version = "0.3", features = [
     "winuser",
     "dcomp",
 ] }
-d3d12 = { path = "../d3d12/", version = "0.20.0", optional = true, features = [
+d3d12 = { path = "../d3d12/", version = "0.19.4", optional = true, features = [
     "libloading",
 ] }
 
@@ -183,7 +183,7 @@ ndk-sys = { version = "0.5.0", optional = true }
 
 [dependencies.naga]
 path = "../naga"
-version = "0.20.0"
+version = "0.19.4"
 
 [build-dependencies]
 cfg_aliases.workspace = true
@@ -191,7 +191,7 @@ cfg_aliases.workspace = true
 # DEV dependencies
 [dev-dependencies.naga]
 path = "../naga"
-version = "0.20.0"
+version = "0.19.4"
 features = ["wgsl-in"]
 
 [dev-dependencies]
diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml
index ea18e6b33..9b9c830f0 100644
--- a/wgpu-types/Cargo.toml
+++ b/wgpu-types/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "wgpu-types"
-version = "0.20.0"
+version = "0.19.4"
 authors = ["gfx-rs developers"]
 edition = "2021"
 description = "WebGPU types"

I mean, you can just do that to see if it works, then you can do it more professionally I guess :slight_smile:

I had a try at going forward to wgpu 0.20, instead of back to 0.19, but it turns out that egui tried to use wgpu 0.20 and backed off pending some substantial fixes to wgpu 0.20. So it's not possible to build my program yet with wgpu 0.20. I don't want to add fixes to wgpu 0.19, since if I fix something a pull request would probably be irrelevant. So I'm stuck for a while until the crates settle.

At least all this stuff is being worked on.

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.