diff --git a/build.rs b/build.rs index e558a36..b0c42fb 100644 --- a/build.rs +++ b/build.rs @@ -49,6 +49,9 @@ pub struct CgProgIf { #[allow(clippy::redundant_field_names)] fn main() { let out_dir = env::var_os("OUT_DIR").unwrap(); + if update_ids().is_err() { + println!("cargo:warning=Failed fetching pci ids, do you have internet connection ?... Using cached version"); + } let src_path = Path::new("pciids/pci.ids"); let dest_path = Path::new(&out_dir).join("pci_ids.cg.rs"); let input = { @@ -291,3 +294,20 @@ impl quote::ToTokens for CgProgIf { }); } } + +fn update_ids() -> Result<(), std::io::Error> { + let status = std::process::Command::new("curl") + .arg("https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids") + .arg("--output") + .arg("pciids/pci.ids") + .spawn()? + .wait()?; + if status.success() { + Ok(()) + } else { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Error fetching pci data", + )) + } +}