Skip to content

Commit 4de4deb

Browse files
committed
Auto merge of rust-lang#129295 - Zalathar:profiler-builtins, r=Kobzol
Build `library/profiler_builtins` from `ci-llvm` if appropriate Running all of `tests/coverage` requires the LLVM profiler runtime, which requires setting `build.profiler = true`. Historically, doing that has required checking out the entire `src/llvm-project` submodule. For compiler contributors who otherwise don't need that submodule (thanks to `download-ci-vm`), that's quite inconvenient. However, thanks to rust-lang#129116, the downloaded CI LLVM tarball now contains a copy of LLVM's `compiler-rt` directory, which includes all the files needed to build the profiler runtime. So with a little bit of extra logic in bootstrap, we can have `library/profiler_builtins` look for the `compiler-rt` files in `ci-llvm` instead of the `src/llvm-project` submodule.
2 parents 8dafd33 + a437005 commit 4de4deb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: profiler_builtins/build.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! See the build.rs for libcompiler_builtins crate for details.
44
55
use std::env;
6-
use std::path::Path;
6+
use std::path::PathBuf;
77

88
fn main() {
99
println!("cargo:rerun-if-env-changed=LLVM_PROFILER_RT_LIB");
@@ -79,17 +79,25 @@ fn main() {
7979
cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
8080
}
8181

82-
// Note that this should exist if we're going to run (otherwise we just
83-
// don't build profiler builtins at all).
84-
let root = Path::new("../../src/llvm-project/compiler-rt");
82+
// Get the LLVM `compiler-rt` directory from bootstrap.
83+
println!("cargo:rerun-if-env-changed=RUST_COMPILER_RT_FOR_PROFILER");
84+
let root = PathBuf::from(env::var("RUST_COMPILER_RT_FOR_PROFILER").unwrap_or_else(|_| {
85+
let path = "../../src/llvm-project/compiler-rt";
86+
println!("RUST_COMPILER_RT_FOR_PROFILER was not set; falling back to {path:?}");
87+
path.to_owned()
88+
}));
8589

8690
let src_root = root.join("lib").join("profile");
91+
assert!(src_root.exists(), "profiler runtime source directory not found: {src_root:?}");
92+
let mut n_sources_found = 0u32;
8793
for src in profile_sources {
8894
let path = src_root.join(src);
8995
if path.exists() {
9096
cfg.file(path);
97+
n_sources_found += 1;
9198
}
9299
}
100+
assert!(n_sources_found > 0, "couldn't find any profiler runtime source files in {src_root:?}");
93101

94102
cfg.include(root.join("include"));
95103
cfg.warnings(false);

0 commit comments

Comments
 (0)