Generates C and C++11 headers from Rust libraries that expose a public C API.
cbindgen is a tool that automatically generates C/C++11 header files for Rust libraries with a public C API. It eliminates the manual and error-prone process of creating these headers by hand, ensuring the generated bindings accurately reflect Rust's type layout and ABI guarantees. The tool supports generating both C and C++ headers from the same Rust library, offering flexibility for different interoperability needs.
Rust developers who need to expose a C-compatible API from their Rust libraries for interoperability with C or C++ codebases, such as those embedding Rust components in larger systems or creating language bindings.
Developers choose cbindgen because it automates header generation with accuracy derived from collaboration with Rust developers, reducing errors and saving time. Its dual-language support allows seamless generation of both C and C++ headers from a single Rust library, providing flexibility without duplication of effort.
A project for generating C bindings from Rust code
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Generates both C and C++11 headers from the same Rust library, eliminating the need to maintain separate bindings, as highlighted in the README: 'you can just tell it to emit both.'
Developed in collaboration with Rust developers to ensure headers reflect accurate type layout and ABI guarantees, reducing manual errors and ensuring compatibility, as stated in the README.
Used in real-world projects like WebRender and Stylo, demonstrating reliability in complex, performance-critical systems, with examples listed in the README.
Can be used as a standalone command-line tool or integrated into build scripts (e.g., build.rs), offering versatility for different workflows, as described in the README.
Development is driven by maintainer use cases, so it may randomly fail to support certain Rust constructs or scenarios, as admitted in the README: 'cbindgen may randomly fail to support some particular situation.'
Using it as a standalone program requires external installation, while library usage can lead to frequent rebuilds when Rust compiler updates, adding overhead, as explained in the README.
Only generates headers compatible with C++11, which may not meet the needs of projects relying on newer C++ features like constexpr or auto, limiting interoperability with modern codebases.