Skip to content

Commit 48d1b9b

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 48d1b9b

File tree

1 file changed

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

1 file changed

+18
-13
lines changed

src/bootstrap/src/core/build_steps/tool.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ impl Step for ToolBuild {
8181
match self.mode {
8282
Mode::ToolRustc => {
8383
builder.ensure(compile::Std::new(compiler, compiler.host));
84-
builder.ensure(compile::Rustc::new(compiler, target));
84+
// When building a tool that links against rustc,
85+
// we need the rustc to link against to be present and ready in the syroot.
86+
builder.ensure(compile::Assemble {
87+
target_compiler: compiler.with_stage(compiler.stage + 1),
88+
});
8589
}
8690
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)),
8791
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
@@ -863,8 +867,8 @@ macro_rules! tool_extended {
863867
$($name:ident,
864868
$path:expr,
865869
$tool_name:expr,
870+
mode = $mode:expr,
866871
stable = $stable:expr
867-
$(,tool_std = $tool_std:literal)?
868872
$(,allow_features = $allow_features:expr)?
869873
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
870874
;)+) => {
@@ -913,15 +917,16 @@ macro_rules! tool_extended {
913917
compiler: $sel.compiler,
914918
target: $sel.target,
915919
tool: $tool_name,
916-
mode: if false $(|| $tool_std)? { Mode::ToolStd } else { Mode::ToolRustc },
920+
mode: $mode,
917921
path: $path,
918922
extra_features: $sel.extra_features,
919923
source_type: SourceType::InTree,
920924
allow_features: concat!($($allow_features)*),
921925
});
922926

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

927932
#[allow(unused_variables)]
@@ -950,17 +955,17 @@ macro_rules! tool_extended {
950955
// NOTE: Most submodule updates for tools are handled by bootstrap.py, since they're needed just to
951956
// invoke Cargo to build bootstrap. See the comment there for more details.
952957
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"];
958+
Cargofmt, "src/tools/rustfmt", "cargo-fmt", mode=Mode::ToolRustc, stable=true;
959+
CargoClippy, "src/tools/clippy", "cargo-clippy", mode= Mode::ToolRustc, stable=true;
960+
Clippy, "src/tools/clippy", "clippy-driver", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
961+
Miri, "src/tools/miri", "miri", mode= Mode::ToolRustc, stable=false, add_bins_to_sysroot = ["miri"];
962+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["cargo-miri"];
958963
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
959964
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
960965
// 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"];
966+
Rls, "src/tools/rls", "rls", mode=Mode::ToolStd, stable=true;
967+
RustDemangler, "src/tools/rust-demangler", "rust-demangler", mode=Mode::ToolStd, stable=false;
968+
Rustfmt, "src/tools/rustfmt", "rustfmt", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
964969
);
965970

966971
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)