mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #129650 - Zalathar:profiler-builtins, r=Mark-Simulacrum
Clean up `library/profiler_builtins/build.rs` This PR makes a series of improvements to the long-neglected build script for `profiler_builtins`. Most notably: - The logic that silently skips missing source files has been removed, since it is currently unnecessary and makes build errors more confusing. - The script now emits `cargo::rerun-if-changed` directives for the `compiler-rt` source and include directories. Compiler behaviour and user programs should be unaffected by these changes.
This commit is contained in:
commit
6a96e7a255
@ -1,14 +1,15 @@
|
|||||||
//! Compiles the profiler part of the `compiler-rt` library.
|
//! Compiles the profiler part of the `compiler-rt` library.
|
||||||
//!
|
//!
|
||||||
//! See the build.rs for libcompiler_builtins crate for details.
|
//! Loosely based on:
|
||||||
|
//! - LLVM's `compiler-rt/lib/profile/CMakeLists.txt`
|
||||||
|
//! - <https://github.com/rust-lang/compiler-builtins/blob/master/build.rs>.
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-env-changed=LLVM_PROFILER_RT_LIB");
|
if let Ok(rt) = tracked_env_var("LLVM_PROFILER_RT_LIB") {
|
||||||
if let Ok(rt) = env::var("LLVM_PROFILER_RT_LIB") {
|
println!("cargo::rustc-link-lib=static:+verbatim={rt}");
|
||||||
println!("cargo:rustc-link-lib=static:+verbatim={rt}");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,13 +17,13 @@ fn main() {
|
|||||||
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
|
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV was not set");
|
||||||
let cfg = &mut cc::Build::new();
|
let cfg = &mut cc::Build::new();
|
||||||
|
|
||||||
// FIXME: `rerun-if-changed` directives are not currently emitted and the build script
|
let profile_sources = vec![
|
||||||
// will not rerun on changes in these source files or headers included into them.
|
// tidy-alphabetical-start
|
||||||
let mut profile_sources = vec![
|
|
||||||
"GCDAProfiling.c",
|
"GCDAProfiling.c",
|
||||||
"InstrProfiling.c",
|
"InstrProfiling.c",
|
||||||
"InstrProfilingBuffer.c",
|
"InstrProfilingBuffer.c",
|
||||||
"InstrProfilingFile.c",
|
"InstrProfilingFile.c",
|
||||||
|
"InstrProfilingInternal.c",
|
||||||
"InstrProfilingMerge.c",
|
"InstrProfilingMerge.c",
|
||||||
"InstrProfilingMergeFile.c",
|
"InstrProfilingMergeFile.c",
|
||||||
"InstrProfilingNameVar.c",
|
"InstrProfilingNameVar.c",
|
||||||
@ -37,15 +38,13 @@ fn main() {
|
|||||||
"InstrProfilingValue.c",
|
"InstrProfilingValue.c",
|
||||||
"InstrProfilingVersionVar.c",
|
"InstrProfilingVersionVar.c",
|
||||||
"InstrProfilingWriter.c",
|
"InstrProfilingWriter.c",
|
||||||
// These files were added in LLVM 11.
|
"WindowsMMap.c",
|
||||||
"InstrProfilingInternal.c",
|
// tidy-alphabetical-end
|
||||||
"InstrProfilingBiasVar.c",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if target_env == "msvc" {
|
if target_env == "msvc" {
|
||||||
// Don't pull in extra libraries on MSVC
|
// Don't pull in extra libraries on MSVC
|
||||||
cfg.flag("/Zl");
|
cfg.flag("/Zl");
|
||||||
profile_sources.push("WindowsMMap.c");
|
|
||||||
cfg.define("strdup", Some("_strdup"));
|
cfg.define("strdup", Some("_strdup"));
|
||||||
cfg.define("open", Some("_open"));
|
cfg.define("open", Some("_open"));
|
||||||
cfg.define("fdopen", Some("_fdopen"));
|
cfg.define("fdopen", Some("_fdopen"));
|
||||||
@ -60,8 +59,6 @@ fn main() {
|
|||||||
if target_os != "windows" {
|
if target_os != "windows" {
|
||||||
cfg.flag("-fvisibility=hidden");
|
cfg.flag("-fvisibility=hidden");
|
||||||
cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
|
cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
|
||||||
} else {
|
|
||||||
profile_sources.push("WindowsMMap.c");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,26 +77,33 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the LLVM `compiler-rt` directory from bootstrap.
|
// Get the LLVM `compiler-rt` directory from bootstrap.
|
||||||
println!("cargo:rerun-if-env-changed=RUST_COMPILER_RT_FOR_PROFILER");
|
let root = PathBuf::from(tracked_env_var_or_fallback(
|
||||||
let root = PathBuf::from(env::var("RUST_COMPILER_RT_FOR_PROFILER").unwrap_or_else(|_| {
|
"RUST_COMPILER_RT_FOR_PROFILER",
|
||||||
let path = "../../src/llvm-project/compiler-rt";
|
"../../src/llvm-project/compiler-rt",
|
||||||
println!("RUST_COMPILER_RT_FOR_PROFILER was not set; falling back to {path:?}");
|
));
|
||||||
path.to_owned()
|
|
||||||
}));
|
|
||||||
|
|
||||||
let src_root = root.join("lib").join("profile");
|
let src_root = root.join("lib").join("profile");
|
||||||
assert!(src_root.exists(), "profiler runtime source directory not found: {src_root:?}");
|
assert!(src_root.exists(), "profiler runtime source directory not found: {src_root:?}");
|
||||||
let mut n_sources_found = 0u32;
|
println!("cargo::rerun-if-changed={}", src_root.display());
|
||||||
for src in profile_sources {
|
for file in profile_sources {
|
||||||
let path = src_root.join(src);
|
cfg.file(src_root.join(file));
|
||||||
if path.exists() {
|
|
||||||
cfg.file(path);
|
|
||||||
n_sources_found += 1;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
assert!(n_sources_found > 0, "couldn't find any profiler runtime source files in {src_root:?}");
|
|
||||||
|
|
||||||
cfg.include(root.join("include"));
|
let include = root.join("include");
|
||||||
|
println!("cargo::rerun-if-changed={}", include.display());
|
||||||
|
cfg.include(include);
|
||||||
|
|
||||||
cfg.warnings(false);
|
cfg.warnings(false);
|
||||||
cfg.compile("profiler-rt");
|
cfg.compile("profiler-rt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn tracked_env_var(key: &str) -> Result<String, env::VarError> {
|
||||||
|
println!("cargo::rerun-if-env-changed={key}");
|
||||||
|
env::var(key)
|
||||||
|
}
|
||||||
|
fn tracked_env_var_or_fallback(key: &str, fallback: &str) -> String {
|
||||||
|
tracked_env_var(key).unwrap_or_else(|_| {
|
||||||
|
println!("cargo::warning={key} was not set; falling back to {fallback:?}");
|
||||||
|
fallback.to_owned()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user