cheadergen
cheadergen generates accurate C headers for Rust libraries that expose a C-compatible API.
cheadergen provides:
- Multi-crate support. One C header per crate, with
cross-crate
#includes wired up automatically. - Compiler-accurate type analysis. Type information comes from
rustdoc-json, so the generated output mirrors what the Rust compiler actually sees. - Macro-aware. Items defined by declarative or procedural macros are picked up automatically.
cheadergen is an alternative to
cbindgen. Check out our
comparison page
for more details.
cheadergen (C Header Generator) is built and maintained by Luca Palmieri.
What it does
You write Rust:
pub extern "C"
cheadergen produces a header your C code can consume:
typedef struct Point;
double ;
New to C/Rust interoperability?
If you've never written extern "C" in Rust before, the
FFI chapter of the Rust Nomicon
is a good primer on the topic.