Skip to content
Permalink
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.
  • Loading branch information...
Mark-Simulacrum committed Mar 3, 2019
1 parent c0086b9 commit 9efc93c96dd6746460cef916d307b72ba21a7fd0
Showing with 78 additions and 42 deletions.
  1. +5 −1 src/bootstrap/doc.rs
  2. +5 −5 src/bootstrap/test.rs
  3. +68 −36 src/bootstrap/tool.rs
@@ -883,7 +883,11 @@ impl Step for ErrorIndex {
builder.info(&format!("Documenting error index ({})", target));
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
let mut index = builder.tool_cmd(Tool::ErrorIndex);
let compiler = builder.compiler(2, builder.config.build);
let mut index = tool::ErrorIndex::command(
builder,
compiler,
);
index.arg("html");
index.arg(out.join("error-index.html"));

@@ -414,7 +414,6 @@ impl Step for Miri {

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct CompiletestTest {
stage: u32,
host: Interned<String>,
}

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

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(CompiletestTest {
stage: run.builder.top_stage,
host: run.target,
});
}

/// Runs `cargo test` for compiletest.
fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let host = self.host;
let compiler = builder.compiler(stage, host);
let compiler = builder.compiler(0, host);

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

let mut tool = builder.tool_cmd(Tool::ErrorIndex);
let mut tool = tool::ErrorIndex::command(
builder,
builder.compiler(compiler.stage, builder.config.build),
);
tool.arg("markdown")
.arg(&output)
.env("CFG_BUILD", &builder.config.build)
@@ -250,9 +250,9 @@ pub fn prepare_tool_cargo(
cargo
}

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

impl Tool {
pub fn get_mode(&self) -> Mode {
let mode = match self {
$(Tool::$name => $mode,)+
};
mode
Mode::ToolBootstrap
}

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

impl<'a> Builder<'a> {
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
let stage = self.tool_default_stage(tool);
match tool {
$(Tool::$name =>
self.ensure($name {
compiler: self.compiler(stage, self.config.build),
compiler: self.compiler(0, self.config.build),
target: self.config.build,
}),
)+
}
}

pub fn tool_default_stage(&self, tool: Tool) -> u32 {
// Compile the error-index in the same stage as rustdoc to avoid
// recompiling rustdoc twice if we can. Otherwise compile
// everything else in stage0 as there's no need to rebootstrap
// everything.
match tool {
Tool::ErrorIndex if self.top_stage >= 2 => self.top_stage,
_ => 0,
}
}
}

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

fn make_run(run: RunConfig<'_>) {
run.builder.ensure($name {
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
// snapshot compiler
compiler: run.builder.compiler(0, run.builder.config.build),
target: run.target,
});
}
@@ -331,7 +317,7 @@ macro_rules! tool {
compiler: self.compiler,
target: self.target,
tool: $tool_name,
mode: $mode,
mode: Mode::ToolBootstrap,
path: $path,
is_optional_tool: false,
source_type: if false $(|| $external)* {
@@ -347,21 +333,67 @@ macro_rules! tool {
}
}

tool!(
Rustbook, "src/tools/rustbook", "rustbook", Mode::ToolBootstrap;
ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::ToolRustc;
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolBootstrap;
Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolBootstrap;
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap;
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true;
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap,
is_external_tool = true;
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolBootstrap;
bootstrap_tool!(
Rustbook, "src/tools/rustbook", "rustbook";
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
Tidy, "src/tools/tidy", "tidy";
Linkchecker, "src/tools/linkchecker", "linkchecker";
CargoTest, "src/tools/cargotest", "cargotest";
Compiletest, "src/tools/compiletest", "compiletest", llvm_tools = true;
BuildManifest, "src/tools/build-manifest", "build-manifest";
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
);

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ErrorIndex {
pub compiler: Compiler,
}

impl ErrorIndex {
pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command {
let mut cmd = Command::new(builder.ensure(ErrorIndex {
compiler
}));
add_lib_path(
vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))],
&mut cmd,
);
cmd
}
}

impl Step for ErrorIndex {
type Output = PathBuf;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/error_index_generator")
}

fn make_run(run: RunConfig<'_>) {
// Compile the error-index in the same stage as rustdoc to avoid
// recompiling rustdoc twice if we can.
let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 };
run.builder.ensure(ErrorIndex {
compiler: run.builder.compiler(stage, run.builder.config.build),
});
}

fn run(self, builder: &Builder<'_>) -> PathBuf {
builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.compiler.host,
tool: "error_index_generator",
mode: Mode::ToolRustc,
path: "src/tools/error_index_generator",
is_optional_tool: false,
source_type: SourceType::InTree,
extra_features: Vec::new(),
}).expect("expected to build -- essential tool")
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RemoteTestServer {
pub compiler: Compiler,
@@ -625,7 +657,7 @@ impl<'a> Builder<'a> {
/// `host`.
pub fn tool_cmd(&self, tool: Tool) -> Command {
let mut cmd = Command::new(self.tool_exe(tool));
let compiler = self.compiler(self.tool_default_stage(tool), self.config.build);
let compiler = self.compiler(0, self.config.build);
self.prepare_tool_cmd(compiler, tool, &mut cmd);
cmd
}
@@ -637,7 +669,7 @@ impl<'a> Builder<'a> {
fn prepare_tool_cmd(&self, compiler: Compiler, tool: Tool, cmd: &mut Command) {
let host = &compiler.host;
let mut lib_paths: Vec<PathBuf> = vec![
if compiler.stage == 0 && tool != Tool::ErrorIndex {
if compiler.stage == 0 {
self.build.rustc_snapshot_libdir()
} else {
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host))

0 comments on commit 9efc93c

Please sign in to comment.
You can’t perform that action at this time.