Skip to content

Commit 1cfec67

Browse files
committed
Copy built tools to stage sysroot
Motivation for this is to enable tools usage when using `rustup toolchain link`.
1 parent df70463 commit 1cfec67

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/bootstrap/builder.rs

+21
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,27 @@ impl<'a> Builder<'a> {
613613
self.ensure(compile::Sysroot { compiler })
614614
}
615615

616+
pub fn sysroot_bindir(&self, compiler: Compiler) -> Interned<PathBuf> {
617+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
618+
struct Bindir {
619+
compiler: Compiler,
620+
}
621+
impl Step for Bindir {
622+
type Output = Interned<PathBuf>;
623+
624+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
625+
run.never()
626+
}
627+
628+
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
629+
let sysroot_bindir = builder.sysroot(self.compiler).join("bin");
630+
t!(fs::create_dir_all(&sysroot_bindir));
631+
INTERNER.intern_path(sysroot_bindir)
632+
}
633+
}
634+
self.ensure(Bindir { compiler })
635+
}
636+
616637
/// Returns the libdir where the standard library and other artifacts are
617638
/// found for a compiler's sysroot.
618639
pub fn sysroot_libdir(&self, compiler: Compiler, target: TargetSelection) -> Interned<PathBuf> {

src/bootstrap/compile.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,7 @@ impl Step for Assemble {
11251125
// Link the compiler binary itself into place
11261126
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
11271127
let rustc = out_dir.join(exe("rustc-main", host));
1128-
let bindir = sysroot.join("bin");
1129-
t!(fs::create_dir_all(&bindir));
1128+
let _ = builder.sysroot_bindir(target_compiler);
11301129
let compiler = builder.rustc(target_compiler);
11311130
builder.copy(&rustc, &compiler);
11321131

src/bootstrap/tool.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::fs;
44
use std::path::PathBuf;
55
use std::process::{exit, Command};
66

7-
use build_helper::t;
8-
97
use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
108
use crate::channel::GitInfo;
119
use crate::compile;
@@ -214,10 +212,17 @@ impl Step for ToolBuild {
214212
if tool == "tidy" {
215213
tool = "rust-tidy";
216214
}
217-
let cargo_out =
218-
builder.cargo_out(compiler, self.mode, target).join(exe(tool, compiler.host));
219-
let bin = builder.tools_dir(compiler).join(exe(tool, compiler.host));
215+
let exe = exe(tool, compiler.host);
216+
let cargo_out = builder.cargo_out(compiler, self.mode, target).join(&exe);
217+
let bin = builder.tools_dir(compiler).join(&exe);
220218
builder.copy(&cargo_out, &bin);
219+
220+
// Don't create a stage0-sysroot/bin directory.
221+
if compiler.stage > 0 {
222+
let sysroot_bin = builder.sysroot_bindir(compiler).join(&exe);
223+
builder.copy(&cargo_out, &sysroot_bin);
224+
}
225+
221226
Some(bin)
222227
}
223228
}
@@ -565,11 +570,9 @@ impl Step for Rustdoc {
565570
.cargo_out(build_compiler, Mode::ToolRustc, target)
566571
.join(exe("rustdoc_tool_binary", target_compiler.host));
567572

568-
// don't create a stage0-sysroot/bin directory.
573+
// Don't create a stage0-sysroot/bin directory.
569574
if target_compiler.stage > 0 {
570-
let sysroot = builder.sysroot(target_compiler);
571-
let bindir = sysroot.join("bin");
572-
t!(fs::create_dir_all(&bindir));
575+
let bindir = builder.sysroot_bindir(target_compiler);
573576
let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host));
574577
let _ = fs::remove_file(&bin_rustdoc);
575578
builder.copy(&tool_rustdoc, &bin_rustdoc);

0 commit comments

Comments
 (0)