Skip to content

Commit 51623ec

Browse files
committed
let ToolBuild to handle compiler tool stages automatically
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent dafdcb7 commit 51623ec

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Step for Miri {
126126
// This compiler runs on the host, we'll just use it for the target.
127127
let target_compiler = builder.compiler(stage, host);
128128
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
129-
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
129+
// we'd have stageN/bin/rustc and stageN/bin/miri be effectively different stage
130130
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
131131
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
132132
let host_compiler = builder.compiler(stage - 1, host);

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -522,23 +522,24 @@ impl Step for Miri {
522522

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

531526
// Build our tools.
532-
let miri = builder.ensure(tool::Miri { compiler: host_compiler, target: host });
527+
let miri = builder.ensure(tool::Miri { compiler: target_compiler, target: host });
533528
// the ui tests also assume cargo-miri has been built
534-
builder.ensure(tool::CargoMiri { compiler: host_compiler, target: host });
529+
builder.ensure(tool::CargoMiri { compiler: target_compiler, target: host });
535530

536531
// We also need sysroots, for Miri and for the host (the latter for build scripts).
537532
// This is for the tests so everything is done with the target compiler.
538533
let miri_sysroot = Miri::build_miri_sysroot(builder, target_compiler, target);
539534
builder.ensure(compile::Std::new(target_compiler, host));
540535
let host_sysroot = builder.sysroot(target_compiler);
541536

537+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
538+
// we'd have stageN/bin/rustc and stageN/bin/miri be effectively different stage
539+
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
540+
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
541+
let host_compiler = builder.compiler(stage - 1, host);
542+
542543
// Miri has its own "target dir" for ui test dependencies. Make sure it gets cleared when
543544
// the sysroot gets rebuilt, to avoid "found possibly newer version of crate `std`" errors.
544545
if !builder.config.dry_run() {
@@ -1720,17 +1721,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17201721
// If we're using `--stage 0`, we should provide the bootstrap cargo.
17211722
builder.initial_cargo.clone()
17221723
} else {
1723-
// We need to properly build cargo using the suitable stage compiler.
1724-
1725-
let compiler = builder.download_rustc().then_some(compiler).unwrap_or_else(||
1726-
// HACK: currently tool stages are off-by-one compared to compiler stages, i.e. if
1727-
// you give `tool::Cargo` a stage 1 rustc, it will cause stage 2 rustc to be built
1728-
// and produce a cargo built with stage 2 rustc. To fix this, we need to chop off
1729-
// the compiler stage by 1 to align with expected `./x test run-make --stage N`
1730-
// behavior, i.e. we need to pass `N - 1` compiler stage to cargo. See also Miri
1731-
// which does a similar hack.
1732-
builder.compiler(builder.top_stage - 1, compiler.host));
1733-
17341724
builder.ensure(tool::Cargo { compiler, target: compiler.host })
17351725
};
17361726

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,8 +1395,8 @@ impl<'a> Builder<'a> {
13951395
self.ensure(tool::Rustdoc { compiler })
13961396
}
13971397

1398-
pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
1399-
if run_compiler.stage == 0 {
1398+
pub fn cargo_clippy_cmd(&self, compiler: Compiler) -> BootstrapCommand {
1399+
if compiler.stage == 0 {
14001400
let cargo_clippy = self
14011401
.config
14021402
.initial_cargo_clippy
@@ -1408,27 +1408,23 @@ 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 });
1413-
let cargo_clippy =
1414-
self.ensure(tool::CargoClippy { compiler: build_compiler, target: self.build.build });
1411+
self.ensure(tool::Clippy { compiler, target: self.build.build });
1412+
let cargo_clippy = self.ensure(tool::CargoClippy { compiler, target: self.build.build });
14151413
let mut dylib_path = helpers::dylib_path();
1416-
dylib_path.insert(0, self.sysroot(run_compiler).join("lib"));
1414+
dylib_path.insert(0, self.sysroot(compiler).join("lib"));
14171415

14181416
let mut cmd = command(cargo_clippy);
14191417
cmd.env(helpers::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
14201418
cmd.env("CARGO", &self.initial_cargo);
14211419
cmd
14221420
}
14231421

1424-
pub fn cargo_miri_cmd(&self, run_compiler: Compiler) -> BootstrapCommand {
1425-
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);
1422+
pub fn cargo_miri_cmd(&self, compiler: Compiler) -> BootstrapCommand {
1423+
assert!(compiler.stage > 0, "miri can not be invoked at stage 0");
14271424

14281425
// Prepare the tools
1429-
let miri = self.ensure(tool::Miri { compiler: build_compiler, target: self.build.build });
1430-
let cargo_miri =
1431-
self.ensure(tool::CargoMiri { compiler: build_compiler, target: self.build.build });
1426+
let miri = self.ensure(tool::Miri { compiler, target: self.build.build });
1427+
let cargo_miri = self.ensure(tool::CargoMiri { compiler, target: self.build.build });
14321428
// Invoke cargo-miri, make sure it can find miri and cargo.
14331429
let mut cmd = command(cargo_miri);
14341430
cmd.env("MIRI", &miri);
@@ -1441,7 +1437,7 @@ impl<'a> Builder<'a> {
14411437
// `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries added to
14421438
// the PATH due to the stage mismatch.
14431439
// Also see https://github.com/rust-lang/rust/pull/123192#issuecomment-2028901503.
1444-
add_dylib_path(self.rustc_lib_paths(run_compiler), &mut cmd);
1440+
add_dylib_path(self.rustc_lib_paths(compiler), &mut cmd);
14451441
cmd
14461442
}
14471443

0 commit comments

Comments
 (0)