Skip to content

Commit ef41cf0

Browse files
committed
Compile stage0 tools with the raw bootstrap compiler
This commit updates the stage0 build of tools to use the libraries of the stage0 compiler instead of the compiled libraries by the stage0 compiler. This should enable us to avoid any stage0 hacks (like missing SIMD).
1 parent fb97bb5 commit ef41cf0

File tree

7 files changed

+73
-29
lines changed

7 files changed

+73
-29
lines changed

src/bootstrap/builder.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,22 @@ impl<'a> Builder<'a> {
769769

770770
let want_rustdoc = self.doc_tests != DocTests::No;
771771

772+
// We synthetically interpret a stage0 compiler used to build tools as a
773+
// "raw" compiler in that it's the exact snapshot we download. Normally
774+
// the stage0 build means it uses libraries build by the stage0
775+
// compiler, but for tools we just use the precompiled libraries that
776+
// we've downloaded
777+
let use_snapshot = mode == Mode::ToolBootstrap;
778+
assert!(!use_snapshot || stage == 0);
779+
780+
let maybe_sysroot = self.sysroot(compiler);
781+
let sysroot = if use_snapshot {
782+
self.rustc_snapshot_sysroot()
783+
} else {
784+
&maybe_sysroot
785+
};
786+
let libdir = sysroot.join(libdir(&compiler.host));
787+
772788
// Customize the compiler we're running. Specify the compiler to cargo
773789
// as our shim and then pass it some various options used to configure
774790
// how the actual compiler itself is called.
@@ -784,8 +800,8 @@ impl<'a> Builder<'a> {
784800
"RUSTC_DEBUG_ASSERTIONS",
785801
self.config.rust_debug_assertions.to_string(),
786802
)
787-
.env("RUSTC_SYSROOT", self.sysroot(compiler))
788-
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
803+
.env("RUSTC_SYSROOT", &sysroot)
804+
.env("RUSTC_LIBDIR", &libdir)
789805
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
790806
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
791807
.env(
@@ -809,7 +825,7 @@ impl<'a> Builder<'a> {
809825
cargo.env("RUSTC_ERROR_FORMAT", error_format);
810826
}
811827
if cmd != "build" && cmd != "check" && want_rustdoc {
812-
cargo.env("RUSTDOC_LIBDIR", self.sysroot_libdir(compiler, self.config.build));
828+
cargo.env("RUSTDOC_LIBDIR", &libdir);
813829
}
814830

815831
if mode.is_tool() {

src/bootstrap/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,5 +273,6 @@ fn codegen_backend_stamp(builder: &Builder,
273273
/// Cargo's output path for rustdoc in a given stage, compiled by a particular
274274
/// compiler for the specified target.
275275
pub fn rustdoc_stamp(builder: &Builder, compiler: Compiler, target: Interned<String>) -> PathBuf {
276-
builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rustdoc-check.stamp")
276+
builder.cargo_out(compiler, Mode::ToolRustc, target)
277+
.join(".rustdoc-check.stamp")
277278
}

src/bootstrap/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ impl Step for PlainSourceTarball {
957957
if !has_cargo_vendor {
958958
let mut cmd = builder.cargo(
959959
builder.compiler(0, builder.config.build),
960-
Mode::ToolRustc,
960+
Mode::ToolBootstrap,
961961
builder.config.build,
962962
"install"
963963
);

src/bootstrap/doc.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,14 +799,22 @@ impl Step for Rustdoc {
799799
builder.ensure(tool::Rustdoc { host: compiler.host });
800800

801801
// Symlink compiler docs to the output directory of rustdoc documentation.
802-
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");
802+
let out_dir = builder.stage_out(compiler, Mode::ToolRustc)
803+
.join(target)
804+
.join("doc");
803805
t!(fs::create_dir_all(&out_dir));
804806
builder.clear_if_dirty(&out, &rustdoc);
805807
t!(symlink_dir_force(&builder.config, &out, &out_dir));
806808

807809
// Build cargo command.
808810
let mut cargo = prepare_tool_cargo(
809-
builder, compiler, Mode::ToolRustc, target, "doc", "src/tools/rustdoc");
811+
builder,
812+
compiler,
813+
Mode::ToolRustc,
814+
target,
815+
"doc",
816+
"src/tools/rustdoc",
817+
);
810818

811819
cargo.env("RUSTDOCFLAGS", "--document-private-items");
812820
builder.run(&mut cargo);

src/bootstrap/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,22 @@ pub enum Mode {
328328
/// Build codegen libraries, placing output in the "stageN-codegen" directory
329329
Codegen,
330330

331-
/// Build some tools, placing output in the "stageN-tools" directory.
332-
ToolStd,
333-
ToolTest,
331+
/// Build some tools, placing output in the "stageN-tools" directory. The
332+
/// "other" here is for miscellaneous sets of tools that are built using the
333+
/// bootstrap compiler in its entirety (target libraries and all).
334+
/// Typically these tools compile with stable Rust.
335+
ToolBootstrap,
336+
337+
/// Compile a tool which uses all libraries we compile (up to rustc).
338+
/// Doesn't use the stage0 compiler libraries like "other", and includes
339+
/// tools like rustdoc, cargo, rls, etc.
334340
ToolRustc,
335341
}
336342

337343
impl Mode {
338344
pub fn is_tool(&self) -> bool {
339345
match self {
340-
Mode::ToolStd | Mode::ToolTest | Mode::ToolRustc => true,
346+
Mode::ToolBootstrap | Mode::ToolRustc => true,
341347
_ => false
342348
}
343349
}
@@ -547,7 +553,8 @@ impl Build {
547553
Mode::Test => "-test",
548554
Mode::Codegen => "-rustc",
549555
Mode::Rustc => "-rustc",
550-
Mode::ToolStd | Mode::ToolTest | Mode::ToolRustc => "-tools",
556+
Mode::ToolBootstrap => "-bootstrap-tools",
557+
Mode::ToolRustc => "-tools",
551558
};
552559
self.out.join(&*compiler.host)
553560
.join(format!("stage{}{}", compiler.stage, suffix))
@@ -656,8 +663,12 @@ impl Build {
656663

657664
/// Returns the libdir of the snapshot compiler.
658665
fn rustc_snapshot_libdir(&self) -> PathBuf {
666+
self.rustc_snapshot_sysroot().join(libdir(&self.config.build))
667+
}
668+
669+
/// Returns the sysroot of the snapshot compiler.
670+
fn rustc_snapshot_sysroot(&self) -> &Path {
659671
self.initial_rustc.parent().unwrap().parent().unwrap()
660-
.join(libdir(&self.config.build))
661672
}
662673

663674
/// Runs a command, printing out nice contextual information if it fails.

src/bootstrap/test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,10 @@ impl Step for RemoteCopyLibs {
18061806
builder.info(&format!("REMOTE copy libs to emulator ({})", target));
18071807
t!(fs::create_dir_all(builder.out.join("tmp")));
18081808

1809-
let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1809+
let server = builder.ensure(tool::RemoteTestServer {
1810+
compiler: compiler.with_stage(0),
1811+
target,
1812+
});
18101813

18111814
// Spawn the emulator and wait for it to come online
18121815
let tool = builder.tool_exe(Tool::RemoteTestClient);

src/bootstrap/tool.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ impl Step for ToolBuild {
104104
let is_ext_tool = self.is_ext_tool;
105105

106106
match self.mode {
107-
Mode::ToolStd => builder.ensure(compile::Std { compiler, target }),
108-
Mode::ToolTest => builder.ensure(compile::Test { compiler, target }),
109-
Mode::ToolRustc => builder.ensure(compile::Rustc { compiler, target }),
107+
Mode::ToolRustc => {
108+
builder.ensure(compile::Rustc { compiler, target })
109+
}
110+
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
110111
_ => panic!("unexpected Mode for tool build")
111112
}
112113

@@ -341,17 +342,17 @@ macro_rules! tool {
341342
}
342343

343344
tool!(
344-
Rustbook, "src/tools/rustbook", "rustbook", Mode::ToolRustc;
345+
Rustbook, "src/tools/rustbook", "rustbook", Mode::ToolBootstrap;
345346
ErrorIndex, "src/tools/error_index_generator", "error_index_generator", Mode::ToolRustc;
346-
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolStd;
347-
Tidy, "src/tools/tidy", "tidy", Mode::ToolStd;
348-
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolStd;
349-
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolStd;
350-
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolTest, llvm_tools = true;
351-
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolStd;
352-
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolStd;
353-
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolStd;
354-
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolStd;
347+
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen", Mode::ToolBootstrap;
348+
Tidy, "src/tools/tidy", "tidy", Mode::ToolBootstrap;
349+
Linkchecker, "src/tools/linkchecker", "linkchecker", Mode::ToolBootstrap;
350+
CargoTest, "src/tools/cargotest", "cargotest", Mode::ToolBootstrap;
351+
Compiletest, "src/tools/compiletest", "compiletest", Mode::ToolBootstrap, llvm_tools = true;
352+
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::ToolBootstrap;
353+
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client", Mode::ToolBootstrap;
354+
RustInstaller, "src/tools/rust-installer", "fabricate", Mode::ToolBootstrap;
355+
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes", Mode::ToolBootstrap;
355356
);
356357

357358
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
@@ -379,7 +380,7 @@ impl Step for RemoteTestServer {
379380
compiler: self.compiler,
380381
target: self.target,
381382
tool: "remote-test-server",
382-
mode: Mode::ToolStd,
383+
mode: Mode::ToolBootstrap,
383384
path: "src/tools/remote-test-server",
384385
is_ext_tool: false,
385386
extra_features: Vec::new(),
@@ -604,7 +605,11 @@ impl<'a> Builder<'a> {
604605
fn prepare_tool_cmd(&self, compiler: Compiler, tool: Tool, cmd: &mut Command) {
605606
let host = &compiler.host;
606607
let mut lib_paths: Vec<PathBuf> = vec![
607-
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host)),
608+
if compiler.stage == 0 {
609+
self.build.rustc_snapshot_libdir()
610+
} else {
611+
PathBuf::from(&self.sysroot_libdir(compiler, compiler.host))
612+
},
608613
self.cargo_out(compiler, tool.get_mode(), *host).join("deps"),
609614
];
610615

0 commit comments

Comments
 (0)