Skip to content

Commit 0fd667c

Browse files
authored
Rollup merge of #126472 - onur-ozkan:improve-libcxx-build, r=Kobzol
build `libcxx-version` only when it doesn't exist In #126423, it seems like c++ parsing takes quite amount of time on bootstrap startups. This PR makes libcxx-version to be compiled only when it doesn't exist. A simple demonstration on the overhead of buiding `libcxx-version`: ```sh $ rm -rf build/host/libcxx-version $ x build Building bootstrap Finished `dev` profile [unoptimized] target(s) in 0.07s ----- LIBCXX VERSION CHECK TOOK: 509ms Building tool rustdoc (stage1 -> stage2, x86_64-unknown-linux-gnu) Finished `release` profile [optimized] target(s) in 0.25s Build completed successfully in 0:00:02 $ x build Building bootstrap Finished `dev` profile [unoptimized] target(s) in 0.07s ----- LIBCXX VERSION CHECK TOOK: 2ms Creating a sysroot for stage2 compiler (use `rustup toolchain link 'name' build/host/stage2`) Building tool rustdoc (stage1 -> stage2, x86_64-unknown-linux-gnu) Finished `release` profile [optimized] target(s) in 0.14s Build completed successfully in 0:00:01 ```
2 parents 8520129 + e2e1afa commit 0fd667c

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

+19-9
Original file line numberDiff line numberDiff line change
@@ -823,19 +823,29 @@ impl Step for LibcxxVersionTool {
823823

824824
fn run(self, builder: &Builder<'_>) -> LibcxxVersion {
825825
let out_dir = builder.out.join(self.target.to_string()).join("libcxx-version");
826-
let _ = fs::remove_dir_all(&out_dir);
827-
t!(fs::create_dir_all(&out_dir));
826+
let executable = out_dir.join(exe("libcxx-version", self.target));
828827

829-
let compiler = builder.cxx(self.target).unwrap();
830-
let mut cmd = Command::new(compiler);
828+
// This is a sanity-check specific step, which means it is frequently called (when using
829+
// CI LLVM), and compiling `src/tools/libcxx-version/main.cpp` at the beginning of the bootstrap
830+
// invocation adds a fair amount of overhead to the process (see https://github.com/rust-lang/rust/issues/126423).
831+
// Therefore, we want to avoid recompiling this file unnecessarily.
832+
if !executable.exists() {
833+
if !out_dir.exists() {
834+
t!(fs::create_dir_all(&out_dir));
835+
}
831836

832-
let executable = out_dir.join(exe("libcxx-version", self.target));
833-
cmd.arg("-o").arg(&executable).arg(builder.src.join("src/tools/libcxx-version/main.cpp"));
837+
let compiler = builder.cxx(self.target).unwrap();
838+
let mut cmd = Command::new(compiler);
834839

835-
builder.run_cmd(&mut cmd);
840+
cmd.arg("-o")
841+
.arg(&executable)
842+
.arg(builder.src.join("src/tools/libcxx-version/main.cpp"));
836843

837-
if !executable.exists() {
838-
panic!("Something went wrong. {} is not present", executable.display());
844+
builder.run_cmd(&mut cmd);
845+
846+
if !executable.exists() {
847+
panic!("Something went wrong. {} is not present", executable.display());
848+
}
839849
}
840850

841851
let version_output = output(&mut Command::new(executable));

src/bootstrap/src/core/sanity.rs

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub fn check(build: &mut Build) {
129129
eprintln!(
130130
"Consider upgrading libstdc++ or disabling the `llvm.download-ci-llvm` option."
131131
);
132+
eprintln!(
133+
"If you choose to upgrade libstdc++, run `x clean` or delete `build/host/libcxx-version` manually after the upgrade."
134+
);
132135
}
133136
}
134137
tool::LibcxxVersion::Llvm(_) => {

0 commit comments

Comments
 (0)