mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.37k stars 305 forks source link

Macro generated functions are ignored in header generation #976

Open dmulder opened 3 months ago

dmulder commented 3 months ago

I have several functions which are relevant to multiple objects, so I created some macros to reduce code duplication. When I generate the header file, the generated functions are excluded from the header file. I can see the symbols are present in the generated shared object library.

I read somewhere that I needed to set [parse.expand] crates in my cbindgen.toml in order to pre-process the sources to generate the header correctly. I tried this, and it made no difference at all.

I'm using cargo cbuild to wrap cbindgen, but the same happens manually calling cbindgen.

You can see the sources here: https://gitlab.com/davidmmulder/libhimmelblau/-/tree/dmulder/serialize_deserialize?ref_type=heads

jschwe commented 3 months ago

https://gitlab.com/davidmmulder/libhimmelblau/-/tree/dmulder/serialize_deserialize?ref_type=heads

That link gives a 404 for me. Is the project visible to the public?

dmulder commented 3 months ago

https://gitlab.com/davidmmulder/libhimmelblau/-/tree/dmulder/serialize_deserialize?ref_type=heads

That link gives a 404 for me. Is the project visible to the public?

Sorry, I merged the branch and deleted it afterward. Sources are here: https://gitlab.com/samba-team/libhimmelblau/

Notice that I'm having to manually include the function prototypes for macro generated functions in my cbindgen.toml, because I couldn't find a way to pre-process and expand the macros.