Feature: add namespace attribute support #1123
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces support for per-function C++ namespace specification in generated headers using a new procedural macro attribute, improving flexibility for organizing C++ bindings. The main changes include the creation of a new
cbindgen-macrocrate, parsing and storing per-function namespace attributes, updating the C++ code generation logic to group functions into nested namespaces, and comprehensive documentation and tests to demonstrate the feature.Procedural macro and attribute support
cbindgen-macrocrate, which provides the#[cbindgen_macro::namespace("...")]procedural macro attribute for specifying C++ namespaces for individual functions. The macro is a no-op at compile time but is parsed bycbindgenfor header generation. [1] [2] [3]Parsing and IR enhancements
Functionstruct insrc/bindgen/ir/function.rs) to store the per-function namespace parsed from the attribute, and added helper logic to extract this attribute from source code. [1] [2] [3] [4] [5]C++ code generation changes
src/bindgen/language_backend/clike.rs) so that functions with per-item namespace attributes are grouped and emitted within nested namespace blocks in generated headers. Functions without the attribute use the global or no namespace as before. [1] [2] [3]Documentation
Testing