bootstrap: put Miri sysroot into local build dir

This commit is contained in:
Ralf Jung 2022-11-06 10:13:32 +01:00
parent c199a39884
commit a9edee7d1a
3 changed files with 24 additions and 11 deletions

View File

@ -466,7 +466,13 @@ pub struct Miri {
impl Miri { impl Miri {
/// Run `cargo miri setup` for the given target, return where the Miri sysroot was put. /// Run `cargo miri setup` for the given target, return where the Miri sysroot was put.
pub fn build_miri_sysroot(builder: &Builder<'_>, compiler: Compiler, miri: &Path, target: TargetSelection) -> String { pub fn build_miri_sysroot(
builder: &Builder<'_>,
compiler: Compiler,
miri: &Path,
target: TargetSelection,
) -> String {
let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysrot");
let mut cargo = tool::prepare_tool_cargo( let mut cargo = tool::prepare_tool_cargo(
builder, builder,
compiler, compiler,
@ -485,6 +491,8 @@ pub fn build_miri_sysroot(builder: &Builder<'_>, compiler: Compiler, miri: &Path
cargo.env("MIRI_LIB_SRC", builder.src.join("library")); cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
// Tell it where to find Miri. // Tell it where to find Miri.
cargo.env("MIRI", &miri); cargo.env("MIRI", &miri);
// Tell it where to put the sysroot.
cargo.env("MIRI_SYSROOT", &miri_sysroot);
// Debug things. // Debug things.
cargo.env("RUST_BACKTRACE", "1"); cargo.env("RUST_BACKTRACE", "1");

View File

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

View File

@ -17,10 +17,8 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
let only_setup = matches!(subcommand, MiriCommand::Setup); let only_setup = matches!(subcommand, MiriCommand::Setup);
let ask_user = !only_setup; let ask_user = !only_setup;
let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path let print_sysroot = only_setup && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
if std::env::var_os("MIRI_SYSROOT").is_some() { if !only_setup && std::env::var_os("MIRI_SYSROOT").is_some() {
if only_setup { // Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
println!("WARNING: MIRI_SYSROOT already set, not doing anything.")
}
return; return;
} }
@ -61,8 +59,13 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
} }
// Determine where to put the sysroot. // Determine where to put the sysroot.
let user_dirs = directories::ProjectDirs::from("org", "rust-lang", "miri").unwrap(); let sysroot_dir = match std::env::var_os("MIRI_SYSROOT") {
let sysroot_dir = user_dirs.cache_dir(); Some(dir) => PathBuf::from(dir),
None => {
let user_dirs = directories::ProjectDirs::from("org", "rust-lang", "miri").unwrap();
user_dirs.cache_dir().to_owned()
}
};
// Sysroot configuration and build details. // Sysroot configuration and build details.
let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() { let sysroot_config = if std::env::var_os("MIRI_NO_STD").is_some() {
SysrootConfig::NoStd SysrootConfig::NoStd
@ -111,7 +114,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
(command, rustflags) (command, rustflags)
}; };
// Make sure all target-level Miri invocations know their sysroot. // Make sure all target-level Miri invocations know their sysroot.
std::env::set_var("MIRI_SYSROOT", sysroot_dir); std::env::set_var("MIRI_SYSROOT", &sysroot_dir);
// Do the build. // Do the build.
if only_setup { if only_setup {
@ -121,7 +124,7 @@ pub fn setup(subcommand: &MiriCommand, target: &str, rustc_version: &VersionMeta
// We want to be quiet, but still let the user know that something is happening. // We want to be quiet, but still let the user know that something is happening.
eprint!("Preparing a sysroot for Miri (target: {target})... "); eprint!("Preparing a sysroot for Miri (target: {target})... ");
} }
Sysroot::new(sysroot_dir, target) Sysroot::new(&sysroot_dir, target)
.build_from_source(&rust_src, BuildMode::Check, sysroot_config, rustc_version, cargo_cmd) .build_from_source(&rust_src, BuildMode::Check, sysroot_config, rustc_version, cargo_cmd)
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
if only_setup { if only_setup {