Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment thread
MonterraByte marked this conversation as resolved.

[build-dependencies]
bindgen = "0.72"
Expand Down
82 changes: 36 additions & 46 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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 <stdbool.h>
#include <cdio/cdio.h>
#include <cdio/cd_types.h>
#include <cdio/logging.h>
#include <cdio/mmc_cmds.h>
#include <cdio/utf8.h>\n";
fn main() -> Result<(), Box<dyn Error>> {
system_deps::Config::new().probe()?;
make_bindings()?;

#[cfg(feature = "iso9660")]
const ISO9660_HEADER: &str = "#include <cdio/iso9660.h>\n";

#[cfg(feature = "udf")]
const UDF_HEADER: &str = "#include <cdio/udf.h>\n";

#[cfg(feature = "cdda")]
const CDDA_HEADER: &str = "#include <cdio/paranoia/cdda.h>\n";

#[cfg(feature = "paranoia")]
const PARANOIA_HEADER: &str = "#include <cdio/paranoia/paranoia.h>\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<dyn Error>> {
// 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 <stdbool.h>
#include <cdio/cdio.h>
#include <cdio/cd_types.h>
#include <cdio/logging.h>
#include <cdio/mmc_cmds.h>
#include <cdio/utf8.h>
";
static HEADERS: &[&str] = &[
CDIO_HEADERS,
#[cfg(feature = "iso9660")]
"#include <cdio/iso9660.h>",
#[cfg(feature = "udf")]
"#include <cdio/udf.h>",
#[cfg(feature = "cdda")]
"#include <cdio/paranoia/cdda.h>",
#[cfg(feature = "paranoia")]
"#include <cdio/paranoia/paranoia.h>",
];
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(())
}
Loading