Skip to content

Commit

Permalink
Implement --locked for build-std
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgemmell committed Sep 20, 2024
1 parent eaee77d commit c3509ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn resolve_std<'gctx>(
// TODO: Consider doing something to enforce --locked? Or to prevent the
// lock file from being written, such as setting ephemeral.
let mut std_ws = Workspace::new(&std_ws_manifest_path, gctx)?;
std_ws.set_is_std(true);
// Don't require optional dependencies in this workspace, aka std's own
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
// those included because we'll never use them anyway.
Expand Down
12 changes: 12 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ pub struct Workspace<'gctx> {

/// Local overlay configuration. See [`crate::sources::overlay`].
local_overlays: HashMap<SourceId, PathBuf>,

/// Whether this is the workspace used for building the standard library
is_std: bool,
}

// Separate structure for tracking loaded packages (to avoid loading anything
Expand Down Expand Up @@ -250,6 +253,7 @@ impl<'gctx> Workspace<'gctx> {
resolve_honors_rust_version: false,
custom_metadata: None,
local_overlays: HashMap::new(),
is_std: false,
}
}

Expand Down Expand Up @@ -1790,6 +1794,14 @@ impl<'gctx> Workspace<'gctx> {

Ok(ret.into_iter())
}

pub fn is_std(&self) -> bool {
self.is_std
}

pub fn set_is_std(&mut self, is_std: bool) {
self.is_std = is_std
}
}

impl<'gctx> Packages<'gctx> {
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes
);
}

if ws.is_std() {
anyhow::bail!(
"Attempted to write the standard library's lockfile.\n\
This most likely means the lockfile has been previously modified by mistake."
);
}

// While we're updating the lock file anyway go ahead and update its
// encoding to whatever the latest default is. That way we can slowly roll
// out lock file updates as they're otherwise already updated, and changes
Expand Down

0 comments on commit c3509ae

Please sign in to comment.