Skip to content

Commit

Permalink
Add support so that Miri can be quiet when the sysroot is unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed May 11, 2024
1 parent 353c7fd commit 96403a0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ pub struct SysrootBuilder {
rustflags: Vec<OsString>,
cargo: Option<Command>,
rustc_version: Option<rustc_version::VersionMeta>,
when_build_required: Option<Box<dyn FnOnce()>>,
}

pub enum SysrootStatus {
AlreadyCached,
SysrootBuilt,
}

/// Hash file name (in target/lib directory).
Expand Down Expand Up @@ -185,6 +191,7 @@ impl SysrootBuilder {
rustflags: default_flags.iter().map(Into::into).collect(),
cargo: None,
rustc_version: None,
when_build_required: None,
}
}

Expand Down Expand Up @@ -232,6 +239,11 @@ impl SysrootBuilder {
self
}

pub fn when_build_required(mut self, when_build_required: impl FnOnce() + 'static) -> Self {
self.when_build_required = Some(Box::new(when_build_required));
self
}

/// Our configured target can be either a built-in target name, or a path to a target file.
/// We use the same logic as rustc to tell which is which:
/// https://github.com/rust-lang/rust/blob/8d39ec1825024f3014e1f847942ac5bbfcf055b0/compiler/rustc_session/src/config.rs#L2252-L2263
Expand Down Expand Up @@ -379,7 +391,7 @@ panic = 'unwind'
/// Build the `self` sysroot from the given sources.
///
/// `src_dir` must be the `library` source folder, i.e., the one that contains `std/Cargo.toml`.
pub fn build_from_source(mut self, src_dir: &Path) -> Result<()> {
pub fn build_from_source(mut self, src_dir: &Path) -> Result<SysrootStatus> {
// A bit of preparation.
if !src_dir.join("std").join("Cargo.toml").exists() {
bail!(
Expand All @@ -401,7 +413,12 @@ panic = 'unwind'
let cur_hash = self.sysroot_compute_hash(src_dir, &rustc_version)?;
if self.sysroot_read_hash() == Some(cur_hash) {
// Already done!
return Ok(());
return Ok(SysrootStatus::AlreadyCached);
}

// A build is required, so we run the when-build-required function if one was set.
if let Some(when_build_required) = self.when_build_required.take() {
when_build_required();
}

// Prepare a workspace for cargo
Expand Down Expand Up @@ -493,6 +510,6 @@ panic = 'unwind'
.context("failed to create target directory")?;
fs::rename(staging_dir.path(), sysroot_lib_dir).context("failed installing sysroot")?;

Ok(())
return Ok(SysrootStatus::SysrootBuilt);
}
}

0 comments on commit 96403a0

Please sign in to comment.