diff --git a/Cargo.toml b/Cargo.toml index 7b8c389..3df1d26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,9 @@ thiserror = "1" [dev-dependencies] env_logger = "0.8" +[build-dependencies] +cbindgen = "0.18.0" + [target.'cfg(windows)'.dependencies] tolk = { version = "0.3", optional = true } windows = "0.2" diff --git a/build.rs b/build.rs index 8b1edc2..c92ffc7 100644 --- a/build.rs +++ b/build.rs @@ -8,4 +8,18 @@ fn main() { println!("cargo:rustc-link-lib=framework=AppKit"); } } + + #[cfg(feature = "ffi")] + generate_c_bindings(); +} + +#[cfg(feature = "ffi")] +fn generate_c_bindings() { + use std::path::PathBuf; + let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let mut header_path: PathBuf = std::env::var("OUT_DIR").unwrap().into(); + header_path.push("tts.h"); + cbindgen::generate(crate_dir) + .unwrap() + .write_to_file(header_path); }