sensor/build.rs
2022-01-07 22:37:15 +01:00

38 lines
856 B
Rust

extern crate bindgen;
use cc;
use std::path::PathBuf;
use std::env;
fn main() {
println!("cargo:rerun-if-changed=src/pcsensor.c");
bind();
compile_pcsensor();
link();
}
fn bind() {
let bindings = bindgen::Builder::default()
.header("/usr/include/libusb-1.0/libusb.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
fn compile_pcsensor() {
cc::Build::new()
.file("src/pcsensor.c")
.shared_flag(true)
.static_flag(true)
.compile("pcsensor");
}
fn link() {
println!("cargo:rustc-link-lib=pcsensor");
println!("cargo:rustc-link-lib=usb");
}