-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.rs
40 lines (34 loc) · 1.02 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::env;
use std::path::PathBuf;
macro_rules! set_rustc_env_var {
($name: expr, $value: expr) => {{
println!("cargo:rustc-env={}={}", $name, $value);
}};
}
macro_rules! set_env_var_if_absent {
($name: expr, $default_value: expr) => {{
if let Err(_) = env::var($name) {
set_rustc_env_var!($name, $default_value);
}
}};
}
macro_rules! set_specific_path_if_absent {
($env_name: expr, $env_default: expr, $name: expr, $default_value: expr) => {{
let prefix = env::var($env_name).unwrap_or(String::from($env_default));
let mut value = PathBuf::new();
value.push(prefix);
value.push($default_value);
set_env_var_if_absent!($name, value.to_str().unwrap());
}};
}
macro_rules! set_runstate_path_if_absent {
($name: expr, $default_value: expr) => {{
set_specific_path_if_absent!("RUNSTATEDIR", "/run", $name, $default_value);
}};
}
fn main() {
if let Ok(target) = env::var("TARGET") {
println!("cargo:rustc-env=TACD_TARGET={target}");
};
set_runstate_path_if_absent!("TACD_DEFAULT_PID_FILE", "tacd.pid");
}