Skip to content

Patching an indirect dependency with package = "xxx" renaming #13734

Open
@billy1624

Description

@billy1624

Problem

Context

We have three crates:

  • parent
  • child
  • client

Where client depends on child and child depends on parent.

We want to patch (overriding) the parent used by child.

First Try: with package renaming

Here, we would use the patch syntax in client/Cargo.toml:

[patch.'https://github.com/billy1624/test-cargo-patch.git'] 
parent = { path = "../parent-x", package = "parent-x" } 

https://github.com/billy1624/test-cargo-patch/blob/2257248f866c8bd9efcc635b33075cb66f89fd93/client/Cargo.toml#L1-L17

Overriding parent with parent-x. The parent-x is being renamed as parent as follows:

Checkout the branch.

$ cd client

$ cargo b
   Compiling child v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
error[E0061]: this function takes 1 argument but 0 arguments were supplied
 --> /Users/billy/.cargo/git/checkouts/test-cargo-patch-ae21da568fb3f50c/12ec729/child/src/lib.rs:2:5
  |
2 |     parent::func();
  |     ^^^^^^^^^^^^-- an argument of type `String` is missing
  |
note: function defined here
 --> /Users/billy/.cargo/git/checkouts/test-cargo-patch-ae21da568fb3f50c/12ec729/parent/src/lib.rs:1:8
  |
1 | pub fn func(_: String) -> &'static str {
  |        ^^^^
help: provide the argument
  |
2 |     parent::func(/* String */);
  |                 ~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0061`.
error: could not compile `child` (lib) due to 1 previous error

$ cargo tree
client v0.1.0 (/Users/billy/Projects/test-cargo-patch/client)
├── child v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
│   └── parent v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
└── parent-x v0.1.0 (/Users/billy/Projects/test-cargo-patch/parent-x)

From the result of cargo build and cargo tree, we saw that it did NOT patch (override) the parent dependency that's used in child.

Second Try: without package renaming

Overriding parent with parent-x. The package in parent-x is being named as parent, 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.

$ cd client

❯ cargo b
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s

❯ cargo tree
client v0.1.0 (/Users/billy/Projects/test-cargo-patch/client)
├── child v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
│   └── parent v0.1.0 (/Users/billy/Projects/test-cargo-patch/parent-x)
└── parent v0.1.0 (/Users/billy/Projects/test-cargo-patch/parent-x)

Here, we successfully patch (override) the parent dependency that's used in child.

Questions

  • Is this the intended behaviour?

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-questionCategory: questionS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions