Skip to content

Commit a9edee7

Browse files
committed
bootstrap: put Miri sysroot into local build dir
1 parent c199a39 commit a9edee7

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/bootstrap/test.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,13 @@ pub struct Miri {
466466

467467
impl Miri {
468468
/// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
469-
pub fn build_miri_sysroot(builder: &Builder<'_>, compiler: Compiler, miri: &Path, target: TargetSelection) -> String {
469+
pub fn build_miri_sysroot(
470+
builder: &Builder<'_>,
471+
compiler: Compiler,
472+
miri: &Path,
473+
target: TargetSelection,
474+
) -> String {
475+
let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysrot");
470476
let mut cargo = tool::prepare_tool_cargo(
471477
builder,
472478
compiler,
@@ -485,6 +491,8 @@ impl Miri {
485491
cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
486492
// Tell it where to find Miri.
487493
cargo.env("MIRI", &miri);
494+
// Tell it where to put the sysroot.
495+
cargo.env("MIRI_SYSROOT", &miri_sysroot);
488496
// Debug things.
489497
cargo.env("RUST_BACKTRACE", "1");
490498

src/tools/miri/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,10 @@ Moreover, Miri recognizes some environment variables:
433433
trigger a re-build of the standard library; you have to clear the Miri build
434434
cache manually (on Linux, `rm -rf ~/.cache/miri`).
435435
* `MIRI_SYSROOT` (recognized by `cargo miri` and the Miri driver) indicates the sysroot to use. When
436-
using `cargo miri`, only set this if you do not want to use the automatically created sysroot. For
437-
directly invoking the Miri driver, this variable (or a `--sysroot` flag) is mandatory.
436+
using `cargo miri`, this skips the automatic setup -- only set this if you do not want to use the
437+
automatically created sysroot. For directly invoking the Miri driver, this variable (or a
438+
`--sysroot` flag) is mandatory. When invoking `cargo miri setup`, this indicates where the sysroot
439+
will be put.
438440
* `MIRI_TEST_TARGET` (recognized by the test suite and the `./miri` script) indicates which target
439441
architecture to test against. `miri` and `cargo miri` accept the `--target` flag for the same
440442
purpose.

src/tools/miri/cargo-miri/src/setup.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
1717
let only_setup = matches!(subcommand, MiriCommand::Setup);
1818
let ask_user = !only_setup;
1919
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
20-
if std::env::var_os("MIRI_SYSROOT").is_some() {
21-
if only_setup {
22-
println!("WARNING: MIRI_SYSROOT already set, not doing anything.")
23-
}
20+
if !only_setup && std::env::var_os("MIRI_SYSROOT").is_some() {
21+
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
2422
return;
2523
}
2624

@@ -61,8 +59,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
6159
}
6260

6361
// Determine where to put the sysroot.
64-
let user_dirs = directories::ProjectDirs::from("org", "rust-lang", "miri").unwrap();
65-
let sysroot_dir = user_dirs.cache_dir();
62+
let sysroot_dir = match std::env::var_os("MIRI_SYSROOT") {
63+
Some(dir) => PathBuf::from(dir),
64+
None => {
65+
let user_dirs = directories::ProjectDirs::from("org", "rust-lang", "miri").unwrap();
66+
user_dirs.cache_dir().to_owned()
67+
}
68+
};
6669
// Sysroot configuration and build details.
6770
let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() {
6871
SysrootConfig::NoStd
@@ -111,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
111114
(command, rustflags)
112115
};
113116
// Make sure all target-level Miri invocations know their sysroot.
114-
std::env::set_var("MIRI_SYSROOT", sysroot_dir);
117+
std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
115118

116119
// Do the build.
117120
if only_setup {
@@ -121,7 +124,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
121124
// We want to be quiet, but still let the user know that something is happening.
122125
eprint!("Preparing a sysroot for Miri (target: {target})... ");
123126
}
124-
Sysroot::new(sysroot_dir, target)
127+
Sysroot::new(&sysroot_dir, target)
125128
.build_from_source(&rust_src, BuildMode::Check, sysroot_config, rustc_version, cargo_cmd)
126129
.unwrap_or_else(|_| {
127130
if only_setup {

0 commit comments

Comments
 (0)