Skip to content

Commit 5dc0d89

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 aa5832b commit 5dc0d89

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

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

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ impl Step for Std {
149149
let target = self.target;
150150
let compiler = self.compiler;
151151

152+
// We already have std ready to be used for stage 0.
153+
if compiler.stage == 0 {
154+
builder.ensure(StdLink::from_std(self, compiler));
155+
156+
return;
157+
}
158+
152159
// When using `download-rustc`, we already have artifacts for the host available. Don't
153160
// recompile them.
154-
if builder.download_rustc() && builder.config.is_host_target(target)
155-
// NOTE: the beta compiler may generate different artifacts than the downloaded compiler, so
156-
// its artifacts can't be reused.
157-
&& compiler.stage != 0
161+
if builder.download_rustc()
162+
&& builder.config.is_host_target(target)
158163
&& !self.force_recompile
159164
{
160165
let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false });
@@ -753,23 +758,16 @@ impl Step for StdLink {
753758
(libdir, hostdir)
754759
};
755760

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

763767
// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
764768
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
765769
// and is not set to a custom path.
766-
if compiler.stage == 0
767-
&& builder
768-
.build
769-
.config
770-
.initial_rustc
771-
.starts_with(builder.out.join(compiler.host).join("stage0/bin"))
772-
{
770+
if compiler.stage == 0 && is_downloaded_beta_stage0 {
773771
// Copy bin files from stage0/bin to stage0-sysroot/bin
774772
let sysroot = builder.out.join(compiler.host).join("stage0-sysroot");
775773

@@ -779,21 +777,8 @@ impl Step for StdLink {
779777
t!(fs::create_dir_all(&sysroot_bin_dir));
780778
builder.cp_link_r(&stage0_bin_dir, &sysroot_bin_dir);
781779

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

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

0 commit comments

Comments
 (0)