eclipse-iceoryx / eclipse-iceoryx/iceoryx2-csharp
Generate Iox2NativeMethods constants and struct sizes from the cbindgen C header
- Dominant language
- C#
- Stars
- 31
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
## Background
`src/Iceoryx2/Native/Iox2NativeMethods.cs` manually mirrors C constants from the cbindgen-generated `iceoryx2.h` (`IOX2_OK`, `IOX2_NODE_NAME_LENGTH`, `IOX2_SERVICE_NAME_LENGTH`, `IOX2_SERVICE_ID_LENGTH`, …) and each interop struct hard-codes its `[StructLayout(Size = N)]`. Both must be updated by hand whenever the FFI bumps a value, and `IOX2_SERVICE_ID_LENGTH` going stale (32 → 64) is exactly what motivated the `Node.List()` marshal-offset bugfix in #12 / #20.
PR #20 added `tests/Ffi/NativeStructSizesTests` as a tripwire so future drift is at least loud, but the underlying duplication is unsolved.
## Goal
Generate `Iox2NativeMethods.Generated.cs` (constants + struct sizes) directly from the cbindgen-emitted C header so the binding cannot drift from the FFI.
## Options (ranked by realism)
1. **ClangSharp / CppSharp source generator.** Pipeline: `cargo build → cbindgen → iceoryx2.h → ClangSharp → Iox2NativeMethods.Generated.cs`. Proper fix. Adds an LLVM/libclang build dependency and a generator project.
2. **`cbindgen` sidecar + tiny consumer.** Have the FFI build also emit a `.json` of constants + struct sizes that a small C# T4 / source generator consumes. Lower-weight than ClangSharp but still introduces a new tool.
3. **Status quo + tripwires.** Today: manual `const` mirror plus `NativeStructSizesTests` to catch drift. Cheap, but only catches what we explicitly bookkeep — adding a new constant means the maintainer must remember to also add a tripwire row.
## Suggested next step
Pick option (1) or (2). I'd lean toward (1) — once the generator project exists, every drop-in cbindgen update gives a fresh `.Generated.cs` for free. The implementation effort is mostly the build glue (running the generator at restore time, deciding whether the generated file is committed or built).
## Related
- PR #20 (csharp-iox2-12-ffi-testing): adds the size-mirror tripwire and the `IOX2_SERVICE_ID_LENGTH` fix.
- Issue #12: the parent FFI-testing umbrella.
Contributor guide
Assessment
This issue has not been assessed yet.