sensor/build.rs

38 lines
879 B
Rust
Raw Normal View History

2022-01-07 22:37:15 +01:00
extern crate bindgen;
use cc;
use std::env;
2023-11-08 17:11:32 +01:00
use std::path::PathBuf;
2022-01-07 22:37:15 +01:00
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")
2023-11-08 17:11:32 +01:00
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
2022-01-07 22:37:15 +01:00
.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()
2023-11-08 17:11:32 +01:00
.file("src/pcsensor.c")
.shared_flag(true)
.static_flag(true)
.compile("pcsensor");
2022-01-07 22:37:15 +01:00
}
fn link() {
println!("cargo:rustc-link-lib=pcsensor");
println!("cargo:rustc-link-lib=usb");
}