Skip to content

Commit 9efc93c

Browse files
Tools built by the bootstrap compiler must be built by it
This avoids building compilers that we don't need -- most tools will work just fine with the downloaded compiler.
1 parent c0086b9 commit 9efc93c

File tree

3 files changed

+78
-42
lines changed

3 files changed

+78
-42
lines changed

src/bootstrap/doc.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,11 @@ impl Step for ErrorIndex {
883883
builder.info(&format!("Documenting error index ({})", target));
884884
let out = builder.doc_out(target);
885885
t!(fs::create_dir_all(&out));
886-
let mut index = builder.tool_cmd(Tool::ErrorIndex);
886+
let compiler = builder.compiler(2, builder.config.build);
887+
let mut index = tool::ErrorIndex::command(
888+
builder,
889+
compiler,
890+
);
887891
index.arg("html");
888892
index.arg(out.join("error-index.html"));
889893

src/bootstrap/test.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ impl Step for Miri {
414414

415415
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
416416
pub struct CompiletestTest {
417-
stage: u32,
418417
host: Interned<String>,
419418
}
420419

@@ -427,16 +426,14 @@ impl Step for CompiletestTest {
427426

428427
fn make_run(run: RunConfig<'_>) {
429428
run.builder.ensure(CompiletestTest {
430-
stage: run.builder.top_stage,
431429
host: run.target,
432430
});
433431
}
434432

435433
/// Runs `cargo test` for compiletest.
436434
fn run(self, builder: &Builder<'_>) {
437-
let stage = self.stage;
438435
let host = self.host;
439-
let compiler = builder.compiler(stage, host);
436+
let compiler = builder.compiler(0, host);
440437

441438
let mut cargo = tool::prepare_tool_cargo(builder,
442439
compiler,
@@ -1426,7 +1423,10 @@ impl Step for ErrorIndex {
14261423
t!(fs::create_dir_all(&dir));
14271424
let output = dir.join("error-index.md");
14281425

1429-
let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1426+
let mut tool = tool::ErrorIndex::command(
1427+
builder,
1428+
builder.compiler(compiler.stage, builder.config.build),
1429+
);
14301430
tool.arg("markdown")
14311431
.arg(&output)
14321432
.env("CFG_BUILD", &builder.config.build)

src/bootstrap/tool.rs

+68-36
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ pub fn prepare_tool_cargo(
250250
cargo
251251
}
252252

253-
macro_rules! tool {
253+
macro_rules! bootstrap_tool {
254254
($(
255-
$name:ident, $path:expr, $tool_name:expr, $mode:expr
255+
$name:ident, $path:expr, $tool_name:expr
256256
$(,llvm_tools = $llvm:expr)*
257257
$(,is_external_tool = $external:expr)*
258258
;
@@ -266,10 +266,7 @@ macro_rules! tool {
266266

267267
impl Tool {
268268
pub fn get_mode(&self) -> Mode {
269-
let mode = match self {
270-
$(Tool::$name => $mode,)+
271-
};
272-
mode
269+
Mode::ToolBootstrap
273270
}
274271

275272
/// Whether this tool requires LLVM to run
@@ -282,27 +279,15 @@ macro_rules! tool {
282279

283280
impl<'a> Builder<'a> {
284281
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
285-
let stage = self.tool_default_stage(tool);
286282
match tool {
287283
$(Tool::$name =>
288284
self.ensure($name {
289-
compiler: self.compiler(stage, self.config.build),
285+
compiler: self.compiler(0, self.config.build),
290286
target: self.config.build,
291287
}),
292288
)+
293289
}
294290
}
295-
296-
pub fn tool_default_stage(&self, tool: Tool) -> u32 {
297-
// Compile the error-index in the same stage as rustdoc to avoid
298-
// recompiling rustdoc twice if we can. Otherwise compile
299-
// everything else in stage0 as there's no need to rebootstrap
300-
// everything.
301-
match tool {
302-
Tool::ErrorIndex if self.top_stage >= 2 => self.top_stage,
303-
_ => 0,
304-
}
305-
}
306291
}
307292

308293
$(
@@ -321,7 +306,8 @@ macro_rules! tool {
321306

322307
fn make_run(run: RunConfig<'_>) {
323308
run.builder.ensure($name {
324-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
309+
// snapshot compiler
310+
compiler: run.builder.compiler(0, run.builder.config.build),
325311
target: run.target,
326312
});
327313
}
@@ -331,7 +317,7 @@ macro_rules! tool {
331317
compiler: self.compiler,
332318
target: self.target,
333319
tool: $tool_name,
334-
mode: $mode,
320+
mode: Mode::ToolBootstrap,
335321
path: $path,
336322
is_optional_tool: false,
337323
source_type: if false $(|| $external)* {
@@ -347,21 +333,67 @@ macro_rules! tool {
347333
}
348334
}
349335

350-
tool!(
351-
Rustbook, "src/tools/rustbook", "rustbook", Mode::ToolBootstrap;
352-
ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::ToolRustc;
353-
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolBootstrap;
354-
Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
355-
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolBootstrap;
356-
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap;
357-
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true;
358-
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
359-
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
360-
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap,
361-
is_external_tool = true;
362-
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolBootstrap;
336+
bootstrap_tool!(
337+
Rustbook, "src/tools/rustbook", "rustbook";
338+
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
339+
Tidy, "src/tools/tidy", "tidy";
340+
Linkchecker, "src/tools/linkchecker", "linkchecker";
341+
CargoTest, "src/tools/cargotest", "cargotest";
342+
Compiletest, "src/tools/compiletest", "compiletest", llvm_tools = true;
343+
BuildManifest, "src/tools/build-manifest", "build-manifest";
344+
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
345+
RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
346+
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
363347
);
364348

349+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
350+
pub struct ErrorIndex {
351+
pub compiler: Compiler,
352+
}
353+
354+
impl ErrorIndex {
355+
pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
356+
let mut cmd = Command::new(builder.ensure(ErrorIndex {
357+
compiler
358+
}));
359+
add_lib_path(
360+
vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
361+
&mut cmd,
362+
);
363+
cmd
364+
}
365+
}
366+
367+
impl Step for ErrorIndex {
368+
type Output = PathBuf;
369+
370+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
371+
run.path("src/tools/error_index_generator")
372+
}
373+
374+
fn make_run(run: RunConfig<'_>) {
375+
// Compile the error-index in the same stage as rustdoc to avoid
376+
// recompiling rustdoc twice if we can.
377+
let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 };
378+
run.builder.ensure(ErrorIndex {
379+
compiler: run.builder.compiler(stage, run.builder.config.build),
380+
});
381+
}
382+
383+
fn run(self, builder: &Builder<'_>) -> PathBuf {
384+
builder.ensure(ToolBuild {
385+
compiler: self.compiler,
386+
target: self.compiler.host,
387+
tool: "error_index_generator",
388+
mode: Mode::ToolRustc,
389+
path: "src/tools/error_index_generator",
390+
is_optional_tool: false,
391+
source_type: SourceType::InTree,
392+
extra_features: Vec::new(),
393+
}).expect("expected to build -- essential tool")
394+
}
395+
}
396+
365397
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
366398
pub struct RemoteTestServer {
367399
pub compiler: Compiler,
@@ -625,7 +657,7 @@ impl<'a> Builder<'a> {
625657
/// `host`.
626658
pub fn tool_cmd(&self, tool: Tool) -> Command {
627659
let mut cmd = Command::new(self.tool_exe(tool));
628-
let compiler = self.compiler(self.tool_default_stage(tool), self.config.build);
660+
let compiler = self.compiler(0, self.config.build);
629661
self.prepare_tool_cmd(compiler, tool, &mut cmd);
630662
cmd
631663
}
@@ -637,7 +669,7 @@ impl<'a> Builder<'a> {
637669
fn prepare_tool_cmd(&self, compiler: Compiler, tool: Tool, cmd: &mut Command) {
638670
let host = &compiler.host;
639671
let mut lib_paths: Vec<PathBuf> = vec![
640-
if compiler.stage == 0 && tool != Tool::ErrorIndex {
672+
if compiler.stage == 0 {
641673
self.build.rustc_snapshot_libdir()
642674
} else {
643675
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host))

0 commit comments

Comments
 (0)