Skip to content

Commit 6bf9288

Browse files
committed
use initial rustc's std on stage 0
On stage 0, rather than compiling std utilize the version from the initial rustc. Theoretically, stage 0 should represent the snapshot version not the compiled one. This makes bootstrapping quicker as well. Signed-off-by: onur-ozkan <[email protected]>
1 parent d73bd3f commit 6bf9288

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+22-17
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ impl Step for Std {
137137
let target = self.target;
138138
let compiler = self.compiler;
139139

140+
// We already have std ready to be used for stage 0.
141+
if compiler.stage == 0 {
142+
builder.ensure(StdLink::from_std(
143+
self,
144+
builder.compiler(compiler.stage, builder.config.build),
145+
));
146+
147+
return;
148+
}
149+
140150
// When using `download-rustc`, we already have artifacts for the host available. Don't
141151
// recompile them.
142152
if builder.download_rustc() && target == builder.build.build
@@ -585,18 +595,16 @@ impl Step for StdLink {
585595
(libdir, hostdir)
586596
};
587597

588-
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
598+
let is_downloaded_beta_stage0 = builder
599+
.build
600+
.config
601+
.initial_rustc
602+
.starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin"));
589603

590604
// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
591605
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
592606
// and is not set to a custom path.
593-
if compiler.stage == 0
594-
&& builder
595-
.build
596-
.config
597-
.initial_rustc
598-
.starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin"))
599-
{
607+
if compiler.stage == 0 && is_downloaded_beta_stage0 {
600608
// Copy bin files from stage0/bin to stage0-sysroot/bin
601609
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
602610

@@ -608,15 +616,7 @@ impl Step for StdLink {
608616

609617
// Copy all *.so files from stage0/lib to stage0-sysroot/lib
610618
let stage0_lib_dir = builder.out.join(&host).join("stage0/lib");
611-
if let Ok(files) = fs::read_dir(&stage0_lib_dir) {
612-
for file in files {
613-
let file = t!(file);
614-
let path = file.path();
615-
if path.is_file() && is_dylib(&file.file_name().into_string().unwrap()) {
616-
builder.copy(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
617-
}
618-
}
619-
}
619+
builder.cp_r(&stage0_lib_dir, &sysroot.join("lib"));
620620

621621
// Copy codegen-backends from stage0
622622
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);
@@ -630,6 +630,11 @@ impl Step for StdLink {
630630
if stage0_codegen_backends.exists() {
631631
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
632632
}
633+
} else if compiler.stage == 0 {
634+
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
635+
builder.cp_r(&builder.initial_sysroot.join("lib"), &sysroot.join("lib"));
636+
} else {
637+
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
633638
}
634639
}
635640
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl Step for Tidy {
11211121
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
11221122
builder.info("fmt check");
11231123
if builder.initial_rustfmt().is_none() {
1124-
let inferred_rustfmt_dir = builder.initial_rustc.parent().unwrap();
1124+
let inferred_rustfmt_dir = builder.initial_sysroot.join("bin");
11251125
eprintln!(
11261126
"\
11271127
ERROR: no `rustfmt` binary found in {PATH}

src/bootstrap/src/core/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ impl<'a> Builder<'a> {
11671167
}
11681168

11691169
pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> Command {
1170-
let initial_sysroot_bin = self.initial_rustc.parent().unwrap();
1170+
let initial_sysroot_bin = self.initial_sysroot.join("bin");
11711171
// Set PATH to include the sysroot bin dir so clippy can find cargo.
11721172
// FIXME: once rust-clippy#11944 lands on beta, set `CARGO` directly instead.
11731173
let path = t!(env::join_paths(

0 commit comments

Comments
 (0)