1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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!");
}