rust-lang/rust-bindgen
66.9
Adequate · 30 September 2026
30.3k
lines of production code
Rust
primary language
2
measurements over time
What this system is
This system is a Rust library and command-line tool that generates safe Rust bindings from C and C++ headers. It parses C/C++ source code using libclang to produce idiomatic Rust code, supporting advanced features like custom callbacks for item naming, macro handling, and complex bitfield accessors. The tool includes a robust test suite with fuzzing and integration tests to ensure correctness across various C/C++ constructs and libclang versions.
How it got here
2012–2017 — Workspace restructuring and testing infrastructure
8 changes.
The project transitioned from legacy single-crate sources to a structured Cargo workspace, centralizing dependency management and establishing a minimum Rust version. Significant effort was invested in building comprehensive integration and C++ test suites to validate complex code generation features like bitfields and callbacks. Additionally, automated CI pipelines and fuzzing infrastructure were introduced to ensure consistent behavior and robustness across diverse environments.
2022 — workspace restructuring and codegen improvements
13 changes.
The project reorganized the bindgen codebase into a modular workspace, introducing new APIs for build configuration, callbacks, and Rust target compatibility. Significant internal refactors included a modular intermediate representation, a monotone analysis framework, and a postprocessing stage to normalize generated code structure. The test suite was expanded with dynamic generation, property-based testing, and comprehensive coverage for new features and edge cases.
2023–2025 — CLI integration and test expansion
4 changes.
The project refactored its options system into a macro-driven architecture to unify the programmatic Builder API with the CLI interface. Concurrently, test coverage was expanded to validate the new static function wrapping feature and verify the correct behavior of item discovery and derive callbacks.
Features
Add csmith-based fuzzing driver for bindgen
Added a new fuzzing infrastructure in the \csmith-fuzzing\ directory to test \bindgen\ against randomly generated C/C++ headers. The \driver.py\ script orchestrates the process by generating test cases with \csmith\, validating them via \predicate.py\ (which runs \bindgen\, compiles the output with \rustc\, and executes layout tests), and automatically reducing any discovered bugs using \creduce\. This allows users to run \./driver.py\ to continuously stress-test \bindgen\ and report issues when panics, compilation failures, or layout mismatches occur.
csmith-fuzzing · high confidence
Added release announcement template and contributor listing script
The releases directory now includes a Markdown template for generating release announcements and a shell script to automatically list contributors ('friends') since a specified commit or tag. This streamlines the process of creating consistent release posts by providing a structured format and automating the attribution of contributors.
releases · high confidence
Repository initialization with legacy Rust source and configuration files
The repository is initialized with a set of configuration and documentation files, including \.gitattributes\ to enforce LF line endings for test files, \.gitignore\ rules for build artifacts and generated bindings, and a BSD 3-Clause \LICENSE\. Documentation is provided via \README.md\ (citing an MSRV of 1.71.0) and a detailed \CONTRIBUTING.md\. The project uses \dist-workspace.toml\ for release configuration and \triagebot.toml\ for GitHub automation. Additionally, legacy Rust source files \bindgen.rs\ and \clang.rs\ (written in pre-1.0 Rust syntax) are present, alongside a deleted \bindgen.rc\ manifest.
(repo-wide) · high confidence
Architecture
Refactor intermediate representation into a modular workspace
The internal intermediate representation (IR) has been reorganized into a modular structure with dedicated source files for each component (such as annotations, comments, compound types, context, and derivation logic). This refactoring centralizes the logic for parsing C/C++ types and managing the IR state, improving code maintainability and separation of concerns without changing the external API or generated output.
bindgen/ir · high confidence
Behavioural changes
Add CI scripts for test execution and system header validation
New CI scripts (test.sh, test.bat, no-includes.sh, assert-no-diff.bat) are introduced to automate testing and enforce code quality. The test scripts run the full test suite across debug and release modes, including specific integration tests for the Rust for Linux kernel (targeting v7.1-rc1). Additionally, a new check prevents test cases from including system headers (with an exception for stdarg.h) to ensure consistent binding generation across different environments.
ci · high confidence
CLI error output moved to stderr and panic messages are now visible
The bindgen CLI now directs all error messages, including CLI argument parsing failures and generation errors, to standard error (stderr) instead of standard output, ensuring that successful binding output remains clean for piping. Additionally, the tool no longer suppresses panic messages; if a panic occurs during generation, the raw panic information is printed to stderr, and verbose mode provides specific guidance on known unsupported C++ features and how to file an issue.
bindgen-cli · high confidence
Introduces postprocessing passes to merge extern blocks and sort generated items
The codegen pipeline now includes a postprocessing stage that re-parses generated Rust code using \syn\ to apply two specific transformations: merging duplicate \extern\ blocks that share the same ABI and attributes, and sorting all generated items (such as structs, enums, functions, and traits) into a consistent semantic order. This ensures that the final output is more readable and structurally normalized, with related foreign function declarations grouped together and top-level items arranged by type.
bindgen/codegen/postprocessing · high confidence
New monotone framework for IR type analysis
The \bindgen/ir/analysis\ module has been restructured to use a new monotone framework for performing fix-point analyses on the Intermediate Representation. This change introduces dedicated analysis modules for determining which types cannot derive specific traits (like \Copy\ or \Debug\), which types have destructors, which contain floats, which have vtables, and the sizedness of types. It also includes an analysis to detect unused template type parameters, ensuring generated Rust bindings do not contain unnecessary generic parameters.
bindgen/ir/analysis · high confidence
Refactor bitfield accessors to use a generic \_\_BindgenBitfieldUnit type
The codegen module now generates a new \\_\_BindgenBitfieldUnit\<Storage\>\ struct to handle bitfield access, replacing the previous implementation. This change introduces safe \get\/\set\ methods and unsafe \raw\_get\/\raw\_set\ methods that operate on byte pointers, improving safety and allowing for compile-time optimization via const-generic accessors. The \helpers\ module provides a \bitfield\_unit\ function to generate the type, and \impl\_debug\ and \impl\_partialeq\ modules are updated to use the new accessor names for these fields.
bindgen/codegen · high confidence
Refactored bindgen options into a macro-driven, CLI-integrated system
The \bindgen/options\ module has been restructured to use a central \options!\ macro that automatically generates the \BindgenOptions\ struct, \Builder\ setter methods, and CLI argument conversion logic. This change introduces a new \AsArgs\ trait and helper modules (\as\_args.rs\, \helpers.rs\) to standardize how options are serialized to command-line flags, while \cli.rs\ now defines the \BindgenCommand\ struct using \clap\ for robust argument parsing. This refactoring consolidates option handling, ensuring that new options added via the macro automatically support both the programmatic Builder API and the CLI interface.
bindgen/options · high confidence
Test suite restructured into a workspace with dynamic test generation
The bindgen-tests component has been reorganized into a workspace structure. A new build script (build.rs) was introduced to dynamically generate Rust test functions by scanning the 'tests/headers' directory for C/C++ header files, allowing the test suite to automatically include new headers without manual registration. The library source (src/lib.rs) was cleared, indicating a shift in how tests are compiled and discovered within this new workspace layout.
bindgen-tests · high confidence
bindgen library restructured into a workspace with new build and callback APIs
The bindgen crate has been reorganized as part of a larger workspace split, introducing a new \build.rs\ script that detects the host target and configures rerun triggers for libclang environment variables. The library now exposes a comprehensive \callbacks.rs\ module providing the \ParseCallbacks\ trait, allowing users to customize macro parsing, item naming, field attributes, and visibility. Additionally, a new \features.rs\ module introduces \RustTarget\ and \RustEdition\ types to control the generated code's compatibility, defaulting to the current Rust version when used in build scripts. A \deps.rs\ module handles dependency file generation with proper escaping, and an experimental \diagnostics.rs\ module provides pretty-printed error reporting using \annotate-snippets\.
bindgen · high confidence
Test coverage
Add C++ integration test suite for generated bindings; Added property-based tests for bindgen using quickchecking; Added test expectations for static function wrapping feature; Added test harness for parse callbacks; Added test infrastructure for libclang version-specific expectations; Added tests for derive deduplication in add\_derives callback; Added tests for item discovery callback functionality; Expanded test coverage for bindgen header parsing and code generation; Integration test suite for bindgen callbacks and code generation features; Integration tests for C++ bindings and bitfield handling; Updated test expectations for bindgen code generation; Updated test suite for libclang 22 and added macro fallback tests.
Dependencies
Rust-bindgen workspace restructure and dependency updates
The project has been reorganized into a Cargo workspace containing the core library (bindgen), the CLI tool (bindgen-cli), and test crates (bindgen-tests, bindgen-integration). This change introduces a Cargo.lock file to manage dependency resolution and centralizes version management in the workspace root. Key dependency updates include upgrading clang-sys to 1.9.1, clap to 4.4.18, syn to a range supporting 2.x and 3.x, and prettyplease to \>=0.2.7. The workspace also sets a minimum Rust version of 1.71.0 and configures shared linting rules.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 66 → 67 (+1.3)
- Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.
Lenses
- Code Health 80 → 80 (-0.5)
- Architecture 100 → 98 (-2.2)
- Maturity 60 → 60 (+0.2)
- Readiness 68 → 67 (-1.4)
- Security 62 → 74 (+12.8)
- Performance 80 (new)
Resolved (6)
- Documentation: no installation or build instructions (README.md)
- Documentation: no usage examples (README.md)
- Hotspot: bindgen/ir/comp.rs (bindgen/ir/comp.rs)
- Hotspot: bindgen/ir/function.rs (bindgen/ir/function.rs)
- Hotspot: bindgen/ir/item.rs (bindgen/ir/item.rs)
- Hotspot: bindgen/ir/ty.rs (bindgen/ir/ty.rs)
New (3)
- Hotspot: bindgen/options/cli.rs (bindgen/options/cli.rs)
- Low cohesion: ItemId (LCOM4 5) (bindgen/ir/context.rs)
- Off the main sequence: bindgen
Changes since last survey
- 6 commits — 4 feature/other, 2 fixes
By area
- bindgen-tests/tests — 5 commits
- bindgen/lib.rs — 1 commit
Notable commits
- fix: Fix bitfields spanning nine storage bytes
- fix: codegen: Fix union member wrappers with rust-target < 1.83
- change: Add support for marking functions as safe
- change: Map *-windows-gnullvm targets to *-windows-gnu for clang
- change: codegen: Resolve function typedefs in block pointers
- change: codegen: Use _Complex keyword in static function wrappers
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
rust-lang/rust-bindgen was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 30 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 2829d9a5f48ae377a88ef7438c1e47d0779a4165 — the exact code this score is about.
- Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-505904ce13c1.