From 1cfec67a4c6b7ff8b946a42b851c0baf69ad4b63 Mon Sep 17 00:00:00 2001 From: Boris-Chengbiao Zhou Date: Thu, 20 May 2021 03:41:07 +0200 Subject: [PATCH 1/2] Copy built tools to stage sysroot Motivation for this is to enable tools usage when using `rustup toolchain link`. --- src/bootstrap/builder.rs | 21 +++++++++++++++++++++ src/bootstrap/compile.rs | 3 +-- src/bootstrap/tool.rs | 21 ++++++++++++--------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index f39e89a9d01f7..a1acf3b160539 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -613,6 +613,27 @@ impl<'a> Builder<'a> { self.ensure(compile::Sysroot { compiler }) } + pub fn sysroot_bindir(&self, compiler: Compiler) -> Interned { + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + struct Bindir { + compiler: Compiler, + } + impl Step for Bindir { + type Output = Interned; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.never() + } + + fn run(self, builder: &Builder<'_>) -> Interned { + let sysroot_bindir = builder.sysroot(self.compiler).join("bin"); + t!(fs::create_dir_all(&sysroot_bindir)); + INTERNER.intern_path(sysroot_bindir) + } + } + self.ensure(Bindir { compiler }) + } + /// Returns the libdir where the standard library and other artifacts are /// found for a compiler's sysroot. pub fn sysroot_libdir(&self, compiler: Compiler, target: TargetSelection) -> Interned { diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2676b3bf8e005..fe592537be3c5 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1125,8 +1125,7 @@ impl Step for Assemble { // Link the compiler binary itself into place let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host); let rustc = out_dir.join(exe("rustc-main", host)); - let bindir = sysroot.join("bin"); - t!(fs::create_dir_all(&bindir)); + let _ = builder.sysroot_bindir(target_compiler); let compiler = builder.rustc(target_compiler); builder.copy(&rustc, &compiler); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index dd8c6023a44cb..40a6e9ea574a9 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -4,8 +4,6 @@ use std::fs; use std::path::PathBuf; use std::process::{exit, Command}; -use build_helper::t; - use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step}; use crate::channel::GitInfo; use crate::compile; @@ -214,10 +212,17 @@ impl Step for ToolBuild { if tool == "tidy" { tool = "rust-tidy"; } - let cargo_out = - builder.cargo_out(compiler, self.mode, target).join(exe(tool, compiler.host)); - let bin = builder.tools_dir(compiler).join(exe(tool, compiler.host)); + let exe = exe(tool, compiler.host); + let cargo_out = builder.cargo_out(compiler, self.mode, target).join(&exe); + let bin = builder.tools_dir(compiler).join(&exe); builder.copy(&cargo_out, &bin); + + // Don't create a stage0-sysroot/bin directory. + if compiler.stage > 0 { + let sysroot_bin = builder.sysroot_bindir(compiler).join(&exe); + builder.copy(&cargo_out, &sysroot_bin); + } + Some(bin) } } @@ -565,11 +570,9 @@ impl Step for Rustdoc { .cargo_out(build_compiler, Mode::ToolRustc, target) .join(exe("rustdoc_tool_binary", target_compiler.host)); - // don't create a stage0-sysroot/bin directory. + // Don't create a stage0-sysroot/bin directory. if target_compiler.stage > 0 { - let sysroot = builder.sysroot(target_compiler); - let bindir = sysroot.join("bin"); - t!(fs::create_dir_all(&bindir)); + let bindir = builder.sysroot_bindir(target_compiler); let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host)); let _ = fs::remove_file(&bin_rustdoc); builder.copy(&tool_rustdoc, &bin_rustdoc); From 96ef70f2f9b9cde7bdcef23a085ab9a5d17027c8 Mon Sep 17 00:00:00 2001 From: Boris-Chengbiao Zhou Date: Thu, 20 May 2021 04:50:03 +0200 Subject: [PATCH 2/2] Add cargo-fmt to bootstrap step descriptions --- src/bootstrap/builder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index a1acf3b160539..d037f08e2a1f7 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -367,6 +367,7 @@ impl<'a> Builder<'a> { native::Llvm, native::Sanitizers, tool::Rustfmt, + tool::Cargofmt, tool::Miri, tool::CargoMiri, native::Lld