Skip to content

Commit Cargo.lock to make CI and local debugging more stable #855

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

Merged
merged 1 commit into from
May 17, 2025

Conversation

faern
Copy link
Contributor

@faern faern commented May 16, 2025

The official recommendation regarding libraries commiting the cargo lockfile changed a while back: https://blog.rust-lang.org/2023/08/29/committing-lockfiles/. Previously libraries were not recommended to commit the lockfile. Now it's left up to the library maintainers to decide what fits their needs the best. For example cargo new --lib no longer ignores Cargo.lock by default.

I personally have found that always commiting the lockfile, even for libraries, provide for a much more reproducible debugging experience. Without a lockfile, every CI run might run with different dependencies. And local development becomes against whatever that developer has in their lockfile, instead of some shared view of the expected dependency tree.

Commiting a lockfile does not mean that's the only exact version of everything that the library support. The version range specified in Cargo.toml is still what dictates what versions the library should work with. But just having a stable reference to run against is sooo helpful.

For example now, when I submitted #854. The CI failed with this error that is completely unrelated to my PR: https://github.com/bheisler/criterion.rs/actions/runs/15076547284/job/42385189894?pr=854. The error is because if you get the latest version of all packages we depend on, some of them do not build against the version of rustc that criterion has specified as its MSRV.

Most crates do not treat MSRV changes as breaking changes (that's a completely correct IMHO), but it does create the issue that a dependency you have can suddenly require a newer rustc than you have specified that your library needs, but still be semver compatible with what you have specified. Then a commited lockfile stops the CI form randomly pulling in too new versions of that dependency.

@lemmih lemmih merged commit 7afab6e into bheisler:master May 17, 2025
4 of 5 checks passed
@faern faern deleted the commit-cargo-lockfile-for-stable-ci branch May 17, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants