mirror of https://github.com/rust-lang/rust.git
Use helper functions to read environment variables
This also migrates from legacy `cargo:` directives to the newer `cargo::` prefix.
This commit is contained in:
parent
2c141a4542
commit
fcce75e9a6
|
@ -8,9 +8,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,12 +81,10 @@ 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:?}");
|
||||||
|
@ -105,3 +102,14 @@ fn main() {
|
||||||
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