FFI: Automatically generate bindings when building with ffi feature.

This commit is contained in:
mcb2003 2021-03-06 09:56:57 +00:00
parent 060a057c0f
commit 0644f03f34
2 changed files with 17 additions and 0 deletions

View File

@ -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"

View File

@ -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);
}