-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Listed in 2 issues
Copy link
Labels
C-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`Command-addS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewZ-public-dependencyNightly: public-dependencyNightly: public-dependency
Description
Problem
When adding a new dependency that is meant to interact with another one (ie its a public transitive dependency), you need the versions aligned.
Proposed Solution
When cargo add foo
auto-selects the version requirement, we shouldn't just check other dependency tables to see if the dependency is present but we should first check public transitive dependencies of the table we are editing.
We also should check the public dependencies of the package being added to see if there is a better match
ie in the ideal case we would allow either of the following
$ cargo add clap_complete@3
$ cargo add clap # pick v3 instead of v4
$ ...
$ cargo add clap@3
$ cargo add clap_complete # pick v3 instead of v4
How well it works in practice, it will be seen.
Notes
No response
Metadata
Metadata
Assignees
Labels
C-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`Command-addS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewZ-public-dependencyNightly: public-dependencyNightly: public-dependency
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
--public
support forcargo add
#13037linyihai commentedon Nov 23, 2023
claim first, question it later ~ @rustbot claim
linyihai commentedon Mar 29, 2024
I'm trying to figure out what's possible.
The two examples above seem completely different to me and may require different solutions.
The prerequisite is that clap_complete depends on clap and is
public
, that is to say clap is clap_complete public dependency.Case 1: run
cargo add clap_complete@3
firstlyFor the first example, we run
cargo add clap_complete@3
, then the exact version of clap can be found in Cargo.lock.So a possible outline comes to my mind, when people run
cargo add clap
crate_spec
the resolver records the clap version, and clap is a public transitive of clap_compete, then the version "3.2.25" will be picked up.
Do you think this idea will work?
Case 2: run
cargo add clap@3
firstlyBut if people run
cargo add clap@3
firstly, then the resolver will not records the version about clap_complete. In this case, we can't get the compatible version of the dependency to be added through resolver.Consider public dependencies when choosing a version in cargo add (ru…
Consider public dependencies when choosing a version in cargo add (ru…
Consider public dependencies when choosing a version in cargo add (ru…
Consider public dependencies when choosing a version in cargo add (ru…
Consider public dependencies when choosing a version in cargo add (#1… (