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

When no version is specified, reuse existing locked versions #12046

Open
epage opened this issue Apr 27, 2023 · 3 comments
Open

When no version is specified, reuse existing locked versions #12046

epage opened this issue Apr 27, 2023 · 3 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-add S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@epage
Copy link
Contributor

epage commented Apr 27, 2023

Problem

When developing #12039, I ran cargo add clap into the xtask but that picked the latest clap version, causing more churn to the lockfile than I thought was appropriate for my change.

Proposed Solution

Check the lockfile for the highest version that is semver compatible with the latest version.

  • By limiting it to semver compatible, this avoids the "some random dev dependency is using an old clap" problem (criterion)

Alternatives

  • Pick from non-dev dependencies
  • Pick only if a workspace member depends on it
  • Reject this in favor of workspace inheritance

Notes

See also killercup/cargo-edit#41

@epage epage added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-add S-triage Status: This issue is waiting on initial triage. labels Apr 27, 2023
@epage
Copy link
Contributor Author

epage commented Apr 27, 2023

I originally rejected killercup/cargo-edit#41 because of workspace inheritance but I find that I don't tend to use it for dependencies, preferring to keep that information more local

@weihanglo weihanglo added S-needs-team-input Status: Needs input from team on whether/how to proceed. and removed S-triage Status: This issue is waiting on initial triage. labels Jun 2, 2023
@epage epage added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-needs-team-input Status: Needs input from team on whether/how to proceed. labels Dec 12, 2024
@dev-ardi
Copy link

I wouldn't even oppose to having an opt-in option to use older versions.
I would also expect cargo add crate@latest to keep current behavior.
And now that I'm asking cargo add crate@workspace should work too.

@epage
Copy link
Contributor Author

epage commented Dec 12, 2024

Flags work well when the user runs the command very regularly or if they realize they missed it and can go back, find it, and run it again.

Thats not the case with cargo add, especially in picking versions since cargo add foo && cargo add foo --some-flag-affecting-default-version will mean that a version is already selected and the flag will do nothing. Because of this, we try to provide a reasonable heuristic picking the version.

Flags also come with a cost. The more knobs you offer users, the more they have to search for to find what they are doing or give up and not use the nice feature. The more features we add, the lower the value users get for that feature and every other feature in cargo add.

By default cargo add will already pick

  • A version from another dependency table in the same package, assuming you'll want to use the two versions in sync
  • Inherit from an existing workspace.dependencies entry

#10608 is exploring heuristics to add dependencies to workspace.dependencies.

There is no cargo add <crate>@latest, see #10741.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-add S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants