Skip to content

Commit 53db4e2

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 a8cfc83 commit 53db4e2

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
@@ -78,8 +78,13 @@ impl Step for ToolBuild {
7878

7979
match self.mode {
8080
Mode::ToolRustc => {
81-
builder.ensure(compile::Std::new(compiler, compiler.host));
82-
builder.ensure(compile::Rustc::new(compiler, target));
81+
let linked_against_compiler = compiler.with_stage(compiler.stage + 1);
82+
// When building a tool that links against rustc,
83+
// we need the rustc to link against and its std to be present and ready in the syroot.
84+
builder.ensure(compile::Std::new(
85+
linked_against_compiler,
86+
linked_against_compiler.host,
87+
));
8388
}
8489
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)),
8590
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
@@ -770,8 +775,8 @@ macro_rules! tool_extended {
770775
$($name:ident,
771776
$path:expr,
772777
$tool_name:expr,
778+
mode = $mode:expr,
773779
stable = $stable:expr
774-
$(,tool_std = $tool_std:literal)?
775780
$(,allow_features = $allow_features:expr)?
776781
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
777782
;)+) => {
@@ -820,15 +825,16 @@ macro_rules! tool_extended {
820825
compiler: $sel.compiler,
821826
target: $sel.target,
822827
tool: $tool_name,
823-
mode: if false $(|| $tool_std)? { Mode::ToolStd } else { Mode::ToolRustc },
828+
mode: $mode,
824829
path: $path,
825830
extra_features: $sel.extra_features,
826831
source_type: SourceType::InTree,
827832
allow_features: concat!($($allow_features)*),
828833
});
829834

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

834840
#[allow(unused_variables)]
@@ -857,17 +863,17 @@ macro_rules! tool_extended {
857863
// NOTE: Most submodule updates for tools are handled by bootstrap.py, since they're needed just to
858864
// invoke Cargo to build bootstrap. See the comment there for more details.
859865
tool_extended!((self, builder),
860-
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
861-
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
862-
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
863-
Miri, "src/tools/miri", "miri", stable=false, add_bins_to_sysroot = ["miri"];
864-
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true, add_bins_to_sysroot = ["cargo-miri"];
866+
Cargofmt, "src/tools/rustfmt", "cargo-fmt", mode=Mode::ToolRustc, stable=true;
867+
CargoClippy, "src/tools/clippy", "cargo-clippy", mode= Mode::ToolRustc, stable=true;
868+
Clippy, "src/tools/clippy", "clippy-driver", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
869+
Miri, "src/tools/miri", "miri", mode= Mode::ToolRustc, stable=false, add_bins_to_sysroot = ["miri"];
870+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["cargo-miri"];
865871
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
866872
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
867873
// and this is close enough for now.
868-
Rls, "src/tools/rls", "rls", stable=true, tool_std=true;
869-
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true;
870-
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
874+
Rls, "src/tools/rls", "rls", mode=Mode::ToolStd, stable=true;
875+
RustDemangler, "src/tools/rust-demangler", "rust-demangler", mode=Mode::ToolStd, stable=false;
876+
Rustfmt, "src/tools/rustfmt", "rustfmt", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
871877
);
872878

873879
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)