Skip to content

Commit d28a1a8

Browse files
committed
allow building/testing std with stage0 compiler
Signed-off-by: onur-ozkan <[email protected]>
1 parent 6bf9288 commit d28a1a8

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl Step for Std {
138138
let compiler = self.compiler;
139139

140140
// We already have std ready to be used for stage 0.
141-
if compiler.stage == 0 {
141+
if compiler.stage == 0 && !builder.config.build_std_on_stage0 {
142142
builder.ensure(StdLink::from_std(
143143
self,
144144
builder.compiler(compiler.stage, builder.config.build),
@@ -604,7 +604,7 @@ impl Step for StdLink {
604604
// Special case for stage0, to make `rustup toolchain link` and `x dist --stage 0`
605605
// work for stage0-sysroot. We only do this if the stage0 compiler comes from beta,
606606
// and is not set to a custom path.
607-
if compiler.stage == 0 && is_downloaded_beta_stage0 {
607+
if compiler.stage == 0 && is_downloaded_beta_stage0 && !builder.config.build_std_on_stage0 {
608608
// Copy bin files from stage0/bin to stage0-sysroot/bin
609609
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
610610

@@ -616,7 +616,18 @@ impl Step for StdLink {
616616

617617
// Copy all *.so files from stage0/lib to stage0-sysroot/lib
618618
let stage0_lib_dir = builder.out.join(&host).join("stage0/lib");
619-
builder.cp_r(&stage0_lib_dir, &sysroot.join("lib"));
619+
620+
if !builder.config.build_std_on_stage0 {
621+
builder.cp_r(&stage0_lib_dir, &sysroot.join("lib"));
622+
} else if let Ok(files) = fs::read_dir(&stage0_lib_dir) {
623+
for file in files {
624+
let file = t!(file);
625+
let path = file.path();
626+
if path.is_file() && is_dylib(&file.file_name().into_string().unwrap()) {
627+
builder.copy(&path, &sysroot.join("lib").join(path.file_name().unwrap()));
628+
}
629+
}
630+
}
620631

621632
// Copy codegen-backends from stage0
622633
let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler);
@@ -630,7 +641,7 @@ impl Step for StdLink {
630641
if stage0_codegen_backends.exists() {
631642
builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends);
632643
}
633-
} else if compiler.stage == 0 {
644+
} else if compiler.stage == 0 && !builder.config.build_std_on_stage0 {
634645
let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot");
635646
builder.cp_r(&builder.initial_sysroot.join("lib"), &sysroot.join("lib"));
636647
} else {

src/bootstrap/src/core/config/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ pub struct Config {
186186

187187
pub on_fail: Option<String>,
188188
pub stage: u32,
189+
pub build_std_on_stage0: bool,
189190
pub keep_stage: Vec<u32>,
190191
pub keep_stage_std: Vec<u32>,
191192
pub src: PathBuf,
@@ -1219,6 +1220,7 @@ impl Config {
12191220
config.incremental = flags.incremental;
12201221
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
12211222
config.dump_bootstrap_shims = flags.dump_bootstrap_shims;
1223+
config.build_std_on_stage0 = flags.build_std_on_stage0;
12221224
config.keep_stage = flags.keep_stage;
12231225
config.keep_stage_std = flags.keep_stage_std;
12241226
config.color = flags.color;

src/bootstrap/src/core/config/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub struct Flags {
9292
/// stage to build (indicates compiler to use/test, e.g., stage 0 uses the
9393
/// bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)
9494
pub stage: Option<u32>,
95+
/// Useful for library testing with the beta compiler (without building the stage 1 compiler)
96+
#[arg(global(true), long)]
97+
pub build_std_on_stage0: bool,
9598

9699
#[arg(global(true), value_hint = clap::ValueHint::Other, long, value_name = "N")]
97100
/// stage(s) to keep without recompiling

0 commit comments

Comments
 (0)