diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index f39e89a9d01f7..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 @@ -613,6 +614,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);