-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FFI Gen Feature #591
Comments
we actually have discussed potentially doing this using zig's powerful comptime to inspect all types and build bindings, it would remove the need to parse or produce any headers as source itself would act as comptime header import { murmur32 } from './hash.zig';
console.log(murmur32(new Uint8Array(1024), 1024)); hash.zig: pub fn murmur32(ptr: [*]const u8, length: u32) callconv(.C) u32 {
const slice = ptr[0..length];
return std.hash.Murmur2_32.hash(slice);
} |
Does it mean that we will be able "just load" header files during runtime? but it will require to have zig compiler in a system (if I understand comptime correctly) |
We want to experiment with being able to import source files themselves, so yeah
There are multiple ways to fix this, one of them is for bun to download its own zig compiler This is still only an idea, so anyone is welcome to try and experiment with other ways of doing ffi bindings generation |
Recently, when looking for some reference about bindgen. I saw that you are developing a bindgen C++ to Zig. Could you explain how this bindgen works or intends to work? I've been experimenting with some bindgen:
I also tried to try SWIG for Go (there is still no C Backend for target) but it doesn't seem to be ideal. My report when exploring cbindgen-fork (Rust to Zig): |
Just published my bindings generator (tested on wgpu) |
What is the problem this feature will solve?
Writing ffi interfaces manually
What is the feature you are proposing to solve the problem?
FFI Definition Generator
What alternatives have you considered?
Hi at first I would like to say thank you for such a great work!
Is there any plans to make generator for FFI definitions? Also if you have any perspective on how this should be implemented, I would like to know
I considering try to make it, so far I have 2 ideas
Option 1
For now I'm thinking about modifying existing library (https://github.com/node-ffi-packager/node-ffi-generate/tree/ffi-napi) or make new one that works in a similar way (it uses libclang via FFI to parse header files and generate definitions).
I found other languages have something similar:
https://github.com/rust-lang/rust-bindgen (rust)
https://github.com/ffi/ffi-swig-generator (ruby, outdated)
https://github.com/dart-lang/ffigen (dart)
Option 2
use clang parsers that dump in xml or json format and convert it to js code
https://github.com/rpav/c2ffi
https://github.com/CastXML/CastXML
Either way, I think it will be nice if it can generate js and typescript definitions that can work correctly with editor auto-complete and can automatically split code into modules
(may be it even be possible to make macos apps with native UI using bun and ffi bindings)
The text was updated successfully, but these errors were encountered: