Skip to content

Commit

Permalink
allow per-target env detection (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Torrekie <31795847+Torrekie@users.noreply.github.com>
  • Loading branch information
Torrekie authored Jul 14, 2024
1 parent 5a82b9d commit 2fde3d8
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions jemalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,28 @@ macro_rules! warning {
}
}

fn read_and_watch_env_impl<T, F>(name: &str, env_getter: F) -> Option<T>
where
F: Fn(&str) -> Option<T>,
{
let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_");
let prefixed_name = format!("{}_{}", prefix, name);

println!("cargo:rerun-if-env-changed={}", prefixed_name);
if let Some(value) = env_getter(&prefixed_name) {
return Some(value);
}

println!("cargo:rerun-if-env-changed={}", name);
env_getter(name)
}

fn read_and_watch_env(name: &str) -> Result<String, env::VarError> {
println!("cargo:rerun-if-env-changed={name}");
env::var(name)
read_and_watch_env_impl(name, |n| env::var(n).ok()).ok_or(env::VarError::NotPresent)
}

fn read_and_watch_env_os(name: &str) -> Option<OsString> {
println!("cargo:rerun-if-env-changed={name}");
env::var_os(name)
read_and_watch_env_impl(name, |n| env::var_os(n))
}

fn copy_recursively(src: &Path, dst: &Path) -> io::Result<()> {
Expand Down

0 comments on commit 2fde3d8

Please sign in to comment.