Repository: aya-rs/aya (language: rust)

Issue:
aya-tool generate from C macro
Can `aya-tool` generate corresponding Rust code for the functions and macro definitions in `.h` header files?

like this:

```
#define frame_type(f)		(frame_ftsz(f) & FRAME_TYPE)
#define frame_typep(f)		(frame_ftsz(f) & FRAME_TYPEP)
#define frame_islua(f)		(frame_type(f) == FRAME_LUA)

#define frame_ftsz(f)		((ptrdiff_t)(f)->ftsz)
#define frame_pc(f)		((const BCIns *)frame_ftsz(f))

#define frame_prevl(f)		((f) - (1+LJ_FR2+bc_a(frame_pc(f)[-1])))
#define bc_a(i)		((BCReg)(((i)>>8)&0xff))
```

The expectation is to generate the corresponding Rust code.

Manually translating each macro definition could lead to errors and would be very time-consuming.



Discussion / hints:

Fix patch:
diff --git a/aya-tool/src/bindgen.rs b/aya-tool/src/bindgen.rs
index 87f731020..d138ddf36 100644
--- a/aya-tool/src/bindgen.rs
+++ b/aya-tool/src/bindgen.rs
@@ -1,23 +1,23 @@
 use bindgen::{Builder, EnumVariation};
 
-pub fn user_builder() -> Builder {
+fn common_builder() -> Builder {
     bindgen::builder()
         .use_core()
         .layout_tests(false)
         .generate_comments(false)
         .prepend_enum_name(false)
-        .default_enum_style(EnumVariation::Rust {
-            non_exhaustive: false,
-        })
+        .clang_macro_fallback()
+}
+
+pub fn user_builder() -> Builder {
+    common_builder().default_enum_style(EnumVariation::Rust {
+        non_exhaustive: false,
+    })
 }
 
 pub fn bpf_builder() -> Builder {
-    bindgen::builder()
-        .use_core()
+    common_builder()
         .ctypes_prefix("::aya_ebpf::cty")
-        .layout_tests(false)
-        .generate_comments(false)
         .clang_arg("-Wno-unknown-attributes")
         .default_enum_style(EnumVariation::ModuleConsts)
-        .prepend_enum_name(false)
 }


Test patch: