Support for a GCC-based backend · Issue #1949 · rust-lang/rust-bindgen (original) (raw)

Currently, bindgen uses libclang to understand C/C++ code. #1740 considers moving to a lower-level interface for LLVM, with discussion of whether keeping support for several interfaces is feasible.

It would be great to have support for non-LLVM backends as well. In particular, a GCC-based one. Clang is very compatible with GCC nowadays (in both the Clang driver and the support for GNU C language extensions), but there are still differences here and there, which means one needs to be careful when applying bindgen in complex projects compiled with GCC.

It would require compiling a GCC plugin and using callbacks like PLUGIN_PRE_GENERICIZE ("Allows to see low level AST in C and C++ frontends.") and/or others like PLUGIN_FINISH_PARSE_FUNCTION, PLUGIN_FINISH_TYPE, PLUGIN_FINISH_DECL, etc.; or perhaps another way to use GCC's parser/tooling/etc.; or possibly using other approaches that fetch the information in another way (e.g. querying the compiler via generated C files or extracting it from debug information).

Of course, tackling this would be non-trivial, and it might not be worth the maintenance cost, but it might be an interesting project to expand bindgen's capabilities, as well as relaxing the dependency on LLVM.

Related: #2962.