Skip to content

Add Rust LCM code generator and generated bindings#20

Open
leshy wants to merge 4 commits intomainfrom
rust-codegen
Open

Add Rust LCM code generator and generated bindings#20
leshy wants to merge 4 commits intomainfrom
rust-codegen

Conversation

@leshy
Copy link
Copy Markdown

@leshy leshy commented Mar 20, 2026

Closes #1617

Adds tools/rust/lcm_rust_gen.py — a standalone Python generator (no external deps) that parses all .lcm type definitions and produces a complete Rust crate at generated/rust_lcm_msgs/.

Generated crate:

  • 173 LCM types across 14 packages (188 source files)
  • Derives Clone, Debug, Default, PartialEq for all types
  • Implements encode/decode (big-endian, LCM wire format)
  • Implements get_hash() matching LCM's signed i64 fingerprint arithmetic
  • Depends only on byteorder = "1"
  • Passes cargo check with 0 errors, 0 warnings

Edge cases handled:

  • r#type raw identifier escaping (9 files use reserved keywords)
  • Manual Default impl for [f64; 36] (>32 elements, no auto-derive)
  • Length field suppression for variable-length arrays
  • OnceLock for lazy fingerprint caching
  • String/name field collision resolution

generate.sh updated with Rust generation step.

Closes #1617

Adds tools/rust/lcm_rust_gen.py — a standalone Python generator (no
external deps) that parses all .lcm type definitions and produces a
complete Rust crate at generated/rust_lcm_msgs/.

Generated crate:
- 173 LCM types across 14 packages (188 source files)
- Derives Clone, Debug, Default, PartialEq for all types
- Implements encode/decode (big-endian, LCM wire format)
- Implements get_hash() matching LCM's signed i64 fingerprint arithmetic
- Depends only on byteorder = "1"
- Passes cargo check with 0 errors, 0 warnings

Edge cases handled:
- r#type raw identifier escaping (9 files use reserved keywords)
- Manual Default impl for [f64; 36] (>32 elements, no auto-derive)
- Length field suppression for variable-length arrays
- OnceLock for lazy fingerprint caching
- String/name field collision resolution

generate.sh updated with Rust generation step.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
leshy and others added 3 commits March 21, 2026 01:15
Pure Rust LCM UDP multicast transport — no system LCM library required.
Mirrors the TypeScript @dimos/lcm package. Includes publisher/subscriber
examples using lcm-msgs generated types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add integration tests validating the Rust LCM implementation from PR #1622:

- `generated/rust_lcm_msgs/tests/roundtrip.rs`: 7 tests covering encode/decode
  roundtrips for Vector3, Twist, PoseStamped; fingerprint consistency; corruption
  detection; and exact known binary layout verification.

- `tools/rust/lcm/tests/loopback.rs`: 4 UDP multicast pubsub tests covering
  empty-channel try_recv, typed message publish+receive (Vector3, Twist), and
  raw byte round-trip — all using bounded retries (no sleeps, no interactive I/O).

All 11 tests pass. No external services or manual steps required.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add PartialEq to generated struct derives (was missing despite PR description)
- Add Debug and Clone derives to transport types (LcmTransport, etc.)
- Fix encode_one to return io::Result<()> with ? propagation
- Fix string decode to use proper from_utf8 with error handling
- Regenerate 173 message types with corrected derives
- Add 7 round-trip encode/decode tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant