Generate bindings automatically from C header files #779
Vincent-lau
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
Just wondering if anyone has thought about generating OCaml bindings automatically from C header files? Rust has its bindgen which does this. And it sounds possilbe, at least in theory, just by going through the C header file, parse it into some kind of IR, and then map the type information in the IR to the correct OCaml types represented in ctypes.
This has the benefit of automating the process of generating the most basic mapping to the C library. Obviously this does not remove all the work of writing a good OCaml binding since the generated OCaml code would still be quite low level and developers can/should then write higher level wrappers in OCaml to make the binding more usable, functional, safe, etc. It does help remove some of the repetitive work that is needed in translating some of the types from C to OCaml though (e.g. in my experience, translating large enums in C to OCaml algebraic data types was not a nice experience)
Proposal
Not yet, but I can write a bit more if the idea sounds plausible.
Tasks and updates
No response
Beta Was this translation helpful? Give feedback.
All reactions