I have a proprietary library with a long story and 30KLoC header. I'd like to generate bindings for Rust to it. And I've used bindgen
crate almost successfully. Except bindgen
can't transform macro constants into normal constants. Because those constants are defined in a fuzzy way, like
#define CONSTANT ((const_type)SOME_OTHER_CONSTANT)
So, is there some way to translate such half-constants into normal Rust ones:
const Type name = value;
UPDATE
Apparently, crate bindgen
uses clang
as its backend. And clang
is able to deal with macro definitions and other such stuff, if right flag is provided to parser. So, can anyone advice good tutorial on dealing with macro definitions using libclang
API?
Running the headers through
gcc -E
(i.e. the preprocessor) will remove the#define
s. It may remove more than you want though.If you want to selectively preprocess, there used to be a utility called
scpp
that did that. I can't immediately find a reference to it other than to some tar files to download, but you may have more luck.