rust-lang / rust-lang/rust-bindgen
rust-bindgen generate from C macro
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
I want to generate corresponding Rust macro definitions from C language macro definitions, input C header as follow:
// test.h
enum { FRAME_TYPE, FRAME_TYPEP, FRAME_LUA };
#define frame_type(f) ((f) & FRAME_TYPE)
Run bindgen command:
$ bindgen ./test.h --default-enum-style moduleconsts --no-layout-tests --no-derive-default --use-core --ctypes-prefix ::aya_ebpf::cty --generate functions,types,vars,methods,constructors,destructors --no-doc-comments --no-prepend-enum-name --rust-target 1.82.0 --clang-macro-fallback -- -Wno-unknown-attributes
Output rust as follow:
/* automatically generated by rust-bindgen 0.71.1 */
pub mod _bindgen_ty_1 {
pub type Type = ::aya_ebpf::cty::c_uint;
pub const FRAME_TYPE: Type = 0;
pub const FRAME_TYPEP: Type = 1;
pub const FRAME_LUA: Type = 2;
}
The expectation is to have the frame_type macro definition.
Here is the related issue:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with the test.h header and the bindgen command shown in the issue, then inspect the macro-generation path and the related aya issue and pull request for context. Done means the generated Rust output includes a corresponding definition for frame_type while preserving the existing enum output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- compilers, devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100