You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generate Iox2NativeMethods constants and struct sizes from the cbindgen C header #21
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)
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.
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.
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 Csharp iox2 12 ffi testing #20 (csharp-iox2-12-ffi-testing): adds the size-mirror tripwire and the IOX2_SERVICE_ID_LENGTH fix.
Activity