Ivan FB 7a5ab67831
refactor(codegen): reconcile Rust crate names with the native/cbor convention
Aligns the Rust crate names with the C generator and the symbol naming: the
native (zero-serialization, same-process) crate is the bare `<lib>` and the
CBOR (inter-process) crate carries the `_cbor` suffix — mirroring `<lib>.h` /
`<lib>_cbor.h` and the `<name>` / `<name>_cbor` exports.

Previously the native crate was `<lib>_native` and the CBOR crate was the bare
`<lib>`, which is backwards from the symbol convention. Only the Cargo package
name changes; the linked dylib stays `lib<lib>.dylib` (the `#[link]` name and
build.rs are untouched).

Consumers updated: rust_client depends on `my_timer_cbor` and imports from it;
the native demo imports from the bare `my_timer`.

Validated: rust_client builds against the renamed CBOR crate; the native demo
round-trips version / echo / event / complex / schedule against the bare crate;
check_bindings_rust regen is deterministic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 19:38:35 +02:00
..
2026-05-25 15:51:56 +02:00
2026-05-21 16:33:38 +02:00

timer example

This example is a self-contained Nimble project demonstrating how to import nim-ffi and use the .ffiCtor. / .ffi. abstraction.

Two ABIs, one library

Every generated library exports two ABIs side by side, and you choose per call site:

ABI Header / symbols Use it for
Native (pure C) <lib>.h / <name> Same-process / local calls. Flat C structs by value, zero serialization.
CBOR <lib>_cbor.h / <name>_cbor Inter-process communication only — a different process or machine, where the request must be serialized to cross the boundary.

In a shared address space the CBOR round-trip is pure overhead, so default to the native ABI locally and reach for CBOR only when you actually cross a process/machine boundary (see ipc/). The per-language examples below: native C (c_bindings/), native Go (go_bindings/), native/CBOR C++ (cpp_bindings/), CBOR Rust (rust_client/), and CBOR-over-socket IPC (ipc/).

Usage

  1. Change into the example directory:

    cd examples/timer
    
  2. Install the local ffi dependency:

    nimble install -y ../..
    
  3. Build the example library:

    nimble build
    
  4. 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