Skip to content

Commit 234a2b5

Browse files
committed
make LlvmBitcodeLinker and Rustdoc to use ToolBuild
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 2558413 commit 234a2b5

File tree

1 file changed

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

1 file changed

+40
-105
lines changed

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

+40-105
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Step for ToolBuild {
8484
//
8585
// Compiler tools should be linked in the same way as the compiler it's paired with,
8686
// so it must be built with the previous stage compiler.
87-
self.compiler.stage -= 1
87+
self.compiler.stage -= 1;
8888
}
8989
Mode::ToolStd => builder.ensure(compile::Std::new(self.compiler, self.target)),
9090
Mode::ToolBootstrap => {}
@@ -580,118 +580,74 @@ impl Step for Rustdoc {
580580
}
581581

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

592593
let bin_rustdoc = || {
593-
let sysroot = builder.sysroot(target_compiler);
594+
let sysroot = builder.sysroot(compiler);
594595
let bindir = sysroot.join("bin");
595596
t!(fs::create_dir_all(&bindir));
596-
let bin_rustdoc = bindir.join(exe("rustdoc", target_compiler.host));
597+
let bin_rustdoc = bindir.join(exe("rustdoc", target));
597598
let _ = fs::remove_file(&bin_rustdoc);
598599
bin_rustdoc
599600
};
600601

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

609610
// Check if unchanged
610611
if builder.config.last_modified_commit(files_to_track, "download-rustc", true).is_some()
611612
{
612-
let precompiled_rustdoc = builder
613-
.config
614-
.ci_rustc_dir()
615-
.join("bin")
616-
.join(exe("rustdoc", target_compiler.host));
613+
let precompiled_rustdoc =
614+
builder.config.ci_rustc_dir().join("bin").join(exe("rustdoc", target));
617615

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

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

653-
// NOTE: Never modify the rustflags here, it breaks the build cache for other tools!
654-
let mut cargo = prepare_tool_cargo(
655-
builder,
656-
build_compiler,
657-
Mode::ToolRustc,
634+
let tool_rustdoc = builder.ensure(ToolBuild {
635+
compiler,
658636
target,
659-
Kind::Build,
660-
"src/tools/rustdoc",
661-
SourceType::InTree,
662-
features.as_slice(),
663-
);
664-
665-
// rustdoc is performance sensitive, so apply LTO to it.
666-
let lto = match builder.config.rust_lto {
667-
RustcLto::Off => Some("off"),
668-
RustcLto::Thin => Some("thin"),
669-
RustcLto::Fat => Some("fat"),
670-
RustcLto::ThinLocal => None,
671-
};
672-
if let Some(lto) = lto {
673-
cargo.env(cargo_profile_var("LTO", &builder.config), lto);
674-
}
675-
676-
let _guard = builder.msg_tool(
677-
Kind::Build,
678-
Mode::ToolRustc,
679-
"rustdoc",
680-
build_compiler.stage,
681-
&self.compiler.host,
682-
&target,
683-
);
684-
cargo.into_cmd().run(builder);
685-
686637
// Cargo adds a number of paths to the dylib search path on windows, which results in
687638
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
688639
// rustdoc a different name.
689-
let tool_rustdoc = builder
690-
.cargo_out(build_compiler, Mode::ToolRustc, target)
691-
.join(exe("rustdoc_tool_binary", target_compiler.host));
640+
tool: "rustdoc_tool_binary",
641+
mode: Mode::ToolRustc,
642+
path: "src/tools/rustdoc",
643+
source_type: SourceType::InTree,
644+
extra_features,
645+
allow_features: "",
646+
cargo_args: Vec::new(),
647+
});
692648

693649
// don't create a stage0-sysroot/bin directory.
694-
if target_compiler.stage > 0 {
650+
if compiler.stage > 0 {
695651
if builder.config.rust_debuginfo_level_tools == DebuginfoLevel::None {
696652
// Due to LTO a lot of debug info from C++ dependencies such as jemalloc can make it into
697653
// our final binaries
@@ -916,50 +872,29 @@ impl Step for LlvmBitcodeLinker {
916872
}
917873

918874
fn run(self, builder: &Builder<'_>) -> PathBuf {
919-
let bin_name = "llvm-bitcode-linker";
920-
921-
// If enabled, use ci-rustc and skip building the in-tree compiler.
922-
if !builder.download_rustc() {
923-
builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
924-
builder.ensure(compile::Rustc::new(self.compiler, self.target));
925-
}
926-
927-
let cargo = prepare_tool_cargo(
928-
builder,
929-
self.compiler,
930-
Mode::ToolRustc,
931-
self.target,
932-
Kind::Build,
933-
"src/tools/llvm-bitcode-linker",
934-
SourceType::InTree,
935-
&self.extra_features,
936-
);
937-
938-
let _guard = builder.msg_tool(
939-
Kind::Build,
940-
Mode::ToolRustc,
941-
bin_name,
942-
self.compiler.stage,
943-
&self.compiler.host,
944-
&self.target,
945-
);
946-
947-
cargo.into_cmd().run(builder);
948-
949-
let tool_out = builder
950-
.cargo_out(self.compiler, Mode::ToolRustc, self.target)
951-
.join(exe(bin_name, self.compiler.host));
875+
let bin_source = builder.ensure(ToolBuild {
876+
compiler: self.compiler,
877+
target: self.target,
878+
tool: "llvm-bitcode-linker",
879+
mode: Mode::ToolRustc,
880+
path: "src/tools/llvm-bitcode-linker",
881+
source_type: SourceType::InTree,
882+
extra_features: self.extra_features,
883+
allow_features: "",
884+
cargo_args: Vec::new(),
885+
});
952886

953887
if self.compiler.stage > 0 {
954888
let bindir_self_contained = builder
955889
.sysroot(self.compiler)
956890
.join(format!("lib/rustlib/{}/bin/self-contained", self.target.triple));
957891
t!(fs::create_dir_all(&bindir_self_contained));
958-
let bin_destination = bindir_self_contained.join(exe(bin_name, self.compiler.host));
959-
builder.copy_link(&tool_out, &bin_destination);
892+
let bin_destination =
893+
bindir_self_contained.join(exe("llvm-bitcode-linker", self.compiler.host));
894+
builder.copy_link(&bin_source, &bin_destination);
960895
bin_destination
961896
} else {
962-
tool_out
897+
bin_source
963898
}
964899
}
965900
}

0 commit comments

Comments
 (0)