Skip to content

fix(install): use packaged lockfile by default - #17388

Open
gmemuriuki wants to merge 4 commits into
rust-lang:masterfrom
gmemuriuki:fix/7169-install-use-lockfile
Open

fix(install): use packaged lockfile by default#17388
gmemuriuki wants to merge 4 commits into
rust-lang:masterfrom
gmemuriuki:fix/7169-install-use-lockfile

Conversation

@gmemuriuki

@gmemuriuki gmemuriuki commented Aug 24, 2026

Copy link
Copy Markdown

View all comments

What does this PR try to resolve?

This PR closes #7169

cargo build uses an existing Cargo.lock, while cargo install previously ignored a package's Cargo.lock file unless --locked was passed. As a result, building and testing a binary could use one set of dependency version while installing the same binary selected another.

This can cause installation to fail even though the package built and tested successfully. This also leaves maintainers supporting dependency versions they didn't test or sign-up for.

Following Cargo Team Decision,
this PR makes cargo install use the available lockfile by default. This gives cargo install the existing behavior of cargo install --locked.

--locked remains accepted but it is a no-op. When a package does not contain a lockfile, Cargo fallback to resolving its deps normally. Explicitly passing --locked still emits the existing missing-lockfile warning.

The warning for yanked deps is preserved, but it's suggestion to retry without --locked is removed because doing so no longer changes dep resolution.

Deprecating --locked and adding an option to ignore the packaged lockfile remains a separate effort to be considered as discussed in the decision.

How to test and review this PR?

There are four commits structured in this manner:

  1. Make the help attached to yanked-dependency warning optional without changing the existing behavior
  2. Add tests to verify that cargo install --locked honors packaged lockfile.
  3. Change installation behavior, update the affected tests, and update the generated documentation.
  4. Remove now obsolete ignore_lock workspace state and resolver path.

Test covers

  1. Registry installation without the packaged lockfile by default.
  2. Path installation using it's lockfile by default.
  3. --locked remaining accepted and producing the same resolution.
  4. Falling back to normal resolution when no published lockfile exists.
  5. Git installation without a lockfile
  6. Yanked dependencies continuing to warn without suggesting installation without --locked.
  7. The existing cargo-package yanked-dependency help remaining unchanged.

The following tests were run:

cargo test --test testsuite -- install::install_respects_lock_file
cargo test --test testsuite -- install::install_path_respects_lock_file
cargo test --test testsuite -- install::locked_install_
cargo test --test testsuite -- install::install_without_published_lockfile
cargo test --test testsuite -- install::git_repo
cargo test --test testsuite -- publish_lockfile::warn

@rustbot rustbot added A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-workspaces Area: workspaces Command-install Command-package S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @weihanglo (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @epage, @weihanglo
  • @epage, @weihanglo expanded to epage, weihanglo
  • Random selection from epage, weihanglo

Comment thread src/workspace/workspace.rs Outdated
Comment thread src/ops/cargo_install.rs
Comment thread src/workspace/workspace.rs Outdated
Comment thread tests/testsuite/install.rs Outdated
.with_status(101)
.run();
p.cargo("install --path . --locked").run();
p.cargo("install --path .").run();

@weihanglo weihanglo Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This drops the snapshot asserting [..]not rust[..]. Was it intentional? Otherwise we might want to keep it.

View changes since the review

Comment thread tests/testsuite/install.rs Outdated
.run();
p.cargo("install --path . --locked").run();
p.cargo("install --path .").run();
p.cargo("install --path . --locked --force").run();

@weihanglo weihanglo Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This --locked --force change is better to be in its own test commit, prior to the fix commit, and we might want to have the same assertion verifying it actually respects the lockfile.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's fine. I'll have it ready.

@weihanglo

Copy link
Copy Markdown
Member

Thanks for the contribution. Would you mind cleaning up the template strings in the PR description?

@epage

epage commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

btw thank you for moving this forward! The recent arrayref situation shows how important this change is!

@gmemuriuki

Copy link
Copy Markdown
Author

🙏 Happy to help. I'd love to get more involved with cargo even after this.

@gmemuriuki
gmemuriuki force-pushed the fix/7169-install-use-lockfile branch from 5ad02ea to 07a27bc Compare August 26, 2026 19:31
@weihanglo

Copy link
Copy Markdown
Member

@gmemuriuki You probably want to rebase onto master branch to fix the failed job: https://github.com/rust-lang/cargo/actions/runs/33005586808/job/98298352305?pr=17388

@gmemuriuki

Copy link
Copy Markdown
Author

Sure, I'm on it.

Comment thread tests/testsuite/install.rs
Comment thread tests/testsuite/install.rs
Comment thread tests/testsuite/install.rs
Keep explicit --locked coverage independent from tests for cargo install's default lockfile behavior.
@gmemuriuki
gmemuriuki force-pushed the fix/7169-install-use-lockfile branch from 07a27bc to 61aec32 Compare August 27, 2026 20:21
@rustbot

rustbot commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Make registry and path installs honor Cargo.lock without requiring --locked.
Keep fallback behavior when no lockfile is available,  including the compatibility warning for explicit --locked.
Cargo install now honors an an available lockfile, so no caller needs
Workspace::ignore_lock. Remove the unused state and unreachable resolver
and MSRV-help branches while retaining the no-lockfile yanked-check
guard.
@gmemuriuki
gmemuriuki force-pushed the fix/7169-install-use-lockfile branch from 61aec32 to b7c0e0f Compare August 27, 2026 21:19

@weihanglo weihanglo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Maybe we can polish doc a bit but not a blocker

View changes since this review

@epage epage added the T-cargo Team: Cargo label Aug 28, 2026
@epage

epage commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

@rfcbot fcp merge

This PR implements the policy we decided on in the 2026-04-28 meeting as described at #7169 (comment)

@rust-rfcbot

rust-rfcbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

@epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Aug 28, 2026
@weihanglo

Copy link
Copy Markdown
Member

@rfcbot reviewed

@arlosi

arlosi commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Sep 1, 2026
@rust-rfcbot

Copy link
Copy Markdown
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-workspaces Area: workspaces Command-install Command-package disposition-merge FCP with intent to merge final-comment-period FCP — a period for last comments before action is taken S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo

Projects

Status: FCP merge

Development

Successfully merging this pull request may close these issues.

"cargo install" apparently ignores "Cargo.lock" as opposed to "cargo build"

6 participants