You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
extern crate bindgen; |
|
extern crate pkg_config; |
|
|
|
use std::env; |
|
use std::path::PathBuf; |
|
|
|
fn main() { |
|
let pkgconfig = pkg_config::Config::new(); |
|
let mraa_config = pkgconfig |
|
.probe("mraa") |
|
.expect("pkg_config probe failed for mraa"); |
|
|
|
let _ = pkgconfig |
|
.probe("json-c"); |
|
// .expect("pkg_config probe failed for json-c"); |
|
|
|
// Tell cargo to invalidate the built crate whenever the wrapper changes |
|
println!("cargo:rerun-if-changed=src/wrapper.h"); |
|
|
|
let mut clang_args: Vec<String> = Vec::new(); |
|
for include_dir in &mraa_config.include_paths { |
|
clang_args.push("-I".to_owned()); |
|
clang_args.push(include_dir.to_str().unwrap().to_owned()); |
|
} |
|
|
|
// The bindgen::Builder is the main entry point |
|
// to bindgen, and lets you build up options for |
|
// the resulting bindings. |
|
let mraa_bindings = bindgen::Builder::default() |
|
.clang_args(clang_args) |
|
// The input header we would like to generate |
|
// bindings for. |
|
.header("src/wrapper.h") |
|
.whitelist_type("mraa_.*") |
|
.whitelist_function("mraa_.*") |
|
.whitelist_var("mraa_.*") |
|
// Tell cargo to invalidate the built crate whenever any of the |
|
// included header files changed. |
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks)) |
|
// 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()); |
|
mraa_bindings |
|
.write_to_file(out_path.join("mraa_bindings.rs")) |
|
.expect("Couldn't write bindings!"); |
|
}
|
|
|