Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
billy1624 opened this issue Apr 11, 2024 · 1 comment
Open

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

billy1624 opened this issue Apr 11, 2024 · 1 comment
Labels
C-question Category: question S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@billy1624
Copy link

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

@billy1624 billy1624 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 11, 2024
@weihanglo
Copy link
Member

[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.

@weihanglo weihanglo added C-question Category: question S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: question S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants