Configure how cheadergen generates C/C++ headers from Rust.
cheadergen generates C/C++ header files from Rust libraries that expose a
pub extern "C" API. Output is controlled in two complementary ways:
cheadergen.toml— a project-wide TOML file that the CLI loads via--config. It sets the preamble, include guards, sort order, per-package opaque/skip rules, per-header overrides, and language-specific options. See the config reference for the full schema.- Per-item attributes —
#[cheadergen::config(...)]on items and#[cheadergen(...)]on fields and variants, placed in your Rust source to control how an individual definition appears in the generated header. See the [config] macro for the directive reference.
Per-item attributes
There are two attribute levels:
#[cheadergen::config(...)]— placed on items (structs, enums, unions, functions, statics, type aliases) to control their header representation.#[cheadergen(...)]— placed on fields and enum variants to control their individual representation within a parent item.
Example
#[cheadergen::config(export, rename = "CColor")]
#[repr(C)]
pub enum Color {
#[cheadergen(rename = "COLOR_RED")]
Red,
Green,
Blue,
}
#[cheadergen::config(export, field_names(x, y))]
#[repr(C)]
pub struct Point2D(pub f64, pub f64);
#[cheadergen::config(skip)]
#[unsafe(no_mangle)]
pub extern "C" fn internal_helper() {}