-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust-bindgen generate from C macro #3065
Comments
What do you mean by "macro definition"? A Rust macro? A The Clang macro fallback linked above is (so far, and as far as I always understood it) intended to resolve macros that evaluate to a constant, not to generate code for arbitrary macros. This would be closer to a Cc @jbaublitz |
Generating corresponding Rust code from C language macro definitions would be sufficient, whether as Rust functions or Rust macros. This approach would be better for C projects that involve numerous macro definitions. 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)) |
That would be very useful indeed (even if only for a small subset of cases) -- please see #2369. |
Hi @ojeda, is this something that would be considered another desired feature for Rust for Linux? |
I think in general a tool that would automate some of these would be quite useful for some projects, e.g. in Linux we already had to rewrite ioctl macros (like However, it is non-trivial (it gets closer to a transpiler), and especially with macros, since there may be different potential useful solutions for each macro depending on the use case (how they are called). For instance, for a So it is possible extra input/information/context from the user may be needed to decide. Perhaps this is the sort of problem where such a tool is best used to get potential solutions and then the developer picks and adapts the right one. |
So you're suggesting actually converting from C macros to Rust macros? |
I want to generate corresponding Rust macro definitions from C language macro definitions, input C header as follow:
Run bindgen command:
Output rust as follow:
The expectation is to have the
frame_type
macro definition.Here is the related issue:
aya-rs/aya#1128
aya-rs/aya#1129
The text was updated successfully, but these errors were encountered: