You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. use std::env;
  2. use std::path::PathBuf;
  3. macro_rules! set_rustc_env_var {
  4. ($name: expr, $value: expr) => {{
  5. println!("cargo:rustc-env={}={}", $name, $value);
  6. }};
  7. }
  8. macro_rules! set_env_var_if_absent {
  9. ($name: expr, $default_value: expr) => {{
  10. if let Err(_) = env::var($name) {
  11. set_rustc_env_var!($name, $default_value);
  12. }
  13. }};
  14. }
  15. macro_rules! set_specific_path_if_absent {
  16. ($env_name: expr, $env_default: expr, $name: expr, $default_value: expr) => {{
  17. let prefix = env::var($env_name).unwrap_or(String::from($env_default));
  18. let mut value = PathBuf::new();
  19. value.push(prefix);
  20. value.push($default_value);
  21. set_env_var_if_absent!($name, value.to_str().unwrap());
  22. }};
  23. }
  24. macro_rules! set_runstate_path_if_absent {
  25. ($name: expr, $default_value: expr) => {{
  26. set_specific_path_if_absent!("RUNSTATEDIR", "/run", $name, $default_value);
  27. }};
  28. }
  29. fn main() {
  30. if let Ok(target) = env::var("TARGET") {
  31. println!("cargo:rustc-env=TACD_TARGET={}", target);
  32. };
  33. set_runstate_path_if_absent!("TACD_DEFAULT_PID_FILE", "tacd.pid");
  34. }