Skip to content

Commit 2b66f46

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 2b66f46

File tree

1 file changed

+20
-14
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+20
-14
lines changed

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

+20-14
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ impl Step for ToolBuild {
8080

8181
match self.mode {
8282
Mode::ToolRustc => {
83-
builder.ensure(compile::Std::new(compiler, compiler.host));
84-
builder.ensure(compile::Rustc::new(compiler, target));
83+
let linked_against_compiler = compiler.with_stage(compiler.stage + 1);
84+
// When building a tool that links against rustc,
85+
// we need the rustc to link against and its std to be present and ready in the syroot.
86+
builder.ensure(compile::Std::new(
87+
linked_against_compiler,
88+
linked_against_compiler.host,
89+
));
8590
}
8691
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)),
8792
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
@@ -863,8 +868,8 @@ macro_rules! tool_extended {
863868
$($name:ident,
864869
$path:expr,
865870
$tool_name:expr,
871+
mode = $mode:expr,
866872
stable = $stable:expr
867-
$(,tool_std = $tool_std:literal)?
868873
$(,allow_features = $allow_features:expr)?
869874
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
870875
;)+) => {
@@ -913,15 +918,16 @@ macro_rules! tool_extended {
913918
compiler: $sel.compiler,
914919
target: $sel.target,
915920
tool: $tool_name,
916-
mode: if false $(|| $tool_std)? { Mode::ToolStd } else { Mode::ToolRustc },
921+
mode: $mode,
917922
path: $path,
918923
extra_features: $sel.extra_features,
919924
source_type: SourceType::InTree,
920925
allow_features: concat!($($allow_features)*),
921926
});
922927

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

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

966972
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)