$ cbindgen
v0.29.3A tool for generating C bindings to Rust code.
Latest Update Summary
Crate
Name: cbindgen New version: 0.29.2 Release date: 2025-05-20T12:13:22Z
Crate readme
Short description cbindgen creates C/C++11 headers for Rust libraries which expose a public C API.
Long description cbindgen generates error-free C/C++11 headers based on Rust libraries with a public C API, allowing both C and C++ headers to be emitted from the same library. It can be used as a simple standalone program or as a library in your build.rs. It provides a configuration file (cbindgen.toml) to set options for generating headers, with the ability to produce headers in both C and C++ formats.
Features • Generates C/C++11 headers from Rust libraries • Supports both C and C++ output from the same library • Simple to use as either a standalone program or as a library • Requires a configuration file (cbindgen.toml)
Code Examples Cargo installation
cargo install --force cbindgen
Homebrew installation
brew install cbindgen
Generate header file for C++
cbindgen --config cbindgen.toml --crate my_rust_library --output my_header.h
Generate header file for C
cbindgen --config cbindgen.toml --crate my_rust_library --output my_header.h --lang c
Links • https://github.com/mozilla/cbindgen • https://crates.io/crates/cbindgen • https://docs.rs/cbindgen
https://api.github.com/repos/mozilla/cbindgen/releases/219764621
Release info
Release version: 0.29.0
Release description
The 0.29.0 release introduces several significant enhancements and fixes. Notably, it adds support for the no-export annotation on statics and functions, allowing for greater flexibility in how symbols are exported. A new rename rule for generated associated constants has been added to streamline naming conventions. Additionally, the upgrade of the heck package to version 0.5 enhances code generation features. This release also includes support for an optional nullable attribute, enabling more nuanced handling of types. Furthermore, several bug fixes were addressed, including issues with the handling of constexpr literal structs and improved error generation for structures using the keyword as inside arrays. Deprecated spelling issues in documentation were corrected, ensuring clearer communication of deprecated features. Other minor fixes include improvements in generic handling and the renaming of the -Zparse-only flag for better usability.
Code Examples Support no-export annotation for statics and functions
#[no_export]
static MY_STATIC: i32 = 42;
Rename rule for generated associated constant
#[rename]
const MY_CONSTANT: i32 = 100;
Fix deprecated spelling in docs
// Fixed spelling of deprecated_with_note and deprecated_variant_with_note
Patch update: 0.29.2 → 0.29.3
$ DOWNLOADS TREND
$ VERSION HISTORY
$ LINKS
$ INSTALL
cargo add cbindgenOr add to Cargo.toml: cbindgen = "0.29.3"