Skip to content

Commit

Permalink
Run cbindgen in build script
Browse files Browse the repository at this point in the history
  • Loading branch information
hulthe committed May 14, 2024
1 parent 3cb2d77 commit 2923671
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions crates/maybenot-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
3 changes: 2 additions & 1 deletion crates/maybenot-ffi/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 9 additions & 0 deletions crates/maybenot-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -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"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum MaybenotEventType {
typedef uint32_t MaybenotEventType;

/**
* An FFI friendly result type.
* An FFI friendly result error code type.
*/
enum MaybenotResult {
/**
Expand All @@ -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;

Expand Down

0 comments on commit 2923671

Please sign in to comment.