Files
pyrtest/build.rs
2025-09-08 14:17:51 +02:00

46 lines
1.7 KiB
Rust

use std::env;
use std::path::PathBuf;
fn main() {
// Trying to find python3
let lib = pkg_config::probe_library("python3").expect("Python3 is not available for linking");
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let mut bindings_builder = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("csrc/wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.blocklist_var("FP_INT_UPWARD")
.blocklist_var("FP_NORMAL")
.blocklist_var("FP_SUBNORMAL")
.blocklist_var("FP_INFINITE")
.blocklist_var("FP_INT_TONEAREST")
.blocklist_var("FP_INT_TONEARESTFROMZERO")
.blocklist_var("FP_INT_TOWARDZERO")
.blocklist_var("FP_NAN")
.blocklist_var("FP_ZERO")
.blocklist_var("FP_INT_DOWNWARD");
// Finish the builder and generate the bindings.
for path in lib.include_paths {
let Some(lib_path) = path.as_path().to_str() else {
continue;
};
bindings_builder = bindings_builder.clang_arg(format!("-I{}", lib_path));
}
let bindings = bindings_builder
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}