From 6bf928825ded48811782c41aa1fb1057c5d10a50 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 12 Jan 2024 20:53:55 +0300 Subject: [PATCH] use initial rustc's std on stage 0 On stage 0, rather than compiling std utilize the version from the initial rustc. Theoretically, stage 0 should represent the snapshot version not the compiled one. This makes bootstrapping quicker as well. Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/compile.rs | 39 +++++++++++-------- src/bootstrap/src/core/build_steps/test.rs | 2 +- src/bootstrap/src/core/builder.rs | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 190f0fe3cddcf..91dc149a54502 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -137,6 +137,16 @@ impl Step for Std { let target = self.target; let compiler = self.compiler; + // We already have std ready to be used for stage 0. + if compiler.stage == 0 { + builder.ensure(StdLink::from_std( + self, + builder.compiler(compiler.stage, builder.config.build), + )); + + return; + } + // When using `download-rustc`, we already have artifacts for the host available. Don't // recompile them. if builder.download_rustc() && target == builder.build.build @@ -585,18 +595,16 @@ impl Step for StdLink { (libdir, hostdir) }; - add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target)); + let is_downloaded_beta_stage0 = builder + .build + .config + .initial_rustc + .starts_with(builder.out.join(&compiler.host.triple).join("stage0/bin")); // 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")) - { + if compiler.stage == 0 && is_downloaded_beta_stage0 { // Copy bin files from stage0/bin to stage0-sysroot/bin let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot"); @@ -608,15 +616,7 @@ impl Step for StdLink { // 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())); - } - } - } + builder.cp_r(&stage0_lib_dir, &sysroot.join("lib")); // Copy codegen-backends from stage0 let sysroot_codegen_backends = builder.sysroot_codegen_backends(compiler); @@ -630,6 +630,11 @@ impl Step for StdLink { if stage0_codegen_backends.exists() { builder.cp_r(&stage0_codegen_backends, &sysroot_codegen_backends); } + } else if compiler.stage == 0 { + let sysroot = builder.out.join(&compiler.host.triple).join("stage0-sysroot"); + builder.cp_r(&builder.initial_sysroot.join("lib"), &sysroot.join("lib")); + } else { + add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target)); } } } diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 04728e2e00dcc..9733e39e1384f 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1121,7 +1121,7 @@ impl Step for Tidy { if builder.config.channel == "dev" || builder.config.channel == "nightly" { builder.info("fmt check"); if builder.initial_rustfmt().is_none() { - let inferred_rustfmt_dir = builder.initial_rustc.parent().unwrap(); + let inferred_rustfmt_dir = builder.initial_sysroot.join("bin"); eprintln!( "\ ERROR: no `rustfmt` binary found in {PATH} diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 4e20babc55a68..b7eb8815b6aef 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -1167,7 +1167,7 @@ impl<'a> Builder<'a> { } pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> Command { - let initial_sysroot_bin = self.initial_rustc.parent().unwrap(); + let initial_sysroot_bin = self.initial_sysroot.join("bin"); // Set PATH to include the sysroot bin dir so clippy can find cargo. // FIXME: once rust-clippy#11944 lands on beta, set `CARGO` directly instead. let path = t!(env::join_paths(