use std::path::{Path, PathBuf};
fn main() {
let root = if Path::new("../../src/core/rivide_init.c").exists() {
PathBuf::from("../..")
} else if Path::new("c_src/src/core/rivide_init.c").exists() {
PathBuf::from("c_src")
} else if Path::new("deps/src/core/rivide_init.c").exists() {
PathBuf::from("deps")
} else {
PathBuf::from(".")
};
let include_dir = root.join("include");
let src_dir = root.join("src");
let mut build = cc::Build::new();
build
.flag_if_supported("-std=c99")
.flag_if_supported("-O3")
.flag_if_supported("-Wall")
.flag_if_supported("-Wextra")
.flag_if_supported("-Wpedantic")
.include(&include_dir)
.include(&src_dir);
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if target_os == "macos" {
build.define("_DARWIN_C_SOURCE", None);
} else if target_os == "windows" {
build.define("_CRT_SECURE_NO_WARNINGS", None);
}
let c_sources = [
"core/rivide_init.c",
"core/rivide_types.c",
"utils/mem.c",
"utils/random.c",
"crypto/aes_core.c",
"crypto/aes_gcm.c",
"crypto/ghash.c",
"crypto/keccak.c",
"crypto/sha3.c",
"pqc/ntt_simd.c",
"pqc/ml_kem/kem_cbd.c",
"pqc/ml_kem/kem_compress.c",
"pqc/ml_kem/kem_encode.c",
"pqc/ml_kem/kem_ntt.c",
"pqc/ml_kem/kem_poly.c",
"pqc/ml_kem/kem_reduce.c",
"pqc/ml_kem/kem_sampling.c",
"pqc/ml_kem/ml_kem.c",
"pqc/ml_dsa/dsa_ntt.c",
"pqc/ml_dsa/dsa_packing.c",
"pqc/ml_dsa/dsa_poly.c",
"pqc/ml_dsa/dsa_reduce.c",
"pqc/ml_dsa/dsa_rounding.c",
"pqc/ml_dsa/dsa_sampling.c",
"pqc/ml_dsa/ml_dsa.c",
];
for src_rel in &c_sources {
let file_path = src_dir.join(src_rel);
build.file(&file_path);
}
build.compile("rivide_c");
println!("cargo:rerun-if-changed={}", include_dir.display());
println!("cargo:rerun-if-changed={}", src_dir.display());
println!("cargo:rerun-if-changed=build.rs");
}