-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow Cargo patches without modifying Cargo.lock #17473
Copy link
Copy link
Open
Labels
A-lockfileArea: Cargo.lock issuesArea: Cargo.lock issuesA-patchArea: [patch] table overrideArea: [patch] table overrideC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-lockfileArea: Cargo.lock issuesArea: Cargo.lock issuesA-patchArea: [patch] table overrideArea: [patch] table overrideC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Problem
I maintain a monorepo containing several Rust projects as subtrees. During development, I use
[patch]entries to make those projects compile against local versions of shared dependencies. The same patches are also needed when building the system with Nix.This works for compilation, but Cargo writes patch information into
Cargo.lock. That creates unwanted changes from normal editor activity, including rust-analyzer or even just from running cargo normally, and makes the lockfile describe the local development setup instead of the dependency declared by the package, which adds unwanted changes in git and makes the packages impossible to be compiled separately without modifying the lock file all the time.For example, a dependency declared from crates.io or GitHub should continue to point to that source in
Cargo.lock, even when a local path patch is used during development. Unused patch entries should not be added either.Proposed Solution
Add a boolean configuration option:
When disabled, Cargo should:
[[patch.unused]]entries.[[patch.unused]]entries when reading the lockfile.Cargo.lock, including crates.io or GitHub sources.The default should remain
truefor compatibility with current Cargo behavior.Notes
I have vibecoded an ad-hoc patch to borrow myself some time to develop the main project while this feature is not in standard cargo. It's available at https://github.com/ardos-os/cargo/tree/codex/lockfile-patch-sources
If you're fine upstreaming that exact code I can submit a pull request or if you want to change something in the implementation, i'm available to make those adjustments.