use std::{ env::{self, set_current_dir}, fs, path::PathBuf, }; fn main() { fs::create_dir_all("build").expect("could not create build path"); let int_path = PathBuf::from("build") .canonicalize() .expect("cannot canonicalize path"); set_current_dir(int_path.clone()).expect("failed to change current directory"); let wiringop_path = PathBuf::from( env::var("WIRINGOP_PATH").expect("could not retrieve wiringOP path from env"), ) .canonicalize() .expect("cannot canonicalize path"); let mut cc = cc::Build::new(); cc.files( glob::glob(&format!("{}/wiringPi/*.c", wiringop_path.to_str().unwrap())) .unwrap() .filter_map(|e| e.ok()), ) .include(format!("{}/wiringPi/", wiringop_path.to_str().unwrap())); let target = std::env::var("TARGET").unwrap(); if target.starts_with("aarch64") { cc.flag("-O2"); } cc.static_flag(true).compile("wiringop"); let builder = bindgen::Builder::default() .header("../ffi/wrapper.h") .detect_include_paths(true); let bindings = builder .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .generate() .expect("unable to generate bindings"); let out_path = PathBuf::from(env::var("OUT_DIR").expect("failed to get out dir for bindings")) .join("bindings.rs"); bindings .write_to_file(out_path) .expect("couldn't write bindings"); }