Skip to content

Commit 6d99d6a

Browse files
committed
ship clippy, miri and rustfmt with sysroot
Signed-off-by: ozkanonur <[email protected]>
1 parent 7e23d18 commit 6d99d6a

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/bootstrap/tool.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ macro_rules! tool_extended {
748748
stable = $stable:expr
749749
$(,tool_std = $tool_std:literal)?
750750
$(,allow_features = $allow_features:expr)?
751+
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
751752
;)+) => {
752753
$(
753754
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -790,7 +791,7 @@ macro_rules! tool_extended {
790791

791792
#[allow(unused_mut)]
792793
fn run(mut $sel, $builder: &Builder<'_>) -> Option<PathBuf> {
793-
$builder.ensure(ToolBuild {
794+
let tool = $builder.ensure(ToolBuild {
794795
compiler: $sel.compiler,
795796
target: $sel.target,
796797
tool: $tool_name,
@@ -800,7 +801,27 @@ macro_rules! tool_extended {
800801
is_optional_tool: true,
801802
source_type: SourceType::InTree,
802803
allow_features: concat!($($allow_features)*),
803-
})
804+
})?;
805+
806+
if (false $(|| !$add_bins_to_sysroot.is_empty())?) && $sel.compiler.stage > 0 {
807+
let bindir = $builder.sysroot($sel.compiler).join("bin");
808+
t!(fs::create_dir_all(&bindir));
809+
810+
#[allow(unused_variables)]
811+
let tools_out = $builder
812+
.cargo_out($sel.compiler, Mode::ToolRustc, $sel.target);
813+
814+
$(for add_bin in $add_bins_to_sysroot {
815+
let bin_source = tools_out.join(exe(add_bin, $sel.target));
816+
let bin_destination = bindir.join(exe(add_bin, $sel.compiler.host));
817+
$builder.copy(&bin_source, &bin_destination);
818+
})?
819+
820+
let tool = bindir.join(exe($tool_name, $sel.compiler.host));
821+
Some(tool)
822+
} else {
823+
Some(tool)
824+
}
804825
}
805826
}
806827
)+
@@ -814,15 +835,15 @@ macro_rules! tool_extended {
814835
tool_extended!((self, builder),
815836
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
816837
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
817-
Clippy, "src/tools/clippy", "clippy-driver", stable=true;
818-
Miri, "src/tools/miri", "miri", stable=false;
819-
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true;
838+
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
839+
Miri, "src/tools/miri", "miri", stable=false, add_bins_to_sysroot = ["miri"];
840+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true, add_bins_to_sysroot = ["cargo-miri"];
820841
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
821842
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
822843
// and this is close enough for now.
823844
Rls, "src/tools/rls", "rls", stable=true, tool_std=true;
824845
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true;
825-
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true;
846+
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
826847
);
827848

828849
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)