Add Zig bindings generator - #7
Conversation
Add a source-first generator that extracts exported Zig declarations and emits Dart FFI bindings. Include the CLI entrypoint, Zig metadata dumper, generator tests, public exports, and documentation for the workflow.
a369ee5 to
f8c7b3f
Compare
|
Hi, thanks for your contribution and sorry for a delay. I'll look into it. |
|
@kingwill101 resolve merge conflicts. |
|
@ykmnkmi done. could you approve the workflow so we can verify the build works in ci? |
|
@kingwill101 just checking in. Do you need any help? Did you try compiling the Zig source with the package itself? PS: Accidentally deleted the root README.md, it's restored now. |
- Fix stale CI working-directory path: example/zig_dart_api/zig → example/dart_api/zig - Resolve README.md merge conflict: keep generator workflow in step 6
|
@ykmnkmi resolved. There is a known issue with the generator, it currently does not support exporting c types ➜ dart_api git:(add-zig-bindings-generator) ✗ dart run native_toolchain_zig:zig bindings \
--zig-dir zig \
--root-source-file src/lib.zig \
--output lib/my_package.dart
Building package executable...
Built native_toolchain_zig:zig.
Bad state: Unsupported Zig named type: c.Dart_Port_DLwhich i think is fine for now, zig types work well allow the ci to run once more and we can wrap up. |
I have a working fix but I'm not confident in it's current state. I'd prefer to land that as a separate pr |
|
All passed. I will take a final look and merge it. Did you try to compile the Zig code using the package itself? I tried it before, but I got some errors. |
Demonstrates generating Dart FFI bindings from Zig source code using the native_toolchain_zig bindings generator. - zig/src/counter.zig: example Zig library with exported functions and an extern struct - hook/build.dart: build hook using ZigBuilder - lib/ffi.g.dart: generated FFI bindings (7 functions, 1 struct) - lib/bindings.dart: Dart-friendly wrapper around raw FFI - bin/main.dart: demo of raw and wrapped bindings - README with usage instructions for generating, running, and watch mode
b84ff60 to
8443535
Compare
|
Tested again and everything runs locally. Also added a full bindings example. generator doesn't work well on zig 0.16.0 though, will include a fix in the follow up work i have queued should be able to merge now |
|
Merged. I'll bump SDK to |
Hi, I actually built the same library and it wasn't until I tried publishing that I realized. I've opted to port the useful bits from my package here since you've already published.
This pr introduces a source-first generator that extracts exported Zig declarations and emits Dart FFI bindings.