Skip to content

Commit

Permalink
Copy built tools to stage sysroot
Browse files Browse the repository at this point in the history
Motivation for this is to enable tools usage when using `rustup toolchain link`.
  • Loading branch information
Bobo1239 committed May 20, 2021
1 parent df70463 commit 1cfec67
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
21 changes: 21 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,27 @@ impl<'a> Builder<'a> {
self.ensure(compile::Sysroot { compiler })
}

pub fn sysroot_bindir(&self, compiler: Compiler) -> Interned<PathBuf> {
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct Bindir {
compiler: Compiler,
}
impl Step for Bindir {
type Output = Interned<PathBuf>;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.never()
}

fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
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<PathBuf> {
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
21 changes: 12 additions & 9 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1cfec67

Please sign in to comment.