Usage
Using safer_ffi
is pretty simple, provided one knows how C compilation
works.
TL,DR
Cargo.toml
[lib]
crate-type = ["staticlib", "lib"]
[dependencies]
safer-ffi = "..."
[features]
headers = ["safer-ffi/headers"]
src/lib.rs
#![allow(unused)] fn main() { use ::safer_ffi::prelude::*; #[ffi_export] fn add(x: i32, y: i32) -> i32 { x.wrapping_add(y) } #[cfg(feature = "headers")] pub fn generate_headers() -> ::std::io::Result<()> { ::safer_ffi::headers::builder() .to_file("filename.h")? .generate() } }
src/bin/generate-headers.rs
fn main() -> ::std::io::Result<()> { ::crate_name::generate_headers() }
-
And run:
cargo run --bin generate-headers --features headers
to generate the headers.