Skip to content

rust-bindgen generate from C macro #3065

@cppcoffee

Description

@cppcoffee

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:

aya-rs/aya#1128

aya-rs/aya#1129

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions