Skip to content

Commit ec20e7a

Browse files
committed
Link rustc/std tools into the correct sysroot
When copying tool binaries, we were linking them into the sysroot of the compiler that built the binaries. This makes no sense, the binaries are for the next sysroot. So when the stage0 compiler builds clippy, this clippy belongs into stage1, and when the stage1 compiler builds clippy, this clippy belongs into stage2. This puts it right next to the librustc_driver it actually links against. Additionally, we `ensure(Assemble)` of this librustc_driver such that the tool will be working as expected. To run the tool manually, we still need to set LD_LIBRARY_PATH, but now with this, setting the rpath to `$ORIGIN/../lib` (like the `rustc` and `rustdoc` binaries) should be possible as future work now. Rustdoc, with its special treatment, was already getting the correct behavior.
1 parent e1ac0fa commit ec20e7a

File tree

1 file changed

+13
-12
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+13
-12
lines changed

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,8 @@ macro_rules! tool_extended {
863863
$($name:ident,
864864
$path:expr,
865865
$tool_name:expr,
866+
mode = $mode:expr,
866867
stable = $stable:expr
867-
$(,tool_std = $tool_std:literal)?
868868
$(,allow_features = $allow_features:expr)?
869869
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
870870
;)+) => {
@@ -913,15 +913,16 @@ macro_rules! tool_extended {
913913
compiler: $sel.compiler,
914914
target: $sel.target,
915915
tool: $tool_name,
916-
mode: if false $(|| $tool_std)? { Mode::ToolStd } else { Mode::ToolRustc },
916+
mode: $mode,
917917
path: $path,
918918
extra_features: $sel.extra_features,
919919
source_type: SourceType::InTree,
920920
allow_features: concat!($($allow_features)*),
921921
});
922922

923-
if (false $(|| !$add_bins_to_sysroot.is_empty())?) && $sel.compiler.stage > 0 {
924-
let bindir = $builder.sysroot($sel.compiler).join("bin");
923+
if (false $(|| !$add_bins_to_sysroot.is_empty())?) {
924+
// As usual, we copy the tool into the next sysroot, as it links against the compiler in that sysroot.
925+
let bindir = $builder.sysroot($sel.compiler.with_stage($sel.compiler.stage + 1)).join("bin");
925926
t!(fs::create_dir_all(&bindir));
926927

927928
#[allow(unused_variables)]
@@ -950,17 +951,17 @@ macro_rules! tool_extended {
950951
// NOTE: Most submodule updates for tools are handled by bootstrap.py, since they're needed just to
951952
// invoke Cargo to build bootstrap. See the comment there for more details.
952953
tool_extended!((self, builder),
953-
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
954-
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
955-
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
956-
Miri, "src/tools/miri", "miri", stable=false, add_bins_to_sysroot = ["miri"];
957-
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true, add_bins_to_sysroot = ["cargo-miri"];
954+
Cargofmt, "src/tools/rustfmt", "cargo-fmt", mode=Mode::ToolRustc, stable=true;
955+
CargoClippy, "src/tools/clippy", "cargo-clippy", mode= Mode::ToolRustc, stable=true;
956+
Clippy, "src/tools/clippy", "clippy-driver", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
957+
Miri, "src/tools/miri", "miri", mode= Mode::ToolRustc, stable=false, add_bins_to_sysroot = ["miri"];
958+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["cargo-miri"];
958959
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
959960
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
960961
// and this is close enough for now.
961-
Rls, "src/tools/rls", "rls", stable=true, tool_std=true;
962-
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true;
963-
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
962+
Rls, "src/tools/rls", "rls", mode=Mode::ToolStd, stable=true;
963+
RustDemangler, "src/tools/rust-demangler", "rust-demangler", mode=Mode::ToolStd, stable=false;
964+
Rustfmt, "src/tools/rustfmt", "rustfmt", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
964965
);
965966

966967
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)