Skip to content

Commit 48a6cc7

Browse files
committed
Add tools to sysroot after build.
1 parent 47c008e commit 48a6cc7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/bootstrap/tool.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ macro_rules! tool_extended {
796796
$tool_name:expr,
797797
stable = $stable:expr
798798
$(,tool_std = $tool_std:literal)?
799+
$(,add_to_sysroot = $add_to_sysroot:literal)?
799800
;)+) => {
800801
$(
801802
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -838,7 +839,7 @@ macro_rules! tool_extended {
838839

839840
#[allow(unused_mut)]
840841
fn run(mut $sel, $builder: &Builder<'_>) -> Option<PathBuf> {
841-
$builder.ensure(ToolBuild {
842+
let tool = $builder.ensure(ToolBuild {
842843
compiler: $sel.compiler,
843844
target: $sel.target,
844845
tool: $tool_name,
@@ -847,7 +848,18 @@ macro_rules! tool_extended {
847848
extra_features: $sel.extra_features,
848849
is_optional_tool: true,
849850
source_type: SourceType::InTree,
850-
})
851+
})?;
852+
853+
if (false $(|| $add_to_sysroot)?) && $sel.compiler.stage > 0 {
854+
let bin_dir = $builder.sysroot($sel.compiler).join("bin");
855+
t!(fs::create_dir_all(&bin_dir));
856+
let bin_tool = bin_dir.join(exe($tool_name, $sel.compiler.host));
857+
let _ = fs::remove_file(&bin_tool);
858+
$builder.copy(&tool, &bin_tool);
859+
Some(bin_tool)
860+
} else {
861+
Some(tool)
862+
}
851863
}
852864
}
853865
)+
@@ -859,17 +871,17 @@ macro_rules! tool_extended {
859871
// Note: Most submodule updates for tools are handled by bootstrap.py, since they're needed just to
860872
// invoke Cargo to build bootstrap. See the comment there for more details.
861873
tool_extended!((self, builder),
862-
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
863-
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
864-
Clippy, "src/tools/clippy", "clippy-driver", stable=true;
865-
Miri, "src/tools/miri", "miri", stable=false;
866-
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true;
874+
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true, add_to_sysroot=true;
875+
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true, add_to_sysroot=true;
876+
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_to_sysroot=true;
877+
Miri, "src/tools/miri", "miri", stable=false, add_to_sysroot=true;
878+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, add_to_sysroot=true;
867879
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
868880
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
869881
// and this is close enough for now.
870882
Rls, "src/tools/rls", "rls", stable=true, tool_std=true;
871883
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true;
872-
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true;
884+
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_to_sysroot=true;
873885
);
874886

875887
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)