libcsp-rust/libcsp-sys/build.rs

47 lines
1.5 KiB
Rust
Raw Normal View History

2024-05-29 00:25:05 +02:00
use std::{env, path::PathBuf};
pub const ENV_KEY_CSP_CONFIG_DIR: &str = "CSP_CONFIG_DIR";
2024-06-01 18:59:27 +02:00
pub const ENV_KEY_TEST: &str = "RUN_TESTS";
2024-05-29 00:25:05 +02:00
fn main() {
2024-06-01 18:59:27 +02:00
// libcsp is built in a separate project, so linking it for tests will fail.
// For tests, we do not want to have the link directive to csp.
let run_tests = if let Ok(val) = env::var(ENV_KEY_TEST) {
val == "1"
} else {
false
};
if !run_tests {
println!("cargo:rustc-link-lib=csp");
}
2024-05-29 00:25:05 +02:00
2024-06-01 20:27:41 +02:00
let mut csp_conf_path = if std::env::var("DOCS_RS").is_ok() {
PathBuf::from("./templates")
} else {
match env::var(ENV_KEY_CSP_CONFIG_DIR) {
Ok(conf_path) => conf_path.into(),
Err(_e) => {
println!(
2024-05-29 00:25:05 +02:00
"cargo:warning={} not set, using CARGO_MANIFEST_DIR to search for autoconfig.rs",
ENV_KEY_CSP_CONFIG_DIR
);
2024-06-01 20:27:41 +02:00
env::var("CARGO_MANIFEST_DIR")
.expect("CARGO_MANIFEST_DIR not set")
.into()
}
2024-05-29 00:25:05 +02:00
}
};
2024-06-01 20:27:41 +02:00
let out_path = env::var("OUT_DIR").unwrap();
2024-05-29 00:25:05 +02:00
csp_conf_path.push("autoconfig.rs");
if !csp_conf_path.exists() {
panic!(
"autoconfig.rs not found at {:?}, is required for library build",
csp_conf_path
);
}
let out_path_full = PathBuf::from(&out_path).join("autoconfig.rs");
std::fs::copy(&csp_conf_path, out_path_full).expect("failed to copy autoconfig.rs to OUT_DIR");
println!("cargo::rerun-if-changed={:?}", &csp_conf_path);
}