Skip to content

Commit 5c41e68

Browse files
authored
Use --locked with Cargo where possible (#925)
The Cargo `--locked` argument ensures that Cargo will fail with an error if `Cargo.lock` is out of sync with `Cargo.toml`, rather than the lockfile being silently updated. Since this repo is a library, we currently don't commit its `Cargo.lock` to Git (though we might want to revisit that for a few reasons in the future). However, there are still some places where we should be using `--locked` that aren't already. GUS-W-18062544.
1 parent bbc94d0 commit 5c41e68

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.github/workflows/prepare-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
4848

4949
- name: Install cargo-edit
50-
run: cargo install cargo-edit
50+
run: cargo install --locked cargo-edit
5151

5252
- name: Record old crate version
5353
id: old-version

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
3737

3838
- name: Install cargo-release
39-
run: cargo install cargo-release
39+
run: cargo install --locked cargo-release
4040

4141
- name: Record new crate version
4242
id: new-version

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
- libcnb-package:
13+
- The `cargo build` command used when packing the buildpack is now run using `--locked` when the `CI` env var is set. ([#925](https://github.com/heroku/libcnb.rs/pull/925))
1214

1315
## [0.28.0] - 2025-03-03
1416

libcnb-package/src/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::cargo::{
55
};
66
use cargo_metadata::Metadata;
77
use std::collections::HashMap;
8+
use std::env;
89
use std::ffi::OsString;
910
use std::path::{Path, PathBuf};
1011
use std::process::{Command, ExitStatus};
@@ -104,6 +105,11 @@ fn build_binary(
104105
target_name: impl AsRef<str>,
105106
) -> Result<PathBuf, BuildError> {
106107
let mut cargo_args = vec!["build", "--target", target_triple.as_ref()];
108+
109+
if env::var_os("CI").is_some() {
110+
cargo_args.push("--locked");
111+
}
112+
107113
match cargo_profile {
108114
CargoProfile::Dev => {
109115
// We enable stripping for dev builds too, since debug builds are extremely

0 commit comments

Comments
 (0)