Duplicate and incompatible dependencies when using `patch` on crate with inherited workspace dependencies

I'm currently playing around with wasmtime (GitHub, crates.io.)
While doing so, I wanted to modify the wasmtime-wasi-nn crate (GitHub, crates.io.), which depends on wasmtime and lives in the same repository and cargo workspace.
So I did the following:

  1. clone the wasmtime repository (at the commit of the last crates crates.io release)
  2. do some modifications to my local version of wasmtime-wasi-nn
  3. patch the wasmtime-wasi-nn in my project like this:
[patch.crates-io]
wasmtime-wasi-nn = { path = "../wasmtime/crates/wasi-nn" }

Now I have the problem that there are two incompatible versions of wasmtime in my dependency tree:

  • the crates.io version (direct dependency of my project)
  • my local version, on which the my modified wasmtime-wasi-nn depends (through [dependencies] wasmtime = { workspace = true ... })

I thought that there should be a way to make my local wasmtime-wasi-nn depend on the crates.io version (without changing it's Cargo.toml, as i would have to undo these changes if i wanted to contribute my changes back to the repo).
Or perhaps there is another approach that I am overlooking...

I look forward to any suggestions.

No, there isn't. The way that that change normally happens is that the Cargo.toml is edited by cargo publish to remove the path parts and leave only version (and replace workspace = true with the data it's referring to).

You can make that change in a separate commit on a separate branch, so it doesn't interfere with contributing the other change back.

Or, you can add to [patch.crates.io] a patch for the wasmtime package too, so they both use your local copy. That'll probably have better compatibility anyway.

Thanks for clarifying on why / how this works the way it does!

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.