43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
|
extern crate bindgen;
|
||
|
|
||
|
use std::{env, path::PathBuf};
|
||
|
|
||
|
fn main() {
|
||
|
let zephyr_sdk_install_dir = PathBuf::from(env::var("ZEPHYR_SDK_INSTALL_DIR").unwrap());
|
||
|
|
||
|
let bindings = bindgen::Builder::default()
|
||
|
// Only use core, as we are in embedded land
|
||
|
.use_core()
|
||
|
// The input header we would like to generate
|
||
|
// bindings for.
|
||
|
.header("src/wrapper.h")
|
||
|
.clang_args(
|
||
|
env::var("TARGET_CFLAGS")
|
||
|
.unwrap()
|
||
|
.split(' ')
|
||
|
.filter(|&el| el != "-mfp16-format=ieee" && el != "-fno-reorder-functions"),
|
||
|
)
|
||
|
.clang_arg(format!(
|
||
|
"-I{}",
|
||
|
zephyr_sdk_install_dir
|
||
|
.join("arm-zephyr-eabi/arm-zephyr-eabi/sys-include")
|
||
|
.to_str()
|
||
|
.unwrap()
|
||
|
))
|
||
|
// only allow CONFIG_ defines
|
||
|
.allowlist_item("^CONFIG_.*")
|
||
|
// Tell cargo to invalidate the built crate whenever any of the
|
||
|
// included header files changed.
|
||
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||
|
// Finish the builder and generate the bindings.
|
||
|
.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!");
|
||
|
}
|