918 B
918 B
cbindgen
This project can be used to generate C bindings for rust code. It is currently being developed to support creating bindings for WebRender.
Use
cbindgen path_to_crate > autogen.h
How it works
- All the structs, enums, type aliases, and functions that are representable in C are gathered
- A dependency graph is built using the extern "C" functions as roots
- This removes unneeded types from the bindings and sorts the structs that depend on each other
- Some code generation is done to specialize generics that are specified as type aliases
- The items are printed in dependency order in C syntax
Future work
- Add code for customizing bindings and removing code specific to WebRender
- Improve the CLI
- Better logging
- Sort the output types better
- Better support for types with fully specified names
- Add a validation step
- ...