rust-lang / rust-lang/cargo

Cargo patch is finickier than it needs to be

Open
#6,341 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-patch C-feature-request S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

The current form of the [patch] section is that you do something like:

[patch.crates-io]
foo = { path = "../../foo" }

or

[patch."https://github.com/manishearth/foo"]
foo = { path = "../../foo" }

Right off the bat, having to make this choice is really unnecessary, having overlapping crates is rare. It would be nice if we just supported

[patch."*"]
foo = { path = "../../foo" }

Furthermore, a lot of crates are multiple crates in a single repo, and in such cases you usually want to pull in all of them

[patch.crates-io]
serde = { path = "../../serde" }
serde-derive = { path = "../../serde/derive" }
// etc

It would be nice if you could just say something like

[patch.crates-io]
serde* = { path = "../../serde" }

and it would look for all the crates it needs in that folder. Even if we don't support wildcards, supporting path dependencies that are able to do a directory tree search (the results of which would be cached in the lockfile anyway) would be nice.

If we don't end up doing this, it would be pretty nice to at least have diagnostics for the situation when:

  • You try to patch a git dep with crates-io or vice versa
  • You patch a single git dep from a repo containing multiple

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by tracing Cargo's [patch] handling and dependency-source validation, then clarify whether wildcard sources, crate-name wildcards, directory searches, or diagnostics are in scope. Done means the chosen behavior is agreed, implemented, and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.