From 7a5ab67831bd9da15acea086c354046dbd5f977d Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Sun, 31 May 2026 19:38:35 +0200 Subject: [PATCH] refactor(codegen): reconcile Rust crate names with the native/cbor convention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aligns the Rust crate names with the C generator and the symbol naming: the native (zero-serialization, same-process) crate is the bare `` and the CBOR (inter-process) crate carries the `_cbor` suffix — mirroring `.h` / `_cbor.h` and the `` / `_cbor` exports. Previously the native crate was `_native` and the CBOR crate was the bare ``, which is backwards from the symbol convention. Only the Cargo package name changes; the linked dylib stays `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 --- examples/timer/rust_bindings/Cargo.toml | 2 +- examples/timer/rust_bindings/README.md | 3 ++- examples/timer/rust_client/Cargo.lock | 4 ++-- examples/timer/rust_client/Cargo.toml | 2 +- examples/timer/rust_client/src/main.rs | 2 +- examples/timer/rust_client/src/tokio_main.rs | 2 +- examples/timer/rust_native_bindings/Cargo.toml | 2 +- examples/timer/rust_native_bindings/examples/demo.rs | 2 +- ffi/codegen/rust_cbor.nim | 6 +++++- ffi/codegen/rust_native.nim | 9 ++++++--- 10 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/timer/rust_bindings/Cargo.toml b/examples/timer/rust_bindings/Cargo.toml index b34251a..c1decf1 100644 --- a/examples/timer/rust_bindings/Cargo.toml +++ b/examples/timer/rust_bindings/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "my_timer" +name = "my_timer_cbor" version = "0.1.0" edition = "2021" diff --git a/examples/timer/rust_bindings/README.md b/examples/timer/rust_bindings/README.md index 1a337fe..929c319 100644 --- a/examples/timer/rust_bindings/README.md +++ b/examples/timer/rust_bindings/README.md @@ -31,7 +31,8 @@ The `rust_client` example consumes this crate: ```toml [dependencies] -my_timer = { path = "../rust_bindings" } +# CBOR (inter-process) crate carries the `_cbor` suffix; the native crate is the bare `my_timer`. +my_timer_cbor = { path = "../rust_bindings" } ``` ## Do Not Edit diff --git a/examples/timer/rust_client/Cargo.lock b/examples/timer/rust_client/Cargo.lock index 6f1d949..96b0ebe 100644 --- a/examples/timer/rust_client/Cargo.lock +++ b/examples/timer/rust_client/Cargo.lock @@ -97,7 +97,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] -name = "my_timer" +name = "my_timer_cbor" version = "0.1.0" dependencies = [ "ciborium", @@ -134,7 +134,7 @@ dependencies = [ name = "rust_client" version = "0.1.0" dependencies = [ - "my_timer", + "my_timer_cbor", "serde_json", "tokio", ] diff --git a/examples/timer/rust_client/Cargo.toml b/examples/timer/rust_client/Cargo.toml index ac2c0b3..894edf6 100644 --- a/examples/timer/rust_client/Cargo.toml +++ b/examples/timer/rust_client/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -my_timer = { path = "../rust_bindings" } +my_timer_cbor = { path = "../rust_bindings" } serde_json = "1" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } diff --git a/examples/timer/rust_client/src/main.rs b/examples/timer/rust_client/src/main.rs index e437f6d..eba8d0b 100644 --- a/examples/timer/rust_client/src/main.rs +++ b/examples/timer/rust_client/src/main.rs @@ -6,7 +6,7 @@ // To regenerate the `rust_bindings` crate: // nimble genbindings_rust use std::time::Duration; -use my_timer::{ +use my_timer_cbor::{ EchoRequest, JobSpec, MyTimerCtx, RetryPolicy, ScheduleConfig, TimerConfig, }; diff --git a/examples/timer/rust_client/src/tokio_main.rs b/examples/timer/rust_client/src/tokio_main.rs index e1bdb17..314a328 100644 --- a/examples/timer/rust_client/src/tokio_main.rs +++ b/examples/timer/rust_client/src/tokio_main.rs @@ -1,5 +1,5 @@ use std::time::Duration; -use my_timer::{ +use my_timer_cbor::{ EchoRequest, JobSpec, MyTimerCtx, RetryPolicy, ScheduleConfig, TimerConfig, }; diff --git a/examples/timer/rust_native_bindings/Cargo.toml b/examples/timer/rust_native_bindings/Cargo.toml index 1ee2b70..a6aa80b 100644 --- a/examples/timer/rust_native_bindings/Cargo.toml +++ b/examples/timer/rust_native_bindings/Cargo.toml @@ -1,4 +1,4 @@ [package] -name = "my_timer_native" +name = "my_timer" version = "0.1.0" edition = "2021" diff --git a/examples/timer/rust_native_bindings/examples/demo.rs b/examples/timer/rust_native_bindings/examples/demo.rs index 390da20..179f6ca 100644 --- a/examples/timer/rust_native_bindings/examples/demo.rs +++ b/examples/timer/rust_native_bindings/examples/demo.rs @@ -1,4 +1,4 @@ -use my_timer_native::*; +use my_timer::*; fn main() { let node = MyTimerNode::new(TimerConfig { name: "rust-native-gen".into() }).unwrap(); println!("version: {}", node.version().unwrap()); diff --git a/ffi/codegen/rust_cbor.nim b/ffi/codegen/rust_cbor.nim index b5de184..7b22b95 100644 --- a/ffi/codegen/rust_cbor.nim +++ b/ffi/codegen/rust_cbor.nim @@ -74,9 +74,13 @@ proc generateCargoToml*(libName: string): string = # pulling its async-std/futures shims. # `tokio` is needed only for `tokio::time::timeout` around the async # `recv_async`. Feature-gating tokio (item 11) is a follow-up commit. + # CBOR (inter-process) crate carries the `_cbor` suffix, matching the + # `_cbor` symbol naming and the C `_cbor.h` header; the native + # crate is the bare ``. The linked dylib is still `lib.dylib` + # (see generateBuildRs / the `#[link]` name) — only the crate name changes. return """[package] -name = "$1" +name = "$1_cbor" version = "0.1.0" edition = "2021" diff --git a/ffi/codegen/rust_native.nim b/ffi/codegen/rust_native.nim index 1761217..a29af88 100644 --- a/ffi/codegen/rust_native.nim +++ b/ffi/codegen/rust_native.nim @@ -1,7 +1,8 @@ ## Native (zero-serialization) Rust binding generator. ## -## Emits a `_native` crate that wraps the *native* C ABI (the `` -## entry points + flat C-POD structs) — no CBOR. Each `{.ffi.}` type is a +## Emits a bare `` crate that wraps the *native* C ABI (the `` +## entry points + flat C-POD structs) — no CBOR; the CBOR crate is `_cbor`. +## Each `{.ffi.}` type is a ## `#[repr(C)]` mirror (`ffi`) plus an idiomatic Rust struct with `to_c`/`from_c` ## (`types`), and `Node` marshals typed args in / reads typed struct ## returns out (`api`). Counterpart of the CBOR generator in `rust_cbor.nim`, and @@ -452,8 +453,10 @@ proc generateRustNativeCrate*( events: seq[FFIEventMeta] = @[], ) = createDir(outputDir / "src") + # Native (same-process) crate is the bare ``, matching the `` + # symbol naming and the C `.h` header; the CBOR crate is `_cbor`. writeFile(outputDir / "Cargo.toml", - "[package]\nname = \"" & libName & "_native\"\nversion = \"0.1.0\"\nedition = \"2021\"\n") + "[package]\nname = \"" & libName & "\"\nversion = \"0.1.0\"\nedition = \"2021\"\n") writeFile(outputDir / "src" / "lib.rs", "mod ffi;\nmod types;\nmod api;\npub use types::*;\npub use api::*;\n") writeFile(outputDir / "src" / "ffi.rs", emitFfiRs(procs, types, libName, events))