-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
61 lines (51 loc) · 1.88 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::env;
use std::fs::File;
use std::io::BufWriter;
use std::io::Write;
use std::path::Path;
use pciid_parser::Database;
fn string_to_static_str(s: String) -> &'static str {
Box::leak(s.into_boxed_str())
}
#[derive(Debug, Eq, PartialEq)]
struct PciDeviceInfo {
pub vendor_id: u16,
pub device_id: u16,
pub vendor_name: &'static str,
pub device_name: &'static str,
}
fn main() {
let db = Database::read().unwrap();
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("pci_device_map.rs");
let mut filewriter = BufWriter::new(File::create(&path).unwrap());
let mut devices = phf_codegen::Map::new();
for (vendor_id, vendor) in db.vendors.iter() {
eprintln!("{} {:?}", vendor_id, vendor);
let vendor_name = string_to_static_str(vendor.name.clone());
for (device_id, device) in vendor.devices.iter() {
/*eprintln!(
"vendor={:#?} device={:#?} vendor_id={:?} ||",
vendor, device, vendor_id
);*/
let vendor_id = u16::from_str_radix(vendor_id, 16).unwrap();
let device_id = u16::from_str_radix(device_id, 16).unwrap();
eprintln!("{} {}", vendor_id, device_id);
let key = (vendor_id as u32) << (u32::BITS / 2) | device_id as u32;
let pci_dev_info = PciDeviceInfo {
vendor_id,
device_id,
vendor_name,
device_name: string_to_static_str(device.name.clone()),
};
devices.entry(key, string_to_static_str(format!("{:?}", pci_dev_info)));
eprintln!("-- {} {:?}", device_id, device);
//assert!(device.subdevices.is_empty(), "Don't deal with this atm.");
}
}
writeln!(
&mut filewriter,
"pub static PCI_DEVICES: phf::Map<u32, PciDeviceInfo> = \n{};\n",
devices.build()
)
.unwrap();
}