sensor/build.rs
2023-11-08 17:11:32 +01:00

38 lines
879 B
Rust

extern crate bindgen;
use cc;
use std::env;
use std::path::PathBuf;
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::new()))
.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");
}