arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/base2k/build.rs
base2k/build.rsRaw
 1//use bindgen;
 2//use std::env;
 3//use std::fs;
 4use std::path::absolute;
 5//use std::path::PathBuf;
 6//use std::time::SystemTime;
 7
 8fn main() {
 9    /*
10
11    [build-dependencies]
12    bindgen ="0.71.1"
13
14    // Path to the C header file
15    let header_paths: [&str; 2] = [
16        "spqlios-arithmetic/spqlios/coeffs/coeffs_arithmetic.h",
17        "spqlios-arithmetic/spqlios/arithmetic/vec_znx_arithmetic.h",
18    ];
19
20    let out_path: PathBuf = PathBuf::from(env::var("OUT_DIR").unwrap());
21    let bindings_file = out_path.join("bindings.rs");
22
23    let regenerate: bool = header_paths.iter().any(|header| {
24        let header_metadata: SystemTime = fs::metadata(header)
25            .and_then(|m| m.modified())
26            .unwrap_or(SystemTime::UNIX_EPOCH);
27        let bindings_metadata: SystemTime = fs::metadata(&bindings_file)
28            .and_then(|m| m.modified())
29            .unwrap_or(SystemTime::UNIX_EPOCH);
30        header_metadata > bindings_metadata
31    });
32
33    if regenerate {
34        // Generate the Rust bindings
35        let mut builder: bindgen::Builder = bindgen::Builder::default();
36        for header in header_paths {
37            builder = builder.header(header);
38        }
39
40        let bindings = builder
41            .generate_comments(false) // Optional: includes comments in bindings
42            .generate_inline_functions(true) // Optional: includes inline functions
43            .generate()
44            .expect("Unable to generate bindings");
45
46        // Write the bindings to the OUT_DIR
47        bindings
48            .write_to_file(&bindings_file)
49            .expect("Couldn't write bindings!");
50    }
51    */
52
53    println!(
54        "cargo:rustc-link-search=native={}",
55        absolute("./spqlios-arithmetic/build/spqlios")
56            .unwrap()
57            .to_str()
58            .unwrap()
59    );
60    println!("cargo:rustc-link-lib=static=spqlios"); //"cargo:rustc-link-lib=dylib=spqlios"
61}