mirror of
https://github.com/rust-lang/rust
synced 2024-10-02 23:04:50 +00:00
Allow using external builds of the compiler-rt profile lib
This changes the bootstrap config `target.*.profiler` from a plain bool to also allow a string, which will be used as a path to the pre-built profiling runtime for that target. Then `profiler_builtins/build.rs` reads that in a `LLVM_PROFILER_RT_LIB` environment variable.
This commit is contained in:
parent
4fc6b33474
commit
d0b58f40a0
|
@ -762,8 +762,10 @@ changelog-seen = 2
|
||||||
# This option will override the same option under [build] section.
|
# This option will override the same option under [build] section.
|
||||||
#sanitizers = build.sanitizers (bool)
|
#sanitizers = build.sanitizers (bool)
|
||||||
|
|
||||||
# Build the profiler runtime for this target(required when compiling with options that depend
|
# When true, build the profiler runtime for this target(required when compiling
|
||||||
# on this runtime, such as `-C profile-generate` or `-C instrument-coverage`).
|
# with options that depend on this runtime, such as `-C profile-generate` or
|
||||||
|
# `-C instrument-coverage`). This may also be given a path to an existing build
|
||||||
|
# of the profiling runtime library from LLVM's compiler-rt.
|
||||||
# This option will override the same option under [build] section.
|
# This option will override the same option under [build] section.
|
||||||
#profiler = build.profiler (bool)
|
#profiler = build.profiler (bool)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,12 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
println!("cargo:rerun-if-env-changed=LLVM_PROFILER_RT_LIB");
|
||||||
|
if let Ok(rt) = env::var("LLVM_PROFILER_RT_LIB") {
|
||||||
|
println!("cargo:rustc-link-lib=static:+verbatim={rt}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let target = env::var("TARGET").expect("TARGET was not set");
|
let target = env::var("TARGET").expect("TARGET was not set");
|
||||||
let cfg = &mut cc::Build::new();
|
let cfg = &mut cc::Build::new();
|
||||||
|
|
||||||
|
|
|
@ -323,6 +323,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
|
||||||
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
|
cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(path) = builder.config.profiler_path(target) {
|
||||||
|
cargo.env("LLVM_PROFILER_RT_LIB", path);
|
||||||
|
}
|
||||||
|
|
||||||
// Determine if we're going to compile in optimized C intrinsics to
|
// Determine if we're going to compile in optimized C intrinsics to
|
||||||
// the `compiler-builtins` crate. These intrinsics live in LLVM's
|
// the `compiler-builtins` crate. These intrinsics live in LLVM's
|
||||||
// `compiler-rt` repository, but our `src/llvm-project` submodule isn't
|
// `compiler-rt` repository, but our `src/llvm-project` submodule isn't
|
||||||
|
|
|
@ -533,7 +533,7 @@ pub struct Target {
|
||||||
pub linker: Option<PathBuf>,
|
pub linker: Option<PathBuf>,
|
||||||
pub ndk: Option<PathBuf>,
|
pub ndk: Option<PathBuf>,
|
||||||
pub sanitizers: Option<bool>,
|
pub sanitizers: Option<bool>,
|
||||||
pub profiler: Option<bool>,
|
pub profiler: Option<StringOrBool>,
|
||||||
pub rpath: Option<bool>,
|
pub rpath: Option<bool>,
|
||||||
pub crt_static: Option<bool>,
|
pub crt_static: Option<bool>,
|
||||||
pub musl_root: Option<PathBuf>,
|
pub musl_root: Option<PathBuf>,
|
||||||
|
@ -862,9 +862,9 @@ struct Dist {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum StringOrBool {
|
pub enum StringOrBool {
|
||||||
String(String),
|
String(String),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
}
|
}
|
||||||
|
@ -875,6 +875,12 @@ fn default() -> StringOrBool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StringOrBool {
|
||||||
|
fn is_string_or_true(&self) -> bool {
|
||||||
|
matches!(self, Self::String(_) | Self::Bool(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum RustOptimize {
|
pub enum RustOptimize {
|
||||||
String(String),
|
String(String),
|
||||||
|
@ -1038,7 +1044,7 @@ struct TomlTarget {
|
||||||
llvm_libunwind: Option<String> = "llvm-libunwind",
|
llvm_libunwind: Option<String> = "llvm-libunwind",
|
||||||
android_ndk: Option<String> = "android-ndk",
|
android_ndk: Option<String> = "android-ndk",
|
||||||
sanitizers: Option<bool> = "sanitizers",
|
sanitizers: Option<bool> = "sanitizers",
|
||||||
profiler: Option<bool> = "profiler",
|
profiler: Option<StringOrBool> = "profiler",
|
||||||
rpath: Option<bool> = "rpath",
|
rpath: Option<bool> = "rpath",
|
||||||
crt_static: Option<bool> = "crt-static",
|
crt_static: Option<bool> = "crt-static",
|
||||||
musl_root: Option<String> = "musl-root",
|
musl_root: Option<String> = "musl-root",
|
||||||
|
@ -1951,12 +1957,24 @@ pub fn any_sanitizers_enabled(&self) -> bool {
|
||||||
self.target_config.values().any(|t| t.sanitizers == Some(true)) || self.sanitizers
|
self.target_config.values().any(|t| t.sanitizers == Some(true)) || self.sanitizers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn profiler_path(&self, target: TargetSelection) -> Option<&str> {
|
||||||
|
match self.target_config.get(&target)?.profiler.as_ref()? {
|
||||||
|
StringOrBool::String(s) => Some(s),
|
||||||
|
StringOrBool::Bool(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn profiler_enabled(&self, target: TargetSelection) -> bool {
|
pub fn profiler_enabled(&self, target: TargetSelection) -> bool {
|
||||||
self.target_config.get(&target).map(|t| t.profiler).flatten().unwrap_or(self.profiler)
|
self.target_config
|
||||||
|
.get(&target)
|
||||||
|
.and_then(|t| t.profiler.as_ref())
|
||||||
|
.map(StringOrBool::is_string_or_true)
|
||||||
|
.unwrap_or(self.profiler)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_profiler_enabled(&self) -> bool {
|
pub fn any_profiler_enabled(&self) -> bool {
|
||||||
self.target_config.values().any(|t| t.profiler == Some(true)) || self.profiler
|
self.target_config.values().any(|t| matches!(&t.profiler, Some(p) if p.is_string_or_true()))
|
||||||
|
|| self.profiler
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
|
pub fn rpath_enabled(&self, target: TargetSelection) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue