Ivan FB 23152d4fe7
feat(codegen): native (non-CBOR) Rust generator + rust.nim -> rust_cbor.nim split
Splits the Rust codegen the way C++ is split: rename `rust.nim` -> `rust_cbor.nim`
(CBOR) and add `rust_native.nim` (native). Dispatch on `targetLang=rust` now
honours `-d:ffiMode` (native/cbor); the crates share file names so each mode
writes its own dir (rust_bindings vs rust_native_bindings).

`rust_native.nim` emits a `<lib>_native` crate — the Rust analogue of
`cpp_native`: `#[repr(C)]` POD mirrors + `extern "C"` native entry points
(ffi.rs); idiomatic structs with `to_c`/`from_c`, a holder owning the CStrings
for the call (types.rs); and a `<Lib>Node` whose methods marshal typed args in /
read typed struct returns out, blocking via std mpsc (api.rs).

First cut: scalar/string/bool/float/nested-struct fields (create/version/echo);
seq/Option params are SKIPPED, native events next. Verified end-to-end — the
generated crate builds and the demo round-trips a typed EchoResponse. Tasks:
genbindings_rust (CBOR), genbindings_rust_native.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 18:51:06 +02:00

1.3 KiB

Rust bindings — native (generated)

Generated native (zero-serialization) Rust crate for the timer library — the Rust counterpart of c_bindings / go_bindings / cpp_native_bindings, and the native sibling of the CBOR crate in ../rust_bindings.

File Description
src/ffi.rs #[repr(C)] POD mirrors + extern "C" native entry points.
src/types.rs Idiomatic structs + to_c/from_c (a holder owns the CStrings for the call).
src/api.rs <Lib>Node — methods marshal typed args in / read typed struct returns out; blocking via std::sync::mpsc. No CBOR.
examples/demo.rs A small consumer.
let node = MyTimerNode::new(TimerConfig { name: "my-app".into() })?;
println!("{}", node.version()?);
let r = node.echo(EchoRequest { message: "hello".into(), delay_ms: 5 })?;   // -> EchoResponse

Regenerate with nimble genbindings_rust_native.

Status

First cut — scalar / string / bool / float / nested-struct fields (create, version, echo). Methods taking sequences or optionals (complex, schedule) are // SKIPPED; those plus native typed events are the next increments. Linking is left to the consumer (-L <dir> -l my_timer + an rpath, as in examples/demo.rs); a build.rs that compiles the dylib (like the CBOR crate) can be added later.