mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-21 00:40:16 +00:00
The C codegen already emitted `my_timer.h` / `my_timer_cbor.h`, but the example had no runnable driver. Add `example.c` exercising the native ABI end-to-end (ctor with a struct param, string-returning version, struct-param echo, and a deeply nested ComplexRequest), plus a Makefile that builds the Nim dylib from the repo root — where the vendored Nimble deps resolve — and links the driver. Native is the same-process path; the companion CBOR headers are for crossing a process/machine boundary (see the forthcoming ipc example). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
timer example
This example is a self-contained Nimble project demonstrating how to import nim-ffi and use the .ffiCtor. / .ffi. abstraction.
Usage
-
Change into the example directory:
cd examples/timer -
Install the local
ffidependency:nimble install -y ../.. -
Build the example library:
nimble build -
Generate bindings:
nimble genbindings_rust nimble genbindings_cpp
Rust example clients
The Rust client lives in examples/timer/rust_client.
-
Run the sync example:
cd examples/timer/rust_client cargo run --bin rust_client -
Run the Tokio example:
cd examples/timer/rust_client cargo run --bin tokio_client
C++ example
The generated C++ example lives in examples/timer/cpp_bindings.
Build and run it with:
cd examples/timer/cpp_bindings
cmake -S . -B build
cmake --build build
./build/example