Open billy1624 opened 7 months ago
[patch]
only looks at the canonical package name, i.e. value specified in package.name
, when patching a package. Dependency renaming is not considered and only useful for resolving conflicts due to the limitation of the TOML format. See "Using [patch]
with multiple versions".
You could look closer at the output of cargo tree
. The first one didn't work because you were patching parent-x
from a Git source, however non-existent in the dependency tree. The second one worked because it certainly patched parent
since the package.name
is now parent
for the package under parent-x
directory.
Problem
Context
We have three crates:
parent
child
client
Where
client
depends onchild
andchild
depends onparent
.We want to patch (overriding) the
parent
used bychild
.First Try: with package renaming
Here, we would use the patch syntax in
client/Cargo.toml
:https://github.com/billy1624/test-cargo-patch/blob/2257248f866c8bd9efcc635b33075cb66f89fd93/client/Cargo.toml#L1-L17
Overriding
parent
withparent-x
. Theparent-x
is being renamed asparent
as follows:package = "xxx"
https://github.com/billy1624/test-cargo-patch/blob/2257248f866c8bd9efcc635b33075cb66f89fd93/client/Cargo.toml#L12-L17parent-x
is exported asparent
https://github.com/billy1624/test-cargo-patch/blob/2257248f866c8bd9efcc635b33075cb66f89fd93/parent-x/Cargo.toml#L1-L12Checkout the branch.
From the result of
cargo build
andcargo tree
, we saw that it did NOT patch (override) theparent
dependency that's used inchild
.Second Try: without package renaming
Overriding
parent
withparent-x
. The package inparent-x
is being named asparent
, without any renaming:https://github.com/billy1624/test-cargo-patch/blob/18d4e28b039b851e8ab18cf2749b8700f7d91935/client/Cargo.toml#L1-L17
https://github.com/billy1624/test-cargo-patch/blob/18d4e28b039b851e8ab18cf2749b8700f7d91935/parent-x/Cargo.toml#L1-L12
Checkout the branch.
Here, we successfully patch (override) the
parent
dependency that's used inchild
.Questions
Steps
No response
Possible Solution(s)
No response
Notes
No response
Version
No response