mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 08:19:55 +00:00
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>
58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
// Generated by nim-ffi native Rust codegen. Do not edit by hand.
|
|
#![allow(non_snake_case, dead_code)]
|
|
use std::os::raw::{c_char, c_int, c_void};
|
|
|
|
pub type FFICallback =
|
|
unsafe extern "C" fn(ret: c_int, msg: *const c_char, len: usize, user_data: *mut c_void);
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct TimerConfig {
|
|
pub name: *const c_char,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct EchoRequest {
|
|
pub message: *const c_char,
|
|
pub delay_ms: i64,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct EchoResponse {
|
|
pub echoed: *const c_char,
|
|
pub timer_name: *const c_char,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct ComplexResponse {
|
|
pub summary: *const c_char,
|
|
pub item_count: i64,
|
|
pub has_note: c_int,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct EchoEvent {
|
|
pub message: *const c_char,
|
|
pub echo_count: i64,
|
|
}
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct ScheduleResult {
|
|
pub job_id: *const c_char,
|
|
pub will_run_count: i64,
|
|
pub first_run_at_ms: i64,
|
|
pub effective_backoff_ms: i64,
|
|
}
|
|
|
|
#[link(name = "my_timer")]
|
|
extern "C" {
|
|
pub fn my_timer_create(config: TimerConfig, callback: FFICallback, user_data: *mut c_void) -> *mut c_void;
|
|
pub fn my_timer_echo(ctx: *mut c_void, callback: FFICallback, user_data: *mut c_void, req: EchoRequest) -> c_int;
|
|
pub fn my_timer_version(ctx: *mut c_void, callback: FFICallback, user_data: *mut c_void) -> c_int;
|
|
pub fn my_timer_destroy(ctx: *mut c_void) -> c_int;
|
|
} |