use std::{ path::{Path, PathBuf}, vec, }; fn find_qbdi(version: Option<&str>, install_dir: Option<&str>) -> (String, String) { let version = version.unwrap_or("0.10.0"); let version_dir = format!("QBDI {}", version); let target = std::env::var("TARGET").unwrap(); let default_install_dir = PathBuf::from(match target.as_str() { "x86_64-pc-windows-msvc" => PathBuf::from("C:\\Program Files"), "i686-pc-windows-msvc" => PathBuf::from("C:\\Program Files (x86)"), _ => { panic!("find_qbdi unsupport this target") } }) .join(version_dir); let install_dir = install_dir.unwrap_or(default_install_dir.to_str().unwrap()); // check install_dir is exists if Path::new(&install_dir).exists() { return (version.to_string(), install_dir.to_string()); } else { panic!("Not found QBDI, install it from https://github.com/QBDI/QBDI/releases") } // let install_dir = ; } fn qbdi_lib() -> PathBuf { let (_qbdi_version, qbdi_install_dir) = find_qbdi(None, None); let qbdi_install_dir = PathBuf::from(&qbdi_install_dir); let qbdi_include_dir = qbdi_install_dir.join("include"); let qbdi_lib_dir = qbdi_install_dir.join("lib"); println!("cargo:rustc-link-lib={}", "QBDI_static"); println!( "cargo:rustc-link-search={}", &qbdi_lib_dir.to_str().unwrap() ); qbdi_include_dir } fn main() { println!("cargo:rerun-if-changed=build.rs"); let qbdi_include_dir = qbdi_lib(); let clang_args = vec![format!("-I{}", qbdi_include_dir.to_str().unwrap())]; let bindings = bindgen::Builder::default() // .header(qbdi_header.to_str().unwrap()) .clang_args(clang_args) .header("wrapper.h") .generate() // Unwrap the Result and panic on failure. .expect("Unable to generate bindings"); let current_dir = std::env::current_dir().expect("Failed to get current directory"); let out_path = current_dir.join("src").join("bindings.rs"); bindings .write_to_file(out_path) .expect("Couldn't write bindings!"); }