diff --git a/Cargo.toml b/Cargo.toml index 45a81c6..83be58a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ exclude = ["/.github"] keywords = ["ffi", "cd", "cdio", "iso9660", "udf"] categories = ["external-ffi-bindings", "hardware-support", "multimedia", "multimedia::audio"] license = "GPL-3.0+" +links = "cdio" [build-dependencies] bindgen = "0.72" diff --git a/build.rs b/build.rs index fd311ec..4622b6b 100644 --- a/build.rs +++ b/build.rs @@ -1,60 +1,50 @@ use std::env; +use std::error::Error; use std::path::PathBuf; -// libcdio uses a homegrown boolean type for versions < 2.1.1. -// The homegrown boolean type is not recognized by bindgen. -// This would result in different code gen for versions < 2.1.1 and versions >= 2.1.1. -// To prevent this, we include stdbool.h ourselves, which suppresses the homegrown boolean type. -const CDIO_HEADER: &str = "#include -#include -#include -#include -#include -#include \n"; +fn main() -> Result<(), Box> { + system_deps::Config::new().probe()?; + make_bindings()?; -#[cfg(feature = "iso9660")] -const ISO9660_HEADER: &str = "#include \n"; - -#[cfg(feature = "udf")] -const UDF_HEADER: &str = "#include \n"; - -#[cfg(feature = "cdda")] -const CDDA_HEADER: &str = "#include \n"; - -#[cfg(feature = "paranoia")] -const PARANOIA_HEADER: &str = "#include \n"; - -const HEADERS: &[&str] = &[ - CDIO_HEADER, - #[cfg(feature = "iso9660")] - ISO9660_HEADER, - #[cfg(feature = "udf")] - UDF_HEADER, - #[cfg(feature = "cdda")] - CDDA_HEADER, - #[cfg(feature = "paranoia")] - PARANOIA_HEADER, -]; - -fn main() { - if let Err(s) = system_deps::Config::new().probe() { - println!("cargo:warning={s}"); - std::process::exit(1); - } + Ok(()) +} - let headers = HEADERS.join(""); +fn make_bindings() -> Result<(), Box> { + // libcdio uses a homegrown boolean type for versions < 2.1.1. + // The homegrown boolean type is not recognized by bindgen. + // This would result in different code gen for versions < 2.1.1 and versions >= 2.1.1. + // To prevent this, we include stdbool.h ourselves, which suppresses the homegrown boolean type. + static CDIO_HEADERS: &str = r" + #include + #include + #include + #include + #include + #include +"; + static HEADERS: &[&str] = &[ + CDIO_HEADERS, + #[cfg(feature = "iso9660")] + "#include ", + #[cfg(feature = "udf")] + "#include ", + #[cfg(feature = "cdda")] + "#include ", + #[cfg(feature = "paranoia")] + "#include ", + ]; + let headers = HEADERS.join("\n"); let bindings = bindgen::Builder::default() .header_contents("wrapper.h", &headers) .allowlist_file(r".*[/\\]cdio[/\\][^/\\]*\.h") .allowlist_file(r".*[/\\]cdio[/\\]paranoia[/\\][^/\\]*\.h") .wrap_unsafe_ops(true) .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) - .generate() - .expect("Unable to generate bindings"); + .generate()?; - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let out_path = + PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR should have been set by Cargo")); + bindings.write_to_file(out_path.join("bindings.rs"))?; - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); + Ok(()) }