#[cfg(not(feature = "generate"))]
fn main() {
println!(
"ERROR: to generate bindings, build and run with the 'generate' feature: \n \
cargo run --features=generate"
);
}
#[cfg(feature = "generate")]
use bindgen;
#[cfg(feature = "generate")]
fn main() -> std::result::Result<(), std::io::Error> {
use std::env;
use std::path::PathBuf;
println!("cargo:rerun-if-changed=wrapper.h");
let playdate_sdk =
env::var("PLAYDATE_SDK_PATH").expect("Set PLAYDATE_SDK_PATH to the correct path");
let c_api = PathBuf::from(playdate_sdk).join("C_API");
let builder = bindgen::Builder::default();
#[cfg(not(all(target_arch = "arm", target_os = "none")))]
let builder = builder.clang_arg("-DTARGET_SIMULATOR=1");
#[cfg(not(all(target_arch = "arm", target_os = "none")))]
let builder = builder.clang_arg("-DPLAYDATE_SIMULATOR=1");
#[cfg(all(target_arch = "arm", target_os = "none"))]
let builder = builder.clang_arg("-DTARGET_PLAYDATE=1");
let bindings = builder
.use_core()
.ctypes_prefix("super::ctypes")
.clang_arg(format!("-I{}", c_api.to_str().unwrap()))
.clang_arg("-DTARGET_EXTENSION=1")
.clang_arg("-v")
.allowlist_function("eventHandler")
.allowlist_type("PlaydateAPI")
.allowlist_type("PDSystemEvent")
.allowlist_type("LCDPattern")
.allowlist_var("SEEK_SET")
.allowlist_var("SEEK_CUR")
.allowlist_var("SEEK_END")
.allowlist_var("LCD_COLUMNS")
.allowlist_var("LCD_ROWS")
.allowlist_var("LCD_ROWSIZE")
.newtype_enum("LCDSolidColor")
.newtype_enum("PDSystemEvent")
.newtype_enum("LCDBitmapDrawMode")
.newtype_enum("LCDBitmapFlip")
.newtype_enum("LCDPolygonFillRule")
.newtype_enum("LCDLineCapStyle")
.newtype_enum("PDStringEncoding")
.newtype_enum("LCDPolygonFillRule")
.newtype_enum("PDLanguage")
.bitfield_enum("PDPeripherals")
.newtype_enum("SpriteCollisionResponseType")
.newtype_enum("SoundFormat")
.newtype_enum("LFOType")
.newtype_enum("SoundWaveform")
.newtype_enum("TwoPoleFilterType")
.bitfield_enum("PDButtons")
.bitfield_enum("FileOptions")
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let mut bindgen_out = Vec::new();
bindings.write(Box::new(&mut bindgen_out)).expect("Couldn't write bindings!");
const HEADER: &str = "// To regenerate this bindings module: `cargo run --features=generate`\n\
\n\
#![allow(deref_nullptr)]\n\n";
let mut file_out = Vec::new();
file_out.extend(HEADER.as_bytes());
file_out.extend(bindgen_out.into_iter());
let out_path = PathBuf::from("src").join("bindings.rs");
std::fs::write(&out_path, file_out)?;
println!(
"Successfully generated bindings in {}!",
out_path.to_str().unwrap()
);
Ok(())
}