Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy built tools to stage sysroot #85496

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ impl<'a> Builder<'a> {
native::Llvm,
native::Sanitizers,
tool::Rustfmt,
tool::Cargofmt,
tool::Miri,
tool::CargoMiri,
native::Lld
Expand Down Expand Up @@ -613,6 +614,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this for all tools is likely not a good idea, as it'll place things like tidy and other internal tools in the PATH (particularly on windows, that may be a problem). It should be possible to add this after the calls to ToolBuild, as we return the appropriate path already.

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