Skip to content

build libcxx-version only when it doesn't exist #126472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,19 +823,29 @@ impl Step for LibcxxVersionTool {

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

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

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

builder.run_cmd(&mut cmd);
cmd.arg("-o")
.arg(&executable)
.arg(builder.src.join("src/tools/libcxx-version/main.cpp"));

if !executable.exists() {
panic!("Something went wrong. {} is not present", executable.display());
builder.run_cmd(&mut cmd);

if !executable.exists() {
panic!("Something went wrong. {} is not present", executable.display());
}
}

let version_output = output(&mut Command::new(executable));
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ pub fn check(build: &mut Build) {
eprintln!(
"Consider upgrading libstdc++ or disabling the `llvm.download-ci-llvm` option."
);
eprintln!(
"If you choose to upgrade libstdc++, run `x clean` or delete `build/host/libcxx-version` manually after the upgrade."
);
}
}
tool::LibcxxVersion::Llvm(_) => {
Expand Down
Loading