Skip to content

Commit 2558413

Browse files
committed
refactor ToolBuild to handle compiler tool stages
Signed-off-by: onur-ozkan <[email protected]>
1 parent 7daf4cf commit 2558413

File tree

1 file changed

+26
-25
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+26
-25
lines changed

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

+26-25
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,33 @@ impl Step for ToolBuild {
7171
///
7272
/// This will build the specified tool with the specified `host` compiler in
7373
/// `stage` into the normal cargo output directory.
74-
fn run(self, builder: &Builder<'_>) -> PathBuf {
75-
let compiler = self.compiler;
76-
let target = self.target;
77-
let mut tool = self.tool;
78-
let path = self.path;
79-
74+
fn run(mut self, builder: &Builder<'_>) -> PathBuf {
8075
match self.mode {
8176
Mode::ToolRustc => {
82-
builder.ensure(compile::Std::new(compiler, compiler.host));
83-
builder.ensure(compile::Rustc::new(compiler, target));
77+
assert!(
78+
self.compiler.stage > 0,
79+
"stage0 isn't supported for `Mode::ToolRustc` programs"
80+
);
81+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
82+
// we'd have stageN/bin/rustc and stageN/bin/$tool_name be effectively different stage
83+
// compilers, which isn't what we want.
84+
//
85+
// Compiler tools should be linked in the same way as the compiler it's paired with,
86+
// so it must be built with the previous stage compiler.
87+
self.compiler.stage -= 1
8488
}
85-
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)),
86-
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
89+
Mode::ToolStd => builder.ensure(compile::Std::new(self.compiler, self.target)),
90+
Mode::ToolBootstrap => {}
8791
_ => panic!("unexpected Mode for tool build"),
8892
}
8993

9094
let mut cargo = prepare_tool_cargo(
9195
builder,
92-
compiler,
96+
self.compiler,
9397
self.mode,
94-
target,
98+
self.target,
9599
Kind::Build,
96-
path,
100+
self.path,
97101
self.source_type,
98102
&self.extra_features,
99103
);
@@ -114,7 +118,7 @@ impl Step for ToolBuild {
114118
let build_success = compile::stream_cargo(builder, cargo, vec![], &mut |_| {});
115119

116120
builder.save_toolstate(
117-
tool,
121+
self.tool,
118122
if build_success { ToolState::TestFail } else { ToolState::BuildFail },
119123
);
120124

@@ -124,10 +128,10 @@ impl Step for ToolBuild {
124128
// HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
125129
// compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
126130
// different so the problem doesn't come up.
127-
if tool == "tidy" {
128-
tool = "rust-tidy";
131+
if self.tool == "tidy" {
132+
self.tool = "rust-tidy";
129133
}
130-
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool)
134+
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, self.tool)
131135
}
132136
}
133137
}
@@ -679,9 +683,9 @@ impl Step for Rustdoc {
679683
);
680684
cargo.into_cmd().run(builder);
681685

682-
// Cargo adds a number of paths to the dylib search path on windows, which results in
683-
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
684-
// rustdoc a different name.
686+
// Cargo adds a number of paths to the dylib search path on windows, which results in
687+
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
688+
// rustdoc a different name.
685689
let tool_rustdoc = builder
686690
.cargo_out(build_compiler, Mode::ToolRustc, target)
687691
.join(exe("rustdoc_tool_binary", target_compiler.host));
@@ -1107,7 +1111,7 @@ fn run_tool_build_step(
11071111
path: &'static str,
11081112
add_bins_to_sysroot: Option<&[&str]>,
11091113
) -> PathBuf {
1110-
let tool = builder.ensure(ToolBuild {
1114+
let bin_source = builder.ensure(ToolBuild {
11111115
compiler,
11121116
target,
11131117
tool: tool_name,
@@ -1126,18 +1130,15 @@ fn run_tool_build_step(
11261130
let bindir = builder.sysroot(compiler).join("bin");
11271131
t!(fs::create_dir_all(&bindir));
11281132

1129-
let tools_out = builder.cargo_out(compiler, Mode::ToolRustc, target);
1130-
11311133
for add_bin in add_bins_to_sysroot {
1132-
let bin_source = tools_out.join(exe(add_bin, target));
11331134
let bin_destination = bindir.join(exe(add_bin, compiler.host));
11341135
builder.copy_link(&bin_source, &bin_destination);
11351136
}
11361137

11371138
// Return a path into the bin dir.
11381139
bindir.join(exe(tool_name, compiler.host))
11391140
} else {
1140-
tool
1141+
bin_source
11411142
}
11421143
}
11431144

0 commit comments

Comments
 (0)