Skip to content

Commit da31765

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 da31765

File tree

1 file changed

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

1 file changed

+18
-14
lines changed

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

+18-14
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ 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+
// When building a tool that links against rustc,
82+
// we need the rustc to link against to be present and ready in the syroot.
83+
builder.ensure(compile::Assemble {
84+
target_compiler: compiler.with_stage(compiler.stage + 1),
85+
});
8386
}
8487
Mode::ToolStd => builder.ensure(compile::Std::new(compiler, target)),
8588
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
@@ -770,8 +773,8 @@ macro_rules! tool_extended {
770773
$($name:ident,
771774
$path:expr,
772775
$tool_name:expr,
776+
mode = $mode:expr,
773777
stable = $stable:expr
774-
$(,tool_std = $tool_std:literal)?
775778
$(,allow_features = $allow_features:expr)?
776779
$(,add_bins_to_sysroot = $add_bins_to_sysroot:expr)?
777780
;)+) => {
@@ -820,15 +823,16 @@ macro_rules! tool_extended {
820823
compiler: $sel.compiler,
821824
target: $sel.target,
822825
tool: $tool_name,
823-
mode: if false $(|| $tool_std)? { Mode::ToolStd } else { Mode::ToolRustc },
826+
mode: $mode,
824827
path: $path,
825828
extra_features: $sel.extra_features,
826829
source_type: SourceType::InTree,
827830
allow_features: concat!($($allow_features)*),
828831
});
829832

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

834838
#[allow(unused_variables)]
@@ -857,17 +861,17 @@ macro_rules! tool_extended {
857861
// NOTE: Most submodule updates for tools are handled by bootstrap.py, since they're needed just to
858862
// invoke Cargo to build bootstrap. See the comment there for more details.
859863
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"];
864+
Cargofmt, "src/tools/rustfmt", "cargo-fmt", mode=Mode::ToolRustc, stable=true;
865+
CargoClippy, "src/tools/clippy", "cargo-clippy", mode= Mode::ToolRustc, stable=true;
866+
Clippy, "src/tools/clippy", "clippy-driver", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
867+
Miri, "src/tools/miri", "miri", mode= Mode::ToolRustc, stable=false, add_bins_to_sysroot = ["miri"];
868+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["cargo-miri"];
865869
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
866870
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
867871
// 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"];
872+
Rls, "src/tools/rls", "rls", mode=Mode::ToolStd, stable=true;
873+
RustDemangler, "src/tools/rust-demangler", "rust-demangler", mode=Mode::ToolStd, stable=false;
874+
Rustfmt, "src/tools/rustfmt", "rustfmt", mode=Mode::ToolRustc, stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
871875
);
872876

873877
impl<'a> Builder<'a> {

0 commit comments

Comments
 (0)