From 973ff033f38a1ee23798560e748a7e2035f49ed0 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 20 Sep 2022 00:53:46 +0800 Subject: [PATCH 1/2] fix #102002, Delete the stage1 and stage0-sysroot directories when using download-rustc --- src/bootstrap/compile.rs | 10 ++++++++-- src/bootstrap/tool.rs | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c13e83f6c86..51268a16d63 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1099,10 +1099,11 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { /// 1-3. fn run(self, builder: &Builder<'_>) -> Interned { let compiler = self.compiler; + let host_dir = builder.out.join(&compiler.host.triple); let sysroot = if compiler.stage == 0 { - builder.out.join(&compiler.host.triple).join("stage0-sysroot") + host_dir.join("stage0-sysroot") } else { - builder.out.join(&compiler.host.triple).join(format!("stage{}", compiler.stage)) + host_dir.join(format!("stage{}", compiler.stage)) }; let _ = fs::remove_dir_all(&sysroot); t!(fs::create_dir_all(&sysroot)); @@ -1113,6 +1114,11 @@ fn run(self, builder: &Builder<'_>) -> Interned { builder.config.build, compiler.host, "Cross-compiling is not yet supported with `download-rustc`", ); + + // #102002, cleanup stage1 and stage0-sysroot folders when using download-rustc + let _ = fs::remove_dir_all(host_dir.join("stage1")); + let _ = fs::remove_dir_all(host_dir.join("stage0-sysroot")); + // Copy the compiler into the correct sysroot. let ci_rustc_dir = builder.config.out.join(&*builder.config.build.triple).join("ci-rustc"); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 5d0c7d2bd9d..6a11e04f630 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -512,8 +512,10 @@ fn run(self, builder: &Builder<'_>) -> PathBuf { // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage // compilers, which isn't what we want. Rustdoc should be linked in the same way as the - // rustc compiler it's paired with, so it must be built with the previous stage compiler. - let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build); + // rustc compiler it's paired with, so it must be built with the previous stage compiler, + // if download_rustc is true, we will use the same target stage. + let target_stage = target_compiler.stage - if builder.download_rustc() { 0 } else { 1 }; + let build_compiler = builder.compiler(target_stage, builder.config.build); // When using `download-rustc` and a stage0 build_compiler, copying rustc doesn't actually // build stage0 libstd (because the libstd in sysroot has the wrong ABI). Explicitly build From 60b39ba9a573081af2b1f3faaf14c020ef304d11 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 4 Oct 2022 10:48:53 +0800 Subject: [PATCH 2/2] use ci-rustc-sysroot for sysroot when download_rustc --- src/bootstrap/compile.rs | 4 +++- src/bootstrap/tool.rs | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 51268a16d63..8058fb1eaa2 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1102,6 +1102,8 @@ fn run(self, builder: &Builder<'_>) -> Interned { let host_dir = builder.out.join(&compiler.host.triple); let sysroot = if compiler.stage == 0 { host_dir.join("stage0-sysroot") + } else if builder.download_rustc() { + host_dir.join("ci-rustc-sysroot") } else { host_dir.join(format!("stage{}", compiler.stage)) }; @@ -1115,7 +1117,7 @@ fn run(self, builder: &Builder<'_>) -> Interned { "Cross-compiling is not yet supported with `download-rustc`", ); - // #102002, cleanup stage1 and stage0-sysroot folders when using download-rustc + // #102002, cleanup stage1 and stage0-sysroot folders when using download-rustc so people don't use old versions of the toolchain by accident. let _ = fs::remove_dir_all(host_dir.join("stage1")); let _ = fs::remove_dir_all(host_dir.join("stage0-sysroot")); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 6a11e04f630..5d0c7d2bd9d 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -512,10 +512,8 @@ fn run(self, builder: &Builder<'_>) -> PathBuf { // Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise // we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage // compilers, which isn't what we want. Rustdoc should be linked in the same way as the - // rustc compiler it's paired with, so it must be built with the previous stage compiler, - // if download_rustc is true, we will use the same target stage. - let target_stage = target_compiler.stage - if builder.download_rustc() { 0 } else { 1 }; - let build_compiler = builder.compiler(target_stage, builder.config.build); + // rustc compiler it's paired with, so it must be built with the previous stage compiler. + let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build); // When using `download-rustc` and a stage0 build_compiler, copying rustc doesn't actually // build stage0 libstd (because the libstd in sysroot has the wrong ABI). Explicitly build