Skip to content

Commit 1065d87

Browse files
committed
Auto merge of rust-lang#113341 - Kobzol:stage0-sysroot, r=Mark-Simulacrum
Copy stage0 `rustc` binaries to `stage0-sysroot` This is basically a revival of rust-lang#101711 and rust-lang#107956, with an added check that the full sysroot will only be created if the original rustc comes from `stage0/bin`. What is/should be tested: - [x] `rustup toolchain link stage0` (new libstd is used correctly) - [x] `python3 x.py fmt dist --stage 0` - [x] Custom rustc/cargo in `config.toml` (in this case this logic is ignored) - [x] Perfbot (try perf run has succeeded) - [x] Real use case (rust-lang/backtrace-rs#542) (Hopefully) fixes: rust-lang#101691 This is not the "end all, be all" solution to this problem, but as long as it resolves the basic use-case, and doesn't break perfbot, I say ship it. This code will probably be nuked anyway Soon™ because of the stage redesign.
2 parents a9eba8d + bb8c497 commit 1065d87

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/bootstrap/compile.rs

+43
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,49 @@ impl Step for StdLink {
508508
};
509509

510510
add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
511+
512+
// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
513+
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
514+
// and is not set to a custom path.
515+
if compiler.stage == 0
516+
&& builder
517+
.build
518+
.config
519+
.initial_rustc
520+
.starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin"))
521+
{
522+
// Copy bin files from stage0/bin to stage0-sysroot/bin
523+
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
524+
525+
let host = compiler.host.triple;
526+
let stage0_bin_dir = builder.out.join(&host).join("stage0/bin");
527+
let sysroot_bin_dir = sysroot.join("bin");
528+
t!(fs::create_dir_all(&sysroot_bin_dir));
529+
builder.cp_r(&stage0_bin_dir, &sysroot_bin_dir);
530+
531+
// Copy all *.so files from stage0/lib to stage0-sysroot/lib
532+
let stage0_lib_dir = builder.out.join(&host).join("stage0/lib");
533+
if let Ok(files) = fs::read_dir(&stage0_lib_dir) {
534+
for file in files {
535+
let file = t!(file);
536+
let path = file.path();
537+
if path.is_file() && is_dylib(&file.file_name().into_string().unwrap()) {
538+
builder.copy(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
539+
}
540+
}
541+
}
542+
543+
// Copy codegen-backends from stage0
544+
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);
545+
t!(fs::create_dir_all(&sysroot_codegen_backends));
546+
let stage0_codegen_backends = builder
547+
.out
548+
.join(&host)
549+
.join("stage0/lib/rustlib")
550+
.join(&host)
551+
.join("codegen-backends");
552+
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
553+
}
511554
}
512555
}
513556

0 commit comments

Comments
 (0)