Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4936174

Browse files
committedJan 4, 2025
Move build_miri_sysroot out of the Miri test step
This helper function is used by the test step type that contained it, but it is also used by other miri-related steps.
1 parent d13c80a commit 4936174

File tree

3 files changed

+40
-42
lines changed

3 files changed

+40
-42
lines changed
 

‎src/bootstrap/src/core/build_steps/run.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::PathBuf;
77

88
use crate::Mode;
99
use crate::core::build_steps::dist::distdir;
10-
use crate::core::build_steps::test;
10+
use crate::core::build_steps::test::build_miri_sysroot;
1111
use crate::core::build_steps::tool::{self, SourceType, Tool};
1212
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
1313
use crate::core::config::TargetSelection;
@@ -132,7 +132,7 @@ impl Step for Miri {
132132
let host_compiler = builder.compiler(stage - 1, host);
133133

134134
// Get a target sysroot for Miri.
135-
let miri_sysroot = test::Miri::build_miri_sysroot(builder, target_compiler, target);
135+
let miri_sysroot = build_miri_sysroot(builder, target_compiler, target);
136136

137137
// # Run miri.
138138
// Running it via `cargo run` as that figures out the right dylib path.

‎src/bootstrap/src/core/build_steps/test.rs

+35-38
Original file line numberDiff line numberDiff line change
@@ -437,47 +437,44 @@ pub struct Miri {
437437
target: TargetSelection,
438438
}
439439

440-
impl Miri {
441-
/// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
442-
pub fn build_miri_sysroot(
443-
builder: &Builder<'_>,
444-
compiler: Compiler,
445-
target: TargetSelection,
446-
) -> PathBuf {
447-
let miri_sysroot = builder.out.join(compiler.host).join("miri-sysroot");
448-
let mut cargo = builder::Cargo::new(
449-
builder,
450-
compiler,
451-
Mode::Std,
452-
SourceType::Submodule,
453-
target,
454-
Kind::MiriSetup,
455-
);
440+
/// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
441+
pub(crate) fn build_miri_sysroot(
442+
builder: &Builder<'_>,
443+
compiler: Compiler,
444+
target: TargetSelection,
445+
) -> PathBuf {
446+
let miri_sysroot = builder.out.join(compiler.host).join("miri-sysroot");
447+
let mut cargo = builder::Cargo::new(
448+
builder,
449+
compiler,
450+
Mode::Std,
451+
SourceType::Submodule,
452+
target,
453+
Kind::MiriSetup,
454+
);
456455

457-
// Tell `cargo miri setup` where to find the sources.
458-
cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
459-
// Tell it where to put the sysroot.
460-
cargo.env("MIRI_SYSROOT", &miri_sysroot);
456+
// Tell `cargo miri setup` where to find the sources.
457+
cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
458+
// Tell it where to put the sysroot.
459+
cargo.env("MIRI_SYSROOT", &miri_sysroot);
461460

462-
let mut cargo = BootstrapCommand::from(cargo);
463-
let _guard =
464-
builder.msg(Kind::Build, compiler.stage, "miri sysroot", compiler.host, target);
465-
cargo.run(builder);
461+
let mut cargo = BootstrapCommand::from(cargo);
462+
let _guard = builder.msg(Kind::Build, compiler.stage, "miri sysroot", compiler.host, target);
463+
cargo.run(builder);
466464

467-
// # Determine where Miri put its sysroot.
468-
// To this end, we run `cargo miri setup --print-sysroot` and capture the output.
469-
// (We do this separately from the above so that when the setup actually
470-
// happens we get some output.)
471-
// We re-use the `cargo` from above.
472-
cargo.arg("--print-sysroot");
465+
// # Determine where Miri put its sysroot.
466+
// To this end, we run `cargo miri setup --print-sysroot` and capture the output.
467+
// (We do this separately from the above so that when the setup actually
468+
// happens we get some output.)
469+
// We re-use the `cargo` from above.
470+
cargo.arg("--print-sysroot");
473471

474-
builder.verbose(|| println!("running: {cargo:?}"));
475-
let stdout = cargo.run_capture_stdout(builder).stdout();
476-
// Output is "<sysroot>\n".
477-
let sysroot = stdout.trim_end();
478-
builder.verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
479-
PathBuf::from(sysroot)
480-
}
472+
builder.verbose(|| println!("running: {cargo:?}"));
473+
let stdout = cargo.run_capture_stdout(builder).stdout();
474+
// Output is "<sysroot>\n".
475+
let sysroot = stdout.trim_end();
476+
builder.verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
477+
PathBuf::from(sysroot)
481478
}
482479

483480
impl Step for Miri {
@@ -517,7 +514,7 @@ impl Step for Miri {
517514

518515
// We also need sysroots, for Miri and for the host (the latter for build scripts).
519516
// This is for the tests so everything is done with the target compiler.
520-
let miri_sysroot = Miri::build_miri_sysroot(builder, target_compiler, target);
517+
let miri_sysroot = build_miri_sysroot(builder, target_compiler, target);
521518
builder.ensure(compile::Std::new(target_compiler, host));
522519
let host_sysroot = builder.sysroot(target_compiler);
523520

‎src/bootstrap/src/core/builder/cargo.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::ffi::{OsStr, OsString};
33
use std::path::{Path, PathBuf};
44

55
use super::{Builder, Kind};
6+
use crate::core::build_steps::compile;
7+
use crate::core::build_steps::test::build_miri_sysroot;
68
use crate::core::build_steps::tool::SourceType;
7-
use crate::core::build_steps::{compile, test};
89
use crate::core::config::SplitDebuginfo;
910
use crate::core::config::flags::Color;
1011
use crate::utils::helpers::{
@@ -808,7 +809,7 @@ impl Builder<'_> {
808809
if cmd_kind == Kind::MiriTest {
809810
self.ensure(compile::Std::new(compiler, compiler.host));
810811
let host_sysroot = self.sysroot(compiler);
811-
let miri_sysroot = test::Miri::build_miri_sysroot(self, compiler, target);
812+
let miri_sysroot = build_miri_sysroot(self, compiler, target);
812813
cargo.env("MIRI_SYSROOT", &miri_sysroot);
813814
cargo.env("MIRI_HOST_SYSROOT", &host_sysroot);
814815
}

0 commit comments

Comments
 (0)
Please sign in to comment.