Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 32867b9

Browse files
committed
use initial rustc's std on stage 0
On stage 0, rather than compiling std utilize the one from the stage0 sysroot as stage 0 should represent the snapshot version not the compiled one. Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 249cb84 commit 32867b9

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

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

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,16 @@ impl Step for Std {
153153
let target = self.target;
154154
let compiler = self.compiler;
155155

156+
// We already have std ready to be used for stage 0.
157+
if compiler.stage == 0 {
158+
builder.ensure(StdLink::from_std(self, compiler));
159+
160+
return;
161+
}
162+
156163
// When using `download-rustc`, we already have artifacts for the host available. Don't
157164
// recompile them.
158-
if builder.download_rustc() && builder.is_builder_target(target)
159-
// NOTE: the beta compiler may generate different artifacts than the downloaded compiler, so
160-
// its artifacts can't be reused.
161-
&& compiler.stage != 0
162-
&& !self.force_recompile
163-
{
165+
if builder.download_rustc() && builder.is_builder_target(target) && !self.force_recompile {
164166
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
165167
cp_rustc_component_to_ci_sysroot(
166168
builder,
@@ -757,23 +759,16 @@ impl Step for StdLink {
757759
(libdir, hostdir)
758760
};
759761

760-
add_to_sysroot(
761-
builder,
762-
&libdir,
763-
&hostdir,
764-
&build_stamp::libstd_stamp(builder, compiler, target),
765-
);
762+
let is_downloaded_beta_stage0 = builder
763+
.build
764+
.config
765+
.initial_rustc
766+
.starts_with(builder.out.join(compiler.host).join("stage0/bin"));
766767

767768
// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
768769
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
769770
// and is not set to a custom path.
770-
if compiler.stage == 0
771-
&& builder
772-
.build
773-
.config
774-
.initial_rustc
775-
.starts_with(builder.out.join(compiler.host).join("stage0/bin"))
776-
{
771+
if compiler.stage == 0 && is_downloaded_beta_stage0 {
777772
// Copy bin files from stage0/bin to stage0-sysroot/bin
778773
let sysroot = builder.out.join(compiler.host).join("stage0-sysroot");
779774

@@ -783,18 +778,8 @@ impl Step for StdLink {
783778
t!(fs::create_dir_all(&sysroot_bin_dir));
784779
builder.cp_link_r(&stage0_bin_dir, &sysroot_bin_dir);
785780

786-
// Copy all files from stage0/lib to stage0-sysroot/lib
787781
let stage0_lib_dir = builder.out.join(host).join("stage0/lib");
788-
if let Ok(files) = fs::read_dir(stage0_lib_dir) {
789-
for file in files {
790-
let file = t!(file);
791-
let path = file.path();
792-
if path.is_file() {
793-
builder
794-
.copy_link(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
795-
}
796-
}
797-
}
782+
builder.cp_link_r(&stage0_lib_dir, &sysroot.join("lib"));
798783

799784
// Copy codegen-backends from stage0
800785
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);
@@ -808,6 +793,16 @@ impl Step for StdLink {
808793
if stage0_codegen_backends.exists() {
809794
builder.cp_link_r(&stage0_codegen_backends, &sysroot_codegen_backends);
810795
}
796+
} else if compiler.stage == 0 {
797+
let sysroot = builder.out.join(compiler.host.triple).join("stage0-sysroot");
798+
builder.cp_link_r(&builder.initial_sysroot.join("lib"), &sysroot.join("lib"));
799+
} else {
800+
add_to_sysroot(
801+
builder,
802+
&libdir,
803+
&hostdir,
804+
&build_stamp::libstd_stamp(builder, compiler, target),
805+
);
811806
}
812807
}
813808
}

0 commit comments

Comments
 (0)