1 use std::fs;
2 use std::path::{Path, PathBuf};
3 
get_api_version(libusb_source: &Path)4 fn get_api_version(libusb_source: &Path) {
5     use std::io::BufRead;
6     if let Ok(f) = fs::File::open(libusb_source) {
7         let f = std::io::BufReader::new(f);
8         for line in f.lines().flatten() {
9             if line.starts_with("#define LIBUSB_API_VERSION") {
10                 if let Some(api_version) = line.rsplit(' ').next().and_then(|s| {
11                     if let Some(s) = s.strip_prefix("0x") {
12                         u32::from_str_radix(s, 16).ok()
13                     } else {
14                         None
15                     }
16                 }) {
17                     if api_version >= 0x01000108 {
18                         println!("cargo:rustc-cfg=libusb_hotplug_get_user_data");
19                     }
20                 }
21                 break;
22             }
23         }
24     }
25 }
26 
main()27 fn main() {
28     if let Ok(include_path) = std::env::var("DEP_USB_1.0_INCLUDE") {
29         let path = PathBuf::from(include_path);
30         get_api_version(path.join("libusb.h").as_path());
31     }
32 }
33