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 871df0d

Browse files
committedApr 1, 2024
Auto merge of #123192 - RalfJung:bootstrap-test-miri, r=onur-ozkan
Refactor the way bootstrap invokes `cargo miri` Instead of basically doing `cargo run --manifest-path=<cargo-miri's manifest> -- miri`, let's invoke the `cargo-miri` binary directly. That means less indirections, and also makes it easier to e.g. run the libcore test suite in Miri. (But there are still other issues with that.) Also also adjusted Miri's stage numbering so that it is consistent with rustc/rustdoc. This also makes `./x.py test miri` honor `--no-doc`. And this fixes #123177 by moving where we handle parallel_compiler.
2 parents 7f84ede + 85d460e commit 871df0d

File tree

10 files changed

+174
-135
lines changed

10 files changed

+174
-135
lines changed
 

‎src/bootstrap/src/bin/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn main() {
150150
{
151151
cmd.arg("-Ztls-model=initial-exec");
152152
}
153-
} else if std::env::var("MIRI").is_err() {
153+
} else {
154154
// Find any host flags that were passed by bootstrap.
155155
// The flags are stored in a RUSTC_HOST_FLAGS variable, separated by spaces.
156156
if let Ok(flags) = std::env::var("RUSTC_HOST_FLAGS") {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,12 +1130,6 @@ pub fn rustc_cargo_env(
11301130
cargo.env("CFG_DEFAULT_LINKER", s);
11311131
}
11321132

1133-
if builder.config.rustc_parallel {
1134-
// keep in sync with `bootstrap/lib.rs:Build::rustc_features`
1135-
// `cfg` option for rustc, `features` option for cargo, for conditional compilation
1136-
cargo.rustflag("--cfg=parallel_compiler");
1137-
cargo.rustdocflag("--cfg=parallel_compiler");
1138-
}
11391133
if builder.config.rust_verify_llvm_ir {
11401134
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
11411135
}

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ impl Step for ReplaceVersionPlaceholder {
121121

122122
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
123123
pub struct Miri {
124-
stage: u32,
125-
host: TargetSelection,
126124
target: TargetSelection,
127125
}
128126

@@ -135,29 +133,35 @@ impl Step for Miri {
135133
}
136134

137135
fn make_run(run: RunConfig<'_>) {
138-
run.builder.ensure(Miri {
139-
stage: run.builder.top_stage,
140-
host: run.build_triple(),
141-
target: run.target,
142-
});
136+
run.builder.ensure(Miri { target: run.target });
143137
}
144138

145139
fn run(self, builder: &Builder<'_>) {
146-
let stage = self.stage;
147-
let host = self.host;
140+
let host = builder.build.build;
148141
let target = self.target;
149-
let compiler = builder.compiler(stage, host);
150-
151-
let miri =
152-
builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
153-
let miri_sysroot = test::Miri::build_miri_sysroot(builder, compiler, &miri, target);
142+
let stage = builder.top_stage;
143+
if stage == 0 {
144+
eprintln!("miri cannot be run at stage 0");
145+
std::process::exit(1);
146+
}
147+
148+
// This compiler runs on the host, we'll just use it for the target.
149+
let target_compiler = builder.compiler(stage, host);
150+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
151+
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
152+
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
153+
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
154+
let host_compiler = builder.compiler(stage - 1, host);
155+
156+
// Get a target sysroot for Miri.
157+
let miri_sysroot = test::Miri::build_miri_sysroot(builder, target_compiler, target);
154158

155159
// # Run miri.
156160
// Running it via `cargo run` as that figures out the right dylib path.
157161
// add_rustc_lib_path does not add the path that contains librustc_driver-<...>.so.
158162
let mut miri = tool::prepare_tool_cargo(
159163
builder,
160-
compiler,
164+
host_compiler,
161165
Mode::ToolRustc,
162166
host,
163167
"run",

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

Lines changed: 75 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ impl Step for RustDemangler {
493493

494494
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
495495
pub struct Miri {
496-
stage: u32,
497-
host: TargetSelection,
498496
target: TargetSelection,
499497
}
500498

@@ -503,41 +501,26 @@ impl Miri {
503501
pub fn build_miri_sysroot(
504502
builder: &Builder<'_>,
505503
compiler: Compiler,
506-
miri: &Path,
507504
target: TargetSelection,
508505
) -> String {
509506
let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysroot");
510-
let mut cargo = tool::prepare_tool_cargo(
507+
let mut cargo = builder::Cargo::new(
511508
builder,
512509
compiler,
513-
Mode::ToolRustc,
514-
compiler.host,
515-
"run",
516-
"src/tools/miri/cargo-miri",
517-
SourceType::InTree,
518-
&[],
510+
Mode::Std,
511+
SourceType::Submodule,
512+
target,
513+
"miri-setup",
519514
);
520-
cargo.add_rustc_lib_path(builder);
521-
cargo.arg("--").arg("miri").arg("setup");
522-
cargo.arg("--target").arg(target.rustc_target_arg());
523515

524516
// Tell `cargo miri setup` where to find the sources.
525517
cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
526-
// Tell it where to find Miri.
527-
cargo.env("MIRI", miri);
528518
// Tell it where to put the sysroot.
529519
cargo.env("MIRI_SYSROOT", &miri_sysroot);
530-
// Debug things.
531-
cargo.env("RUST_BACKTRACE", "1");
532520

533521
let mut cargo = Command::from(cargo);
534-
let _guard = builder.msg(
535-
Kind::Build,
536-
compiler.stage + 1,
537-
"miri sysroot",
538-
compiler.host,
539-
compiler.host,
540-
);
522+
let _guard =
523+
builder.msg(Kind::Build, compiler.stage, "miri sysroot", compiler.host, target);
541524
builder.run(&mut cargo);
542525

543526
// # Determine where Miri put its sysroot.
@@ -574,68 +557,75 @@ impl Step for Miri {
574557
}
575558

576559
fn make_run(run: RunConfig<'_>) {
577-
run.builder.ensure(Miri {
578-
stage: run.builder.top_stage,
579-
host: run.build_triple(),
580-
target: run.target,
581-
});
560+
run.builder.ensure(Miri { target: run.target });
582561
}
583562

584563
/// Runs `cargo test` for miri.
585564
fn run(self, builder: &Builder<'_>) {
586-
let stage = self.stage;
587-
let host = self.host;
565+
let host = builder.build.build;
588566
let target = self.target;
589-
let compiler = builder.compiler(stage, host);
590-
// We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
591-
// Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
592-
let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
593-
594-
let miri =
595-
builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
596-
let _cargo_miri = builder.ensure(tool::CargoMiri {
597-
compiler,
598-
target: self.host,
567+
let stage = builder.top_stage;
568+
if stage == 0 {
569+
eprintln!("miri cannot be tested at stage 0");
570+
std::process::exit(1);
571+
}
572+
573+
// This compiler runs on the host, we'll just use it for the target.
574+
let target_compiler = builder.compiler(stage, host);
575+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
576+
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
577+
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
578+
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
579+
let host_compiler = builder.compiler(stage - 1, host);
580+
581+
// Build our tools.
582+
let miri = builder.ensure(tool::Miri {
583+
compiler: host_compiler,
584+
target: host,
585+
extra_features: Vec::new(),
586+
});
587+
// the ui tests also assume cargo-miri has been built
588+
builder.ensure(tool::CargoMiri {
589+
compiler: host_compiler,
590+
target: host,
599591
extra_features: Vec::new(),
600592
});
601-
// The stdlib we need might be at a different stage. And just asking for the
602-
// sysroot does not seem to populate it, so we do that first.
603-
builder.ensure(compile::Std::new(compiler_std, host));
604-
let sysroot = builder.sysroot(compiler_std);
605-
// We also need a Miri sysroot.
606-
let miri_sysroot = Miri::build_miri_sysroot(builder, compiler, &miri, target);
593+
594+
// We also need sysroots, for Miri and for the host (the latter for build scripts).
595+
// This is for the tests so everything is done with the target compiler.
596+
let miri_sysroot = Miri::build_miri_sysroot(builder, target_compiler, target);
597+
builder.ensure(compile::Std::new(target_compiler, host));
598+
let sysroot = builder.sysroot(target_compiler);
607599

608600
// # Run `cargo test`.
601+
// This is with the Miri crate, so it uses the host compiler.
609602
let mut cargo = tool::prepare_tool_cargo(
610603
builder,
611-
compiler,
604+
host_compiler,
612605
Mode::ToolRustc,
613606
host,
614607
"test",
615608
"src/tools/miri",
616609
SourceType::InTree,
617610
&[],
618611
);
619-
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, target);
620612

621613
cargo.add_rustc_lib_path(builder);
622614

615+
// We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test
616+
// harness and therefore do not understand the flags added by `add_flags_and_try_run_test`.
617+
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host_compiler, host, builder);
618+
623619
// miri tests need to know about the stage sysroot
624620
cargo.env("MIRI_SYSROOT", &miri_sysroot);
625621
cargo.env("MIRI_HOST_SYSROOT", &sysroot);
626622
cargo.env("MIRI", &miri);
627-
if builder.config.locked_deps {
628-
// enforce lockfiles
629-
cargo.env("CARGO_EXTRA_FLAGS", "--locked");
630-
}
631623

632624
// Set the target.
633625
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
634626

635-
// This can NOT be `run_cargo_test` since the Miri test runner
636-
// does not understand the flags added by `add_flags_and_try_run_test`.
637-
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", compiler, target, builder);
638627
{
628+
let _guard = builder.msg_sysroot_tool(Kind::Test, stage, "miri", host, target);
639629
let _time = helpers::timeit(builder);
640630
builder.run(&mut cargo);
641631
}
@@ -650,8 +640,14 @@ impl Step for Miri {
650640
// Optimizations can change error locations and remove UB so don't run `fail` tests.
651641
cargo.args(["tests/pass", "tests/panic"]);
652642

653-
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", compiler, target, builder);
654643
{
644+
let _guard = builder.msg_sysroot_tool(
645+
Kind::Test,
646+
stage,
647+
"miri (mir-opt-level 4)",
648+
host,
649+
target,
650+
);
655651
let _time = helpers::timeit(builder);
656652
builder.run(&mut cargo);
657653
}
@@ -660,42 +656,40 @@ impl Step for Miri {
660656
// # Run `cargo miri test`.
661657
// This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
662658
// that we get the desired output), but that is sufficient to make sure that the libtest harness
663-
// itself executes properly under Miri.
659+
// itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode.
660+
// This is running the build `cargo-miri` for the given target, so we need the target compiler.
664661
let mut cargo = tool::prepare_tool_cargo(
665662
builder,
666-
compiler,
667-
Mode::ToolRustc,
668-
host,
669-
"run",
670-
"src/tools/miri/cargo-miri",
663+
target_compiler,
664+
Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test!
665+
target,
666+
"miri-test",
667+
"src/tools/miri/test-cargo-miri",
671668
SourceType::Submodule,
672669
&[],
673670
);
674-
cargo.add_rustc_lib_path(builder);
675-
cargo.arg("--").arg("miri").arg("test");
676-
if builder.config.locked_deps {
677-
cargo.arg("--locked");
678-
}
679-
cargo
680-
.arg("--manifest-path")
681-
.arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
682-
cargo.arg("--target").arg(target.rustc_target_arg());
683-
cargo.arg("--").args(builder.config.test_args());
684671

685-
// `prepare_tool_cargo` sets RUSTDOC to the bootstrap wrapper and RUSTDOC_REAL to a dummy path as this is a "run", not a "test".
686-
// Also, we want the rustdoc from the "next" stage for the same reason that we build a std from the next stage.
687-
// So let's just set that here, and bypass bootstrap's RUSTDOC (just like cargo-miri already ignores bootstrap's RUSTC_WRAPPER).
688-
cargo.env("RUSTDOC", builder.rustdoc(compiler_std));
672+
// We're not using `prepare_cargo_test` so we have to do this ourselves.
673+
// (We're not using that as the test-cargo-miri crate is not known to bootstrap.)
674+
match builder.doc_tests {
675+
DocTests::Yes => {}
676+
DocTests::No => {
677+
cargo.args(["--lib", "--bins", "--examples", "--tests", "--benches"]);
678+
}
679+
DocTests::Only => {
680+
cargo.arg("--doc");
681+
}
682+
}
689683

690-
// Tell `cargo miri` where to find things.
684+
// Tell `cargo miri` where to find the sysroots.
691685
cargo.env("MIRI_SYSROOT", &miri_sysroot);
692686
cargo.env("MIRI_HOST_SYSROOT", sysroot);
693-
cargo.env("MIRI", &miri);
694-
// Debug things.
695-
cargo.env("RUST_BACKTRACE", "1");
696687

688+
// Finally, pass test-args and run everything.
689+
cargo.arg("--").args(builder.config.test_args());
697690
let mut cargo = Command::from(cargo);
698691
{
692+
let _guard = builder.msg_sysroot_tool(Kind::Test, stage, "cargo-miri", host, target);
699693
let _time = helpers::timeit(builder);
700694
builder.run(&mut cargo);
701695
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl Step for Rustdoc {
469469
features.push("jemalloc".to_string());
470470
}
471471

472-
let mut cargo = prepare_tool_cargo(
472+
let cargo = prepare_tool_cargo(
473473
builder,
474474
build_compiler,
475475
Mode::ToolRustc,
@@ -480,10 +480,6 @@ impl Step for Rustdoc {
480480
features.as_slice(),
481481
);
482482

483-
if builder.config.rustc_parallel {
484-
cargo.rustflag("--cfg=parallel_compiler");
485-
}
486-
487483
let _guard = builder.msg_tool(
488484
Mode::ToolRustc,
489485
"rustdoc",
@@ -732,7 +728,7 @@ impl Step for LlvmBitcodeLinker {
732728
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
733729
builder.ensure(compile::Rustc::new(self.compiler, self.target));
734730

735-
let mut cargo = prepare_tool_cargo(
731+
let cargo = prepare_tool_cargo(
736732
builder,
737733
self.compiler,
738734
Mode::ToolRustc,
@@ -743,10 +739,6 @@ impl Step for LlvmBitcodeLinker {
743739
&self.extra_features,
744740
);
745741

746-
if builder.config.rustc_parallel {
747-
cargo.rustflag("--cfg=parallel_compiler");
748-
}
749-
750742
builder.run(&mut cargo.into());
751743

752744
let tool_out = builder

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

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,10 @@ impl<'a> Builder<'a> {
10091009
StepDescription::run(v, self, paths);
10101010
}
10111011

1012-
/// Obtain a compiler at a given stage and for a given host. Explicitly does
1013-
/// not take `Compiler` since all `Compiler` instances are meant to be
1014-
/// obtained through this function, since it ensures that they are valid
1015-
/// (i.e., built and assembled).
1012+
/// Obtain a compiler at a given stage and for a given host (i.e., this is the target that the
1013+
/// compiler will run on, *not* the target it will build code for). Explicitly does not take
1014+
/// `Compiler` since all `Compiler` instances are meant to be obtained through this function,
1015+
/// since it ensures that they are valid (i.e., built and assembled).
10161016
pub fn compiler(&self, stage: u32, host: TargetSelection) -> Compiler {
10171017
self.ensure(compile::Assemble { target_compiler: Compiler { stage, host } })
10181018
}
@@ -1231,6 +1231,36 @@ impl<'a> Builder<'a> {
12311231
cmd
12321232
}
12331233

1234+
pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> Command {
1235+
assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0");
1236+
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
1237+
1238+
let miri = self.ensure(tool::Miri {
1239+
compiler: build_compiler,
1240+
target: self.build.build,
1241+
extra_features: Vec::new(),
1242+
});
1243+
let cargo_miri = self.ensure(tool::CargoMiri {
1244+
compiler: build_compiler,
1245+
target: self.build.build,
1246+
extra_features: Vec::new(),
1247+
});
1248+
// Invoke cargo-miri, make sure we can find miri and cargo.
1249+
let mut cmd = Command::new(cargo_miri);
1250+
cmd.env("MIRI", &miri);
1251+
cmd.env("CARGO", &self.initial_cargo);
1252+
// Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`,
1253+
// so they match the Miri we just built. However this means they are actually living one
1254+
// stage up, i.e. we are running `stage0-tools-bin/miri` with the libraries in `stage1/lib`.
1255+
// This is an unfortunate off-by-1 caused (possibly) by the fact that Miri doesn't have an
1256+
// "assemble" step like rustc does that would cross the stage boundary. We can't use
1257+
// `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries added to
1258+
// the PATH due to the stage mismatch.
1259+
// Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
1260+
add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
1261+
cmd
1262+
}
1263+
12341264
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
12351265
let mut cmd = Command::new(self.bootstrap_out.join("rustdoc"));
12361266
cmd.env("RUSTC_STAGE", compiler.stage.to_string())
@@ -1272,20 +1302,26 @@ impl<'a> Builder<'a> {
12721302
compiler: Compiler,
12731303
mode: Mode,
12741304
target: TargetSelection,
1275-
cmd: &str,
1305+
cmd: &str, // FIXME make this properly typed
12761306
) -> Command {
1277-
let mut cargo = if cmd == "clippy" {
1278-
self.cargo_clippy_cmd(compiler)
1307+
let mut cargo;
1308+
if cmd == "clippy" {
1309+
cargo = self.cargo_clippy_cmd(compiler);
1310+
cargo.arg(cmd);
1311+
} else if let Some(subcmd) = cmd.strip_prefix("miri-") {
1312+
cargo = self.cargo_miri_cmd(compiler);
1313+
cargo.arg("miri").arg(subcmd);
12791314
} else {
1280-
Command::new(&self.initial_cargo)
1281-
};
1315+
cargo = Command::new(&self.initial_cargo);
1316+
cargo.arg(cmd);
1317+
}
12821318

12831319
// Run cargo from the source root so it can find .cargo/config.
12841320
// This matters when using vendoring and the working directory is outside the repository.
12851321
cargo.current_dir(&self.src);
12861322

12871323
let out_dir = self.stage_out(compiler, mode);
1288-
cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd);
1324+
cargo.env("CARGO_TARGET_DIR", &out_dir);
12891325

12901326
// Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`
12911327
// from out of tree it shouldn't matter, since x.py is only used for
@@ -1315,7 +1351,8 @@ impl<'a> Builder<'a> {
13151351

13161352
if self.config.rust_optimize.is_release() {
13171353
// FIXME: cargo bench/install do not accept `--release`
1318-
if cmd != "bench" && cmd != "install" {
1354+
// and miri doesn't want it
1355+
if cmd != "bench" && cmd != "install" && !cmd.starts_with("miri-") {
13191356
cargo.arg("--release");
13201357
}
13211358
}
@@ -1331,14 +1368,15 @@ impl<'a> Builder<'a> {
13311368
/// Cargo. This cargo will be configured to use `compiler` as the actual
13321369
/// rustc compiler, its output will be scoped by `mode`'s output directory,
13331370
/// it will pass the `--target` flag for the specified `target`, and will be
1334-
/// executing the Cargo command `cmd`.
1371+
/// executing the Cargo command `cmd`. `cmd` can be `miri-cmd` for commands
1372+
/// to be run with Miri.
13351373
fn cargo(
13361374
&self,
13371375
compiler: Compiler,
13381376
mode: Mode,
13391377
source_type: SourceType,
13401378
target: TargetSelection,
1341-
cmd: &str,
1379+
cmd: &str, // FIXME make this properly typed
13421380
) -> Cargo {
13431381
let mut cargo = self.bare_cargo(compiler, mode, target, cmd);
13441382
let out_dir = self.stage_out(compiler, mode);
@@ -1649,7 +1687,8 @@ impl<'a> Builder<'a> {
16491687
.env("RUSTDOC", self.bootstrap_out.join("rustdoc"))
16501688
.env(
16511689
"RUSTDOC_REAL",
1652-
if cmd == "doc" || cmd == "rustdoc" || (cmd == "test" && want_rustdoc) {
1690+
// Make sure to handle both `test` and `miri-test` commands.
1691+
if cmd == "doc" || cmd == "rustdoc" || (cmd.ends_with("test") && want_rustdoc) {
16531692
self.rustdoc(compiler)
16541693
} else {
16551694
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
@@ -2045,6 +2084,15 @@ impl<'a> Builder<'a> {
20452084
rustflags.arg("-Zinline-mir");
20462085
}
20472086

2087+
if self.config.rustc_parallel
2088+
&& matches!(mode, Mode::ToolRustc | Mode::Rustc | Mode::Codegen)
2089+
{
2090+
// keep in sync with `bootstrap/lib.rs:Build::rustc_features`
2091+
// `cfg` option for rustc, `features` option for cargo, for conditional compilation
2092+
rustflags.arg("--cfg=parallel_compiler");
2093+
rustdocflags.arg("--cfg=parallel_compiler");
2094+
}
2095+
20482096
// set rustc args passed from command line
20492097
let rustc_args =
20502098
self.config.cmd.rustc_args().iter().map(|s| s.to_string()).collect::<Vec<_>>();
@@ -2309,7 +2357,7 @@ impl Cargo {
23092357
mode: Mode,
23102358
source_type: SourceType,
23112359
target: TargetSelection,
2312-
cmd: &str,
2360+
cmd: &str, // FIXME make this properly typed
23132361
) -> Cargo {
23142362
let mut cargo = builder.cargo(compiler, mode, source_type, target, cmd);
23152363
cargo.configure_linker(builder);
@@ -2323,7 +2371,7 @@ impl Cargo {
23232371
mode: Mode,
23242372
source_type: SourceType,
23252373
target: TargetSelection,
2326-
cmd: &str,
2374+
cmd: &str, // FIXME make this properly typed
23272375
) -> Cargo {
23282376
builder.cargo(compiler, mode, source_type, target, cmd)
23292377
}

‎src/bootstrap/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ pub enum Mode {
250250
/// directory. This is for miscellaneous sets of tools that are built
251251
/// using the bootstrap stage0 compiler in its entirety (target libraries
252252
/// and all). Typically these tools compile with stable Rust.
253+
///
254+
/// Only works for stage 0.
253255
ToolBootstrap,
254256

255257
/// Build a tool which uses the locally built std, placing output in the

‎src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# ignore-tidy-linelength
33

44
set -eu
5+
set -x # so one can see where we are in the script
56

67
X_PY="$1"
78

‎src/tools/miri/cargo-miri/src/phases.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
8989
let verbose = num_arg_flag("-v");
9090

9191
// Determine the involved architectures.
92-
let rustc_version = VersionMeta::for_command(miri_for_host())
93-
.expect("failed to determine underlying rustc version of Miri");
92+
let rustc_version = VersionMeta::for_command(miri_for_host()).unwrap_or_else(|err| {
93+
panic!(
94+
"failed to determine underlying rustc version of Miri ({:?}):\n{err:?}",
95+
miri_for_host()
96+
)
97+
});
9498
let host = &rustc_version.host;
9599
let target = get_arg_flag_value("--target");
96100
let target = target.as_ref().unwrap_or(host);
@@ -222,7 +226,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
222226
}
223227

224228
// Run cargo.
225-
debug_cmd("[cargo-miri miri]", verbose, &cmd);
229+
debug_cmd("[cargo-miri cargo]", verbose, &cmd);
226230
exec(cmd)
227231
}
228232

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ pub fn setup(
9090
let cargo_cmd = {
9191
let mut command = cargo();
9292
// Use Miri as rustc to build a libstd compatible with us (and use the right flags).
93+
// We set ourselves (`cargo-miri`) instead of Miri directly to be able to patch the flags
94+
// for `libpanic_abort` (usually this is done by bootstrap but we have to do it ourselves).
95+
// The `MIRI_CALLED_FROM_SETUP` will mean we dispatch to `phase_setup_rustc`.
9396
// However, when we are running in bootstrap, we cannot just overwrite `RUSTC`,
9497
// because we still need bootstrap to distinguish between host and target crates.
9598
// In that case we overwrite `RUSTC_REAL` instead which determines the rustc used
9699
// for target crates.
97-
// We set ourselves (`cargo-miri`) instead of Miri directly to be able to patch the flags
98-
// for `libpanic_abort` (usually this is done by bootstrap but we have to do it ourselves).
99-
// The `MIRI_CALLED_FROM_SETUP` will mean we dispatch to `phase_setup_rustc`.
100100
let cargo_miri_path = std::env::current_exe().expect("current executable path invalid");
101101
if env::var_os("RUSTC_STAGE").is_some() {
102102
assert!(env::var_os("RUSTC").is_some());

0 commit comments

Comments
 (0)
Please sign in to comment.