|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Change in Guidance on Committing Lockfiles" |
| 4 | +author: Ed Page |
| 5 | +team: The Cargo Team <https://www.rust-lang.org/governance/teams/dev-tools#cargo> |
| 6 | +--- |
| 7 | + |
| 8 | +For years, the Cargo team has encouraged Rust developers to |
| 9 | +[commit their `Cargo.lock` file for packages with binaries but not libraries](https://doc.rust-lang.org/1.71.1/cargo/faq.html#why-do-binaries-have-cargolock-in-version-control-but-not-libraries). |
| 10 | +We now recommend people |
| 11 | +[do what is best for their project](https://doc.rust-lang.org/nightly/cargo/faq.html#why-have-cargolock-in-version-control). |
| 12 | +To help people make a decision, we do include some considerations and suggest |
| 13 | +committing `Cargo.lock` as a starting point in their decision making. |
| 14 | +To align with that starting point, `cargo new` will no longer ignore |
| 15 | +`Cargo.lock` for libraries as of nightly-2023-08-24. |
| 16 | +Regardless of what decision projects make, we encourage regular |
| 17 | +[testing against their latest dependencies](https://doc.rust-lang.org/nightly/cargo/guide/continuous-integration.html#verifying-latest-dependencies). |
| 18 | + |
| 19 | +## Background |
| 20 | + |
| 21 | +The old guidelines ensured libraries tested their latest dependencies which |
| 22 | +helped us keep quality high within Rust's package ecosystem by ensuring issues, |
| 23 | +especially backwards compatibility issues, |
| 24 | +were quickly found and addressed. |
| 25 | +While this extra testing was not exhaustive, |
| 26 | +We believe it helped foster a culture of quality in this nascent ecosystem. |
| 27 | + |
| 28 | +This hasn't been without its downsides though. |
| 29 | +This has removed an important piece of history from code bases, |
| 30 | +making bisecting to find the root cause of a bug harder for maintainers. |
| 31 | +For contributors, |
| 32 | +especially newer ones, |
| 33 | +this is another potential source of confusion and frustration from an unreliable CI whenever a |
| 34 | +dependency is yanked or a new release contains a bug. |
| 35 | + |
| 36 | +## Why the change |
| 37 | + |
| 38 | +A lot as changed for Rust since the guideline was written. |
| 39 | +Rust has shifted from being a language for early adopters to being more mainstream, |
| 40 | +and we need to be mindful of the on-boarding experience of these new-to-Rust developers. |
| 41 | +Also with this wider adoption, it isn't always practical to assume everyone is using |
| 42 | +the latest Rust release and the community has been working through how to |
| 43 | +manage support for minimum-supported Rust versions (MSRV). |
| 44 | +Part of this is maintaining an instance of your dependency tree that can build |
| 45 | +with your MSRV. |
| 46 | +A lockfile is an appropriate way to pin versions for your project so you |
| 47 | +can validate your MSRV but we found people were instead putting upperbounds on their |
| 48 | +version requirements due to the strength of our prior guideline despite |
| 49 | +[likely being a worse solution](https://doc.rust-lang.org/nightly/cargo/reference/specifying-dependencies.html#multiple-requirements). |
| 50 | + |
| 51 | +The wider software development ecosystem has also changed a lot in the |
| 52 | +intervening time. |
| 53 | +CI has become easier to setup and maintain. |
| 54 | +We also have products like |
| 55 | +[Dependabot](https://docs.github.com/en/code-security/dependabot/working-with-dependabot) |
| 56 | +and |
| 57 | +[Renovate](https://docs.renovatebot.com/). |
| 58 | +This has opened up options besides having version control ignore `Cargo.lock` to test newer dependencies. |
| 59 | +Developers could have a scheduled job that first runs `cargo update`. |
| 60 | +They could also have bots regularly update their `Cargo.lock` in PRs, ensuring |
| 61 | +they pass CI before being merged. |
| 62 | + |
| 63 | +Since there isn't a universal answer to these situations, |
| 64 | +we felt it was best to leave the choice to developers and give them information they need in making a decision. |
| 65 | +For feedback on this policy change, |
| 66 | +see [rust-lang/cargo#8728](https://github.com/rust-lang/cargo/issues/8728). |
| 67 | +You can also reach out the the Cargo team more generally on |
| 68 | +[Zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo). |
0 commit comments