Create build.rs
It is necessary to create the header files to be able to link the compiled staticlib from Rust. For this, cbindgen is used to create these automatically.
This is an example configuration to do so:
use cbindgen; fn main() { create_bindings(); } /// Create the bindings for the FFI interface between the DCC and Rust fn create_bindings() { let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); cbindgen::Builder::new() .with_crate(crate_dir) .with_include("dcc_oxidizer.h") .generate() .expect("Unable to generate bindings") .write_to_file("./include/example.h"); }
I've chosen to write the headers to ./include/example.h. However, choose any directory you'd like.
Most importantly is the line to include dcc_oxidizer.h. This will add a line to include the dcc-oxidizer header file. However, without any configuration this file will not exist.
That's why it is important to set the environment variable to create the dcc_oxidizer.h file as well. This is only necessary to do once, or when updating the crate.
This can be done automated with the .cargo/config.toml as shown in the examples. Or set it manually in your shell or CMake.
export DCC_OXIDIZER_HEADER_FILE=path/to/your/directory/dcc_oxidizer.h
After you've set this, run the build and the file will be generated.