From 35999e4e453f3b4a30012e3c7c561112d6751202 Mon Sep 17 00:00:00 2001 From: Shiva Kiran Koninty Date: Thu, 6 Aug 2026 11:25:41 +0530 Subject: [PATCH 1/3] Use the `links` key in Cargo.toml The `links` key allows for Cargo to ensure that there is at most one crate that links to a given native library, preventing duplicate symbols in any given build configuration, which might arise from two different dependencies attempting to link to the same native library. Refer: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) 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" From b09f1452e09b2f6222fa95f8e5f7e0db29912b09 Mon Sep 17 00:00:00 2001 From: Shiva Kiran Koninty Date: Fri, 7 Aug 2026 11:30:44 +0530 Subject: [PATCH 2/3] Return std::error::Error rather than panic/exit --- build.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/build.rs b/build.rs index fd311ec..839eae8 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ use std::env; +use std::error::Error; use std::path::PathBuf; // libcdio uses a homegrown boolean type for versions < 2.1.1. @@ -36,11 +37,8 @@ const HEADERS: &[&str] = &[ PARANOIA_HEADER, ]; -fn main() { - if let Err(s) = system_deps::Config::new().probe() { - println!("cargo:warning={s}"); - std::process::exit(1); - } +fn main() -> Result<(), Box> { + system_deps::Config::new().probe()?; let headers = HEADERS.join(""); let bindings = bindgen::Builder::default() @@ -49,12 +47,12 @@ fn main() { .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")) - .expect("Couldn't write bindings!"); + bindings.write_to_file(out_path.join("bindings.rs"))?; + + Ok(()) } From 3be0049f720a97d91b77ab0275b46ee9574d2a1b Mon Sep 17 00:00:00 2001 From: Shiva Kiran Koninty Date: Fri, 7 Aug 2026 11:33:39 +0530 Subject: [PATCH 3/3] Group binding related code and data in a function --- build.rs | 66 +++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/build.rs b/build.rs index 839eae8..4622b6b 100644 --- a/build.rs +++ b/build.rs @@ -2,45 +2,38 @@ 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"; - -#[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() -> Result<(), Box> { system_deps::Config::new().probe()?; + make_bindings()?; - let headers = HEADERS.join(""); + Ok(()) +} + +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") @@ -51,7 +44,6 @@ fn main() -> Result<(), Box> { 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"))?; Ok(())