From 29236715a9d7453da489f5240c4e7f77388e3ae3 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Tue, 14 May 2024 09:50:32 +0200 Subject: [PATCH] Run cbindgen in build script --- crates/maybenot-ffi/Cargo.toml | 3 +++ crates/maybenot-ffi/README.md | 3 ++- crates/maybenot-ffi/build.rs | 9 +++++++++ crates/maybenot-ffi/{maybenot-ffi.h => maybenot.h} | 8 ++++---- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 crates/maybenot-ffi/build.rs rename crates/maybenot-ffi/{maybenot-ffi.h => maybenot.h} (96%) diff --git a/crates/maybenot-ffi/Cargo.toml b/crates/maybenot-ffi/Cargo.toml index 92e90c0..546c026 100644 --- a/crates/maybenot-ffi/Cargo.toml +++ b/crates/maybenot-ffi/Cargo.toml @@ -15,3 +15,6 @@ crate-type = ["lib", "staticlib", "cdylib"] [dependencies] maybenot = { version = "1.1.1", path = "../maybenot" } thiserror = "1.0" + +[build-dependencies] +cbindgen = { version = "0.26.0", default-features = false } diff --git a/crates/maybenot-ffi/README.md b/crates/maybenot-ffi/README.md index ae9553e..3436cff 100644 --- a/crates/maybenot-ffi/README.md +++ b/crates/maybenot-ffi/README.md @@ -1,7 +1,8 @@ # Maybenot FFI This crate contains C FFI bindings for Maybenot, which let's you use Maybenot as a static library -for languages other than Rust. +for languages other than Rust. Headers are found at `maybenot-ffi/maybenot.h` and are +auto-generated when compiling. ## Building You need to have [rust](https://rustup.rs/) installed. diff --git a/crates/maybenot-ffi/build.rs b/crates/maybenot-ffi/build.rs new file mode 100644 index 0000000..bf46550 --- /dev/null +++ b/crates/maybenot-ffi/build.rs @@ -0,0 +1,9 @@ +use std::env; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + cbindgen::generate(&crate_dir) + .expect("Unable to generate bindings") + .write_to_file(format!("{crate_dir}/maybenot.h")); +} diff --git a/crates/maybenot-ffi/maybenot-ffi.h b/crates/maybenot-ffi/maybenot.h similarity index 96% rename from crates/maybenot-ffi/maybenot-ffi.h rename to crates/maybenot-ffi/maybenot.h index c62e1db..396e926 100644 --- a/crates/maybenot-ffi/maybenot-ffi.h +++ b/crates/maybenot-ffi/maybenot.h @@ -28,7 +28,7 @@ enum MaybenotEventType { typedef uint32_t MaybenotEventType; /** - * An FFI friendly result type. + * An FFI friendly result error code type. */ enum MaybenotResult { /** @@ -45,9 +45,9 @@ typedef uint32_t MaybenotResult; /** * A running Maybenot instance. * - * - Create it: [ffi::maybenot_start]. - * - Feed it actions: [ffi::maybenot_on_event]. - * - Stop it: [ffi::maybenot_stop]. + * - Create it: [maybenot_start]. + * - Feed it actions: [maybenot_on_event]. + * - Stop it: [maybenot_stop]. */ typedef struct MaybenotFramework MaybenotFramework;