diff options
| author | Teddy Wing | 2018-08-25 22:52:41 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-08-25 22:52:41 +0200 |
| commit | 4fd3fd4ded73aa4ba5320de50cd6b19fdf70a8a7 (patch) | |
| tree | 10b9e17c4c1f8a113fce7e71c845aadbefc3fc0e /build.rs | |
| parent | cdac4ed1ce81b76e6684f778fd07c8ebdacce556 (diff) | |
| download | dome-key-map-4fd3fd4ded73aa4ba5320de50cd6b19fdf70a8a7.tar.bz2 | |
Generate a partial C header for our FFI API
* Add the 'cbindgen' crate to help us auto-generate a C header for our
exported FFI enums/structs/functions
* Add a `build.rs` to generate the C header using cbindgen
* Add a rough config for 'cbindgen'
* Export everything from the `cocoa_bridge` crate to include the
`KeyActionResult` struct
* Commit the C header generated by 'cbindgen'
Looks promising. We do, however, have some things to correct. We can't
use `Option` in C, for instance, so we'll need to fix that in our
`KeyActionResult`. Similarly, we need to rework the `run_key_action()`
function to make it accessible as a C interface. Right now it returns an
`Option`, which isn't going to work, and I'm not sure if the slice input
translates. That (any maybe more) is why it doesn't get generated by
'cbindgen' into the header output file.
Diffstat (limited to 'build.rs')
| -rw-r--r-- | build.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..d2a0b5d --- /dev/null +++ b/build.rs @@ -0,0 +1,18 @@ +extern crate cbindgen; + +use cbindgen::Language; + +fn main() { + let crate_dir = env!("CARGO_MANIFEST_DIR"); + + let config = cbindgen::Config::from_file("cbindgen.toml") + .expect("Failed to read 'cbindgen.toml'"); + + cbindgen::Builder::new() + .with_crate(crate_dir) + // .with_language(Language::C) + .with_config(config) + .generate() + .expect("Unable to generate bindings") + .write_to_file("dome_key_map.h"); +} |
