Skip to content

Commit

Permalink
Auto merge of rust-lang#113341 - Kobzol:stage0-sysroot, r=Mark-Simula…
Browse files Browse the repository at this point in the history
…crum

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.
  • Loading branch information
bors committed Jul 9, 2023
2 parents a9eba8d + bb8c497 commit 1065d87
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,49 @@ impl Step for StdLink {
};

add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));

// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
// and is not set to a custom path.
if compiler.stage == 0
&& builder
.build
.config
.initial_rustc
.starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin"))
{
// Copy bin files from stage0/bin to stage0-sysroot/bin
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");

let host = compiler.host.triple;
let stage0_bin_dir = builder.out.join(&host).join("stage0/bin");
let sysroot_bin_dir = sysroot.join("bin");
t!(fs::create_dir_all(&sysroot_bin_dir));
builder.cp_r(&stage0_bin_dir, &sysroot_bin_dir);

// Copy all *.so files from stage0/lib to stage0-sysroot/lib
let stage0_lib_dir = builder.out.join(&host).join("stage0/lib");
if let Ok(files) = fs::read_dir(&stage0_lib_dir) {
for file in files {
let file = t!(file);
let path = file.path();
if path.is_file() && is_dylib(&file.file_name().into_string().unwrap()) {
builder.copy(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
}
}
}

// Copy codegen-backends from stage0
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);
t!(fs::create_dir_all(&sysroot_codegen_backends));
let stage0_codegen_backends = builder
.out
.join(&host)
.join("stage0/lib/rustlib")
.join(&host)
.join("codegen-backends");
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
}
}
}

Expand Down

0 comments on commit 1065d87

Please sign in to comment.