2024-05-29 18:39:54 +02:00
|
|
|
use std::{env, path::PathBuf};
|
|
|
|
|
2024-05-31 12:52:55 +02:00
|
|
|
use libcsp_cargo_build::{generate_autoconf_header_file, Builder};
|
2024-05-29 18:39:54 +02:00
|
|
|
|
|
|
|
fn main() {
|
2024-05-29 20:14:53 +02:00
|
|
|
let out_dir = env::var("OUT_DIR").unwrap_or_default();
|
2024-05-31 12:35:29 +02:00
|
|
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
|
2024-05-31 12:52:55 +02:00
|
|
|
let manifest_path = PathBuf::from(&manifest_dir);
|
2024-06-01 00:50:02 +02:00
|
|
|
let lib_cfg_dir = "../lib/cfg/csp";
|
2024-05-29 20:14:53 +02:00
|
|
|
let libcsp_path = "../lib/libcsp";
|
2024-06-01 01:18:15 +02:00
|
|
|
|
|
|
|
// This helper structure will take care of the majority of work to compile libcsp using the
|
|
|
|
// cc crate.
|
2024-05-31 12:35:29 +02:00
|
|
|
let mut csp_builder = Builder::new(PathBuf::from(libcsp_path), PathBuf::from(&out_dir));
|
2024-06-01 01:18:15 +02:00
|
|
|
// A lot of spam we are not interested in usually.
|
2024-05-31 19:48:12 +02:00
|
|
|
csp_builder.compiler_warnings = false;
|
2024-06-01 01:18:15 +02:00
|
|
|
|
2024-05-31 12:52:55 +02:00
|
|
|
// We always re-generate the header file.
|
|
|
|
generate_autoconf_header_file(manifest_path.clone(), &csp_builder.cfg)
|
|
|
|
.expect("generating header file failed");
|
2024-06-01 01:18:15 +02:00
|
|
|
|
2024-06-01 00:50:02 +02:00
|
|
|
// Copy the file to lib/csp/cfg as well for binding generation.
|
|
|
|
std::fs::copy(
|
|
|
|
manifest_path.join("autoconfig.h"),
|
|
|
|
PathBuf::from(&lib_cfg_dir).join("autoconfig.h"),
|
|
|
|
)
|
|
|
|
.expect("copying autoconfig.h failed");
|
2024-06-01 01:18:15 +02:00
|
|
|
|
|
|
|
// This file is required for the compile-time configuration of libcsp-rust.
|
2024-05-31 12:52:55 +02:00
|
|
|
csp_builder
|
|
|
|
.generate_autoconf_rust_file(manifest_path)
|
|
|
|
.expect("generating autoconfig.rs failed");
|
2024-06-01 01:18:15 +02:00
|
|
|
|
2024-05-29 20:14:53 +02:00
|
|
|
csp_builder.compile().expect("compiling libcsp failed");
|
2024-06-01 01:18:15 +02:00
|
|
|
|
2024-05-31 12:52:55 +02:00
|
|
|
// If we change the libcsp build configuration, we need to re-run the build.
|
|
|
|
println!("cargo::rerun-if-changed=build.rs");
|
2024-05-29 18:39:54 +02:00
|
|
|
}
|