Skip to content

Commit c3509ae

Browse files
committed
Implement --locked for build-std
1 parent eaee77d commit c3509ae

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/cargo/core/compiler/standard_lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub fn resolve_std<'gctx>(
7878
// TODO: Consider doing something to enforce --locked? Or to prevent the
7979
// lock file from being written, such as setting ephemeral.
8080
let mut std_ws = Workspace::new(&std_ws_manifest_path, gctx)?;
81+
std_ws.set_is_std(true);
8182
// Don't require optional dependencies in this workspace, aka std's own
8283
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
8384
// those included because we'll never use them anyway.

src/cargo/core/workspace.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ pub struct Workspace<'gctx> {
120120

121121
/// Local overlay configuration. See [`crate::sources::overlay`].
122122
local_overlays: HashMap<SourceId, PathBuf>,
123+
124+
/// Whether this is the workspace used for building the standard library
125+
is_std: bool,
123126
}
124127

125128
// Separate structure for tracking loaded packages (to avoid loading anything
@@ -250,6 +253,7 @@ impl<'gctx> Workspace<'gctx> {
250253
resolve_honors_rust_version: false,
251254
custom_metadata: None,
252255
local_overlays: HashMap::new(),
256+
is_std: false,
253257
}
254258
}
255259

@@ -1790,6 +1794,14 @@ impl<'gctx> Workspace<'gctx> {
17901794

17911795
Ok(ret.into_iter())
17921796
}
1797+
1798+
pub fn is_std(&self) -> bool {
1799+
self.is_std
1800+
}
1801+
1802+
pub fn set_is_std(&mut self, is_std: bool) {
1803+
self.is_std = is_std
1804+
}
17931805
}
17941806

17951807
impl<'gctx> Packages<'gctx> {

src/cargo/ops/lockfile.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
6666
);
6767
}
6868

69+
if ws.is_std() {
70+
anyhow::bail!(
71+
"Attempted to write the standard library's lockfile.\n\
72+
This most likely means the lockfile has been previously modified by mistake."
73+
);
74+
}
75+
6976
// While we're updating the lock file anyway go ahead and update its
7077
// encoding to whatever the latest default is. That way we can slowly roll
7178
// out lock file updates as they're otherwise already updated, and changes

0 commit comments

Comments
 (0)