Skip to content

Commit 6cf650f

Browse files
committed
remove manually handled stage offs
Signed-off-by: onur-ozkan <[email protected]>
1 parent a338439 commit 6cf650f

File tree

4 files changed

+24
-49
lines changed

4 files changed

+24
-49
lines changed

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ impl Step for Miri {
126126

127127
// This compiler runs on the host, we'll just use it for the target.
128128
let target_compiler = builder.compiler(stage, host);
129-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
130-
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
131-
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
132-
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
133-
let host_compiler = builder.compiler(stage - 1, host);
129+
let host_compiler = tool::get_tool_rustc_compiler(builder, target_compiler);
134130

135131
// Get a target sysroot for Miri.
136132
let miri_sysroot = test::Miri::build_miri_sysroot(builder, target_compiler, target);

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

+5-20
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,11 @@ impl Step for Miri {
523523

524524
// This compiler runs on the host, we'll just use it for the target.
525525
let target_compiler = builder.compiler(stage, host);
526-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
527-
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
528-
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
529-
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
530-
let host_compiler = builder.compiler(stage - 1, host);
531526

532527
// Build our tools.
533-
let miri = builder.ensure(tool::Miri { compiler: host_compiler, target: host });
528+
let miri = builder.ensure(tool::Miri { compiler: target_compiler, target: host });
534529
// the ui tests also assume cargo-miri has been built
535-
builder.ensure(tool::CargoMiri { compiler: host_compiler, target: host });
530+
builder.ensure(tool::CargoMiri { compiler: target_compiler, target: host });
536531

537532
// We also need sysroots, for Miri and for the host (the latter for build scripts).
538533
// This is for the tests so everything is done with the target compiler.
@@ -543,7 +538,8 @@ impl Step for Miri {
543538
// Miri has its own "target dir" for ui test dependencies. Make sure it gets cleared when
544539
// the sysroot gets rebuilt, to avoid "found possibly newer version of crate `std`" errors.
545540
if !builder.config.dry_run() {
546-
let ui_test_dep_dir = builder.stage_out(host_compiler, Mode::ToolStd).join("miri_ui");
541+
let ui_test_dep_dir =
542+
builder.stage_out(miri.build_compiler, Mode::ToolStd).join("miri_ui");
547543
// The mtime of `miri_sysroot` changes when the sysroot gets rebuilt (also see
548544
// <https://github.com/RalfJung/rustc-build-sysroot/commit/10ebcf60b80fe2c3dc765af0ff19fdc0da4b7466>).
549545
// We can hence use that directly as a signal to clear the ui test dir.
@@ -554,7 +550,7 @@ impl Step for Miri {
554550
// This is with the Miri crate, so it uses the host compiler.
555551
let mut cargo = tool::prepare_tool_cargo(
556552
builder,
557-
host_compiler,
553+
miri.build_compiler,
558554
Mode::ToolRustc,
559555
host,
560556
Kind::Test,
@@ -1722,17 +1718,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17221718
// If we're using `--stage 0`, we should provide the bootstrap cargo.
17231719
builder.initial_cargo.clone()
17241720
} else {
1725-
// We need to properly build cargo using the suitable stage compiler.
1726-
1727-
let compiler = builder.download_rustc().then_some(compiler).unwrap_or_else(||
1728-
// HACK: currently tool stages are off-by-one compared to compiler stages, i.e. if
1729-
// you give `tool::Cargo` a stage 1 rustc, it will cause stage 2 rustc to be built
1730-
// and produce a cargo built with stage 2 rustc. To fix this, we need to chop off
1731-
// the compiler stage by 1 to align with expected `./x test run-make --stage N`
1732-
// behavior, i.e. we need to pass `N - 1` compiler stage to cargo. See also Miri
1733-
// which does a similar hack.
1734-
builder.compiler(builder.top_stage - 1, compiler.host));
1735-
17361721
builder.ensure(tool::Cargo { compiler, target: compiler.host })
17371722
};
17381723

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ pub fn prepare_tool_cargo(
274274
cargo
275275
}
276276

277-
fn get_tool_rustc_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Compiler {
277+
pub(crate) fn get_tool_rustc_compiler(
278+
builder: &Builder<'_>,
279+
target_compiler: Compiler,
280+
) -> Compiler {
278281
if builder.download_rustc() && target_compiler.stage == 1 {
279282
// We already have the stage 1 compiler, we don't need to cut the stage.
280283
builder.compiler(target_compiler.stage, builder.config.build)
@@ -555,8 +558,7 @@ impl Step for ErrorIndex {
555558
// src/tools/error-index-generator` which almost nobody does.
556559
// Normally, `x.py test` or `x.py doc` will use the
557560
// `ErrorIndex::command` function instead.
558-
let compiler =
559-
run.builder.compiler(run.builder.top_stage.saturating_sub(1), run.builder.config.build);
561+
let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
560562
run.builder.ensure(ErrorIndex { compiler });
561563
}
562564

@@ -631,13 +633,8 @@ impl Step for Rustdoc {
631633
}
632634

633635
fn make_run(run: RunConfig<'_>) {
634-
run.builder.ensure(Rustdoc {
635-
// NOTE: this is somewhat unique in that we actually want a *target*
636-
// compiler here, because rustdoc *is* a compiler. We won't be using
637-
// this as the compiler to build with, but rather this is "what
638-
// compiler are we producing"?
639-
compiler: run.builder.compiler(run.builder.top_stage, run.target),
640-
});
636+
run.builder
637+
.ensure(Rustdoc { compiler: run.builder.compiler(run.builder.top_stage, run.target) });
641638
}
642639

643640
fn run(self, builder: &Builder<'_>) -> PathBuf {

src/bootstrap/src/core/builder/mod.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1408,10 +1408,9 @@ impl<'a> Builder<'a> {
14081408
return cmd;
14091409
}
14101410

1411-
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
1412-
self.ensure(tool::Clippy { compiler: build_compiler, target: self.build.build });
1411+
let _ = self.ensure(tool::Clippy { compiler: run_compiler, target: self.build.build });
14131412
let cargo_clippy =
1414-
self.ensure(tool::CargoClippy { compiler: build_compiler, target: self.build.build });
1413+
self.ensure(tool::CargoClippy { compiler: run_compiler, target: self.build.build });
14151414
let mut dylib_path = helpers::dylib_path();
14161415
dylib_path.insert(0, self.sysroot(run_compiler).join("lib"));
14171416

@@ -1423,23 +1422,21 @@ impl<'a> Builder<'a> {
14231422

14241423
pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
14251424
assert!(run_compiler.stage > 0, "miri can not be invoked at stage 0");
1426-
let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build);
1427-
14281425
// Prepare the tools
1429-
let miri = self.ensure(tool::Miri { compiler: build_compiler, target: self.build.build });
1426+
let miri = self.ensure(tool::Miri { compiler: run_compiler, target: self.build.build });
14301427
let cargo_miri =
1431-
self.ensure(tool::CargoMiri { compiler: build_compiler, target: self.build.build });
1428+
self.ensure(tool::CargoMiri { compiler: run_compiler, target: self.build.build });
14321429
// Invoke cargo-miri, make sure it can find miri and cargo.
14331430
let mut cmd = command(cargo_miri.tool_path);
14341431
cmd.env("MIRI", &miri.tool_path);
14351432
cmd.env("CARGO", &self.initial_cargo);
1436-
// Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`,
1437-
// so they match the Miri we just built. However this means they are actually living one
1438-
// stage up, i.e. we are running `stage0-tools-bin/miri` with the libraries in `stage1/lib`.
1439-
// This is an unfortunate off-by-1 caused (possibly) by the fact that Miri doesn't have an
1440-
// "assemble" step like rustc does that would cross the stage boundary. We can't use
1441-
// `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries added to
1442-
// the PATH due to the stage mismatch.
1433+
// Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`
1434+
// in `tool::ToolBuild` step, so they match the Miri we just built. However this means they
1435+
// are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the
1436+
// libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact
1437+
// that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary.
1438+
// We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries
1439+
// added to the PATH due to the stage mismatch.
14431440
// Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
14441441
add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
14451442
cmd

0 commit comments

Comments
 (0)