mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
added spqlios as submodule
This commit is contained in:
52
base2k/build.rs
Normal file
52
base2k/build.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use bindgen;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::absolute;
|
||||
use std::path::PathBuf;
|
||||
use std::time::SystemTime;
|
||||
|
||||
fn main() {
|
||||
// Path to the C header file
|
||||
let header_paths = [
|
||||
"lib/spqlios/coeffs/coeffs_arithmetic.h",
|
||||
"lib/spqlios/arithmetic/vec_znx_arithmetic.h",
|
||||
];
|
||||
|
||||
let out_path: PathBuf = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
let bindings_file = out_path.join("bindings.rs");
|
||||
|
||||
let regenerate: bool = header_paths.iter().any(|header| {
|
||||
let header_metadata: SystemTime = fs::metadata(header)
|
||||
.and_then(|m| m.modified())
|
||||
.unwrap_or(SystemTime::UNIX_EPOCH);
|
||||
let bindings_metadata: SystemTime = fs::metadata(&bindings_file)
|
||||
.and_then(|m| m.modified())
|
||||
.unwrap_or(SystemTime::UNIX_EPOCH);
|
||||
header_metadata > bindings_metadata
|
||||
});
|
||||
|
||||
if regenerate {
|
||||
// Generate the Rust bindings
|
||||
let mut builder: bindgen::Builder = bindgen::Builder::default();
|
||||
for header in header_paths {
|
||||
builder = builder.header(header);
|
||||
}
|
||||
|
||||
let bindings = builder
|
||||
.generate_comments(false) // Optional: includes comments in bindings
|
||||
.generate_inline_functions(true) // Optional: includes inline functions
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
// Write the bindings to the OUT_DIR
|
||||
bindings
|
||||
.write_to_file(&bindings_file)
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
||||
|
||||
println!(
|
||||
"cargo:rustc-link-search=native={}",
|
||||
absolute("./lib/build/spqlios").unwrap().to_str().unwrap()
|
||||
);
|
||||
println!("cargo:rustc-link-lib=static=spqlios"); //"cargo:rustc-link-lib=dylib=spqlios"
|
||||
}
|
||||
Reference in New Issue
Block a user