Cargo patch crates with different names

There is a crate let's say lib1, that I want to modify and cargo patch.

But the problem is my modified version of lib1, let's go with lib1-patch has an indirect dependency on lib1. Hence I cannot name my modified crate lib1.
Since now the crates have different names (lib1 and lib1-patch) I'm not able to cargo patch

I know this seems pretty impossible and one should not have circular deps but still hoping for a workaround where I can cargo patch lib1 with lib1-patch.

This might be more of a cargo question than rust.
Thanks

[patch.crates-io]
lib1 = {package = "lib1-patch", version = "0.1.0", path = "lib1_patch" }
warning: Patch `lib1-patcg v0.1.0 (lib1_patch)` 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.

lib1-patch

[package]
# cannot name it "lib1" due to circular dep error, but without same name it won't patch "lib1"
name = "lib1-patch"
version = "0.1.0"

[dependencies]
lib1-orig = { package = "lib1", version = "0.1.0" }
lib1-dependent = "^0.1.0"

lib1-dependent

[package]
name = "lib1-dependent"
version = "0.1.0"

[dependencies]
lib1 = "^0.1.0"

https://github.com/rust-lang/cargo/issues/9227

1 Like

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.