-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo rm
unexpectedly removes patches
#12419
Comments
If I'm reading the reproduction steps correctly, the
Note that this is referencing some of the structure of cargo. This was implemented as This seemed ok because the chance of this seemed low and people could selecting add/revert the relevant parts. |
In serde's repo where I hit this, the patch is definitely used. $ cargo tree
serde v1.0.179 (/git/serde/serde)
[dev-dependencies]
└── serde_derive v1.0.179 (proc-macro) (/git/serde/serde_derive)
├── proc-macro2 v1.0.66
│ └── unicode-ident v1.0.11
├── quote v1.0.32
│ └── proc-macro2 v1.0.66 (*)
└── syn v2.0.28
├── proc-macro2 v1.0.66 (*)
├── quote v1.0.32 (*)
└── unicode-ident v1.0.11
[dev-dependencies]
└── serde v1.0.179 (/git/serde/serde) (*)
serde_derive v1.0.179 (proc-macro) (/git/serde/serde_derive) (*)
serde_derive_internals v0.28.0 (/git/serde/serde_derive_internals)
├── proc-macro2 v1.0.66 (*)
├── quote v1.0.32 (*)
└── syn v2.0.28 (*)
serde_test_suite v0.0.0 (/git/serde/test_suite)
└── serde v1.0.179 (/git/serde/serde) (*)
[dev-dependencies]
├── automod v1.0.12 (proc-macro)
│ ├── proc-macro2 v1.0.66 (*)
│ ├── quote v1.0.32 (*)
│ └── syn v2.0.28 (*)
├── fnv v1.0.7
├── rustversion v1.0.14 (proc-macro)
├── serde v1.0.179 (/git/serde/serde) (*)
├── serde_derive v1.0.179 (proc-macro) (/git/serde/serde_derive) (*)
├── serde_test v1.0.176
│ └── serde v1.0.179 (/git/serde/serde) (*)
└── trybuild v1.0.82
├── basic-toml v0.1.4
│ └── serde v1.0.179 (/git/serde/serde) (*)
├── dissimilar v1.0.7
├── glob v0.3.1
├── once_cell v1.18.0
├── serde v1.0.179 (/git/serde/serde) (*)
├── serde_derive v1.0.179 (proc-macro)
├── serde_json v1.0.104
│ ├── itoa v1.0.9
│ ├── ryu v1.0.15
│ └── serde v1.0.179 (/git/serde/serde) (*)
└── termcolor v1.2.0 Notice how all of |
Updated repro: # serde/Cargo.toml
[package]
name = "serde"
version = "1.0.0"
[dependencies]
serde_derive = { path = "../serde_derive" }
[dev-dependencies]
serde_json = "=1.0.0"
Before: $ cargo tree
serde v1.0.0 (/git/repro/workspace/serde)
└── serde_derive v1.0.0 (/git/repro/workspace/serde_derive)
[dev-dependencies]
└── serde_json v1.0.0
├── dtoa v0.4.8
├── itoa v0.3.4
├── num-traits v0.1.43
│ └── num-traits v0.2.16
│ [build-dependencies]
│ └── autocfg v1.1.0
└── serde v1.0.0 (/git/repro/workspace/serde) (*) After: $ cargo tree
serde v1.0.0 (/git/repro/workspace/serde)
[dev-dependencies]
└── serde_json v1.0.0
├── dtoa v0.4.8
├── itoa v0.3.4
├── num-traits v0.1.43
│ └── num-traits v0.2.16
│ [build-dependencies]
│ └── autocfg v1.1.0
└── serde v1.0.179 |
Mentioning @cassaundra since you worked on the relevant PR. |
Thanks for clarifying the reproduction case! Looks like the bug is that we only check workspace member dependencies for a patch applying. That is correct for workspace inheritance but not for patches. |
I wonder if a simple way of resolving this is to generate the lockfile ( |
@epage hey, I'm a first time contributor here. I was wondering if I could claim this issue? Also, if it's ok, are there any glaring gotchas that you see and I should be on the look out for here? |
I'd start with a test that demonstrates the bug, making this its own commit. This way when the commit with the fix will show the change in behavior, making it easier for a reviewer to see that this has the intended affect. The start of the code in question is here. For the APIs you'll be working with resolve_ws is a good start. You are also welcome to come to office hours to talk it over. |
@epage Looks like the source is that the I'm thinking I could break out gc'ing patches to a separate function and run it after Additionally, I think there's a bug in cargo/src/cargo/core/resolver/resolve.rs Line 142 in b644a40
This marks the package unused only if the graph doesn't contain it, but since the patch is a member it'll always be in the graph. |
Ah, I had overlooked that we already track used patches and can reuse that, nice! I was assuming we'd just walk
I'm not quite following what the problem is. |
Commenting out the gc patch code, |
If I'm understanding correctly, your proposed fix would mean we never GC patches for workspace members? I can live with that, at least for now. This is a minority case (workspace member that is never depended on in the workspace) and people might want to keep that around. I'd simplify the test case to the minimum number of variable which is just a transitive dependency that is being patched. |
I'm proposing the following:
This'll automatically remove unused patches but leave ones that have an actual nested dependency. In its current form, patches are being removed if it isn't overriding a workspace member's dependency. I do wonder if we should be automatically removing unused patches without an explicit flag from the user. Maybe a flag could be added that'll enable this? |
If I'm understanding correctly, this is unrelated to the current issue and should be handled separately. Feel free to create an issue and investigate it further (I'd want input from others more involved with the resolver to even decide whether this is a bug or not) but I don't think this should be part of the discussion fro this issue, in the same PR, or investigation of it blocking progress on this issue. |
That is a separate discussion as well |
Ok, fair enough. I was thinking they should be separate discussions as well. My proposal then is:
|
Problem
When I run
cargo rm dependency
, I expect Cargo to remove the cratedependency
from the current crate's [dependencies], and other related necessary changes, like removingdependency
from the right-hand side of features that previously enabled an optional dependency on "dependency" or one of its features "dependency/…".Cargo does these things, but it also wipes out my
patch.crates-io
section from the workspace's manifest. I could not figure out how this seems related in any way to removing a single dependency, so I think this is a bug.Steps
+
serde/src/lib.rs
andserde_derive/src/lib.rs
which can be empty files.In the
serde
directory, run:Expected diff:
Actual diff produced by Cargo:
Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: