Skip to content

Commit c542009

Browse files
committed
make LlvmBitcodeLinker and Rustdoc to use ToolBuild
Signed-off-by: onur-ozkan <[email protected]>
1 parent 3d8b402 commit c542009

File tree

1 file changed

+40
-94
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+40
-94
lines changed

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

+40-94
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Step for ToolBuild {
8282
//
8383
// Compiler tools should be linked in the same way as the compiler it's paired with,
8484
// so it must be built with the previous stage compiler.
85-
self.compiler.stage -= 1
85+
self.compiler.stage -= 1;
8686
}
8787
Mode::ToolStd => builder.ensure(compile::Std::new(self.compiler, self.target)),
8888
Mode::ToolBootstrap => {}
@@ -578,107 +578,74 @@ impl Step for Rustdoc {
578578
}
579579

580580
fn run(self, builder: &Builder<'_>) -> PathBuf {
581-
let target_compiler = self.compiler;
582-
if target_compiler.stage == 0 {
583-
if !target_compiler.is_snapshot(builder) {
581+
let compiler = self.compiler;
582+
let target = compiler.host;
583+
584+
if compiler.stage == 0 {
585+
if !compiler.is_snapshot(builder) {
584586
panic!("rustdoc in stage 0 must be snapshot rustdoc");
585587
}
586-
return builder.initial_rustc.with_file_name(exe("rustdoc", target_compiler.host));
588+
return builder.initial_rustc.with_file_name(exe("rustdoc", compiler.host));
587589
}
588-
let target = target_compiler.host;
589590

590591
let bin_rustdoc = || {
591-
let sysroot = builder.sysroot(target_compiler);
592+
let sysroot = builder.sysroot(compiler);
592593
let bindir = sysroot.join("bin");
593594
t!(fs::create_dir_all(&bindir));
594-
let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host));
595+
let bin_rustdoc = bindir.join(exe("rustdoc", target));
595596
let _ = fs::remove_file(&bin_rustdoc);
596597
bin_rustdoc
597598
};
598599

599600
// If CI rustc is enabled and we haven't modified the rustdoc sources,
600601
// use the precompiled rustdoc from CI rustc's sysroot to speed up bootstrapping.
601602
if builder.download_rustc()
602-
&& target_compiler.stage > 0
603+
&& compiler.stage > 0
603604
&& builder.rust_info().is_managed_git_subrepository()
604605
{
605606
let files_to_track = &["src/librustdoc", "src/tools/rustdoc"];
606607

607608
// Check if unchanged
608609
if builder.config.last_modified_commit(files_to_track, "download-rustc", true).is_some()
609610
{
610-
let precompiled_rustdoc = builder
611-
.config
612-
.ci_rustc_dir()
613-
.join("bin")
614-
.join(exe("rustdoc", target_compiler.host));
611+
let precompiled_rustdoc =
612+
builder.config.ci_rustc_dir().join("bin").join(exe("rustdoc", target));
615613

616614
let bin_rustdoc = bin_rustdoc();
617615
builder.copy_link(&precompiled_rustdoc, &bin_rustdoc);
618616
return bin_rustdoc;
619617
}
620618
}
621619

622-
let build_compiler = if builder.download_rustc() && target_compiler.stage == 1 {
623-
// We already have the stage 1 compiler, we don't need to cut the stage.
624-
builder.compiler(target_compiler.stage, builder.config.build)
625-
} else {
626-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
627-
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
628-
// compilers, which isn't what we want. Rustdoc should be linked in the same way as the
629-
// rustc compiler it's paired with, so it must be built with the previous stage compiler.
630-
builder.compiler(target_compiler.stage - 1, builder.config.build)
631-
};
632-
633-
// When using `download-rustc` and a stage0 build_compiler, copying rustc doesn't actually
634-
// build stage0 libstd (because the libstd in sysroot has the wrong ABI). Explicitly build
635-
// it.
636-
builder.ensure(compile::Std::new(build_compiler, target_compiler.host));
637-
builder.ensure(compile::Rustc::new(build_compiler, target_compiler.host));
638-
639620
// The presence of `target_compiler` ensures that the necessary libraries (codegen backends,
640621
// compiler libraries, ...) are built. Rustdoc does not require the presence of any
641622
// libraries within sysroot_libdir (i.e., rustlib), though doctests may want it (since
642623
// they'll be linked to those libraries). As such, don't explicitly `ensure` any additional
643624
// libraries here. The intuition here is that If we've built a compiler, we should be able
644625
// to build rustdoc.
645626
//
646-
let mut features = Vec::new();
627+
let mut extra_features = Vec::new();
647628
if builder.config.jemalloc {
648-
features.push("jemalloc".to_string());
629+
extra_features.push("jemalloc".to_string());
649630
}
650631

651-
// NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
652-
let cargo = prepare_tool_cargo(
653-
builder,
654-
build_compiler,
655-
Mode::ToolRustc,
632+
let tool_rustdoc = builder.ensure(ToolBuild {
633+
compiler,
656634
target,
657-
Kind::Build,
658-
"src/tools/rustdoc",
659-
SourceType::InTree,
660-
features.as_slice(),
661-
);
662-
663-
let _guard = builder.msg_tool(
664-
Kind::Build,
665-
Mode::ToolRustc,
666-
"rustdoc",
667-
build_compiler.stage,
668-
&self.compiler.host,
669-
&target,
670-
);
671-
cargo.into_cmd().run(builder);
672-
673635
// Cargo adds a number of paths to the dylib search path on windows, which results in
674636
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
675637
// rustdoc a different name.
676-
let tool_rustdoc = builder
677-
.cargo_out(build_compiler, Mode::ToolRustc, target)
678-
.join(exe("rustdoc_tool_binary", target_compiler.host));
638+
tool: "rustdoc_tool_binary",
639+
mode: Mode::ToolRustc,
640+
path: "src/tools/rustdoc",
641+
source_type: SourceType::InTree,
642+
extra_features,
643+
allow_features: "",
644+
cargo_args: Vec::new(),
645+
});
679646

680647
// don't create a stage0-sysroot/bin directory.
681-
if target_compiler.stage > 0 {
648+
if compiler.stage > 0 {
682649
if builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None {
683650
// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
684651
// our final binaries
@@ -903,50 +870,29 @@ impl Step for LlvmBitcodeLinker {
903870
}
904871

905872
fn run(self, builder: &Builder<'_>) -> PathBuf {
906-
let bin_name = "llvm-bitcode-linker";
907-
908-
// If enabled, use ci-rustc and skip building the in-tree compiler.
909-
if !builder.download_rustc() {
910-
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
911-
builder.ensure(compile::Rustc::new(self.compiler, self.target));
912-
}
913-
914-
let cargo = prepare_tool_cargo(
915-
builder,
916-
self.compiler,
917-
Mode::ToolRustc,
918-
self.target,
919-
Kind::Build,
920-
"src/tools/llvm-bitcode-linker",
921-
SourceType::InTree,
922-
&self.extra_features,
923-
);
924-
925-
let _guard = builder.msg_tool(
926-
Kind::Build,
927-
Mode::ToolRustc,
928-
bin_name,
929-
self.compiler.stage,
930-
&self.compiler.host,
931-
&self.target,
932-
);
933-
934-
cargo.into_cmd().run(builder);
935-
936-
let tool_out = builder
937-
.cargo_out(self.compiler, Mode::ToolRustc, self.target)
938-
.join(exe(bin_name, self.compiler.host));
873+
let bin_source = builder.ensure(ToolBuild {
874+
compiler: self.compiler,
875+
target: self.target,
876+
tool: "llvm-bitcode-linker",
877+
mode: Mode::ToolRustc,
878+
path: "src/tools/llvm-bitcode-linker",
879+
source_type: SourceType::InTree,
880+
extra_features: self.extra_features,
881+
allow_features: "",
882+
cargo_args: Vec::new(),
883+
});
939884

940885
if self.compiler.stage > 0 {
941886
let bindir_self_contained = builder
942887
.sysroot(self.compiler)
943888
.join(format!("lib/rustlib/{}/bin/self-contained", self.target.triple));
944889
t!(fs::create_dir_all(&bindir_self_contained));
945-
let bin_destination = bindir_self_contained.join(exe(bin_name, self.compiler.host));
946-
builder.copy_link(&tool_out, &bin_destination);
890+
let bin_destination =
891+
bindir_self_contained.join(exe("llvm-bitcode-linker", self.compiler.host));
892+
builder.copy_link(&bin_source, &bin_destination);
947893
bin_destination
948894
} else {
949-
tool_out
895+
bin_source
950896
}
951897
}
952898
}

0 commit comments

Comments
 (0)