khepera4-sys 0.1.0

APIs for controlling a Khepera IV robot.
Documentation
use std::env;
use std::path::PathBuf;

fn main() {
    // Ask Cargo to link the libkhepera library.
    println!("cargo:rustc-link-lib=khepera");

    // Ask Cargo to invalidate the build cache
    // when the Khepera headers change.
    println!("cargo:rerun-if-changed=vendor/libkhepera/khepera.h");

    // Exit early if the architecture is incorrect.
    if env::var("CARGO_CFG_TARGET_ARCH").unwrap() != "arm" {
        eprintln!("Khepera system libraries may only be built on ARM platforms.");
        return;
    }

    // Generate C bindings.
    let bindings = bindgen::Builder::default()
        // Bind to the Khepera SDK sysroot.
        .clang_arg("--sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi")
        // Generate bindings for the Khepera header.
        .header("vendor/libkhepera/khepera.h")
        // Invalidate the build cache whenever any
        // included headers change.
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        // Disallow bindings for numeric constants in the
        // khepera libraries that get defined many times.
        .blocklist_item("FP_NAN")
        .blocklist_item("FP_INFINITE")
        .blocklist_item("FP_ZERO")
        .blocklist_item("FP_SUBNORMAL")
        .blocklist_item("FP_NORMAL")
        // Generate bindings.
        .generate()
        .expect("Unable to generate bindings");

    // Write the bindings to the $OUT_DIR/libkhepera.rs file.
    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("libkhepera.rs"))
        .expect("Couldn't write bindings!");
}