Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Rust
  3. cbindgen

cbindgen

MPL-2.0Rust0.29.4

Generates C and C++11 headers from Rust libraries that expose a public C API.

GitHubGitHub
3.0k stars390 forks0 contributors

What is cbindgen?

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.

Target Audience

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.

Value Proposition

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.

Overview

A project for generating C bindings from Rust code

Use Cases

Best For

  • Automatically generating C headers for Rust libraries to ensure ABI compatibility and reduce manual errors.
  • Creating C++11 headers with ergonomic features like operator overloads and constructors from Rust APIs.
  • Integrating Rust code into existing C or C++ projects, such as browsers or performance-critical systems.
  • Building language bindings or FFI layers where accurate type representation is crucial.
  • Using in build scripts (e.g., build.rs) to generate headers as part of the compilation process.
  • Projects requiring production-ready bindings, as proven by use in WebRender, Stylo, and milksnake.

Not Ideal For

  • Projects that don't require C/C++ interoperability at all, as cbindgen is specifically for generating foreign language bindings.
  • Teams needing modern C++ features beyond C++11, since cbindgen only supports up to C++11 standards.
  • Situations requiring highly customized or non-standard header layouts, as automation may not cover all edge cases or formatting preferences.

Pros & Cons

Pros

Dual Language Support

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.'

Rust ABI Accuracy

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.

Production Proven

Used in real-world projects like WebRender and Stylo, demonstrating reliability in complex, performance-critical systems, with examples listed in the README.

Flexible Integration

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.

Cons

Adhoc Feature Coverage

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.'

Dependency Management Trade-offs

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.

Limited to C++11

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.

Frequently Asked Questions

Quick Stats

Stars2,960
Forks390
Contributors0
Open Issues229
Last commit2 months ago
CreatedSince 2017

Tags

#header-generation#c-bindings#ffi#interoperability#rust#code-generation#build-tool

Built With

R
Rust

Included in

Rust56.6k
Auto-fetched 1 day ago

Related Projects

RustPythonRustPython

A Python Interpreter written in Rust

Stars22,412
Forks1,502
Last commit1 day ago
PyO3PyO3

Rust bindings for the Python interpreter

Stars16,258
Forks1,039
Last commit2 days ago
wasm-bindgenwasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript

Stars9,198
Forks1,257
Last commit1 day ago
NeonNeon

Rust bindings for writing safe and fast native Node.js modules.

Stars8,423
Forks287
Last commit21 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub