Skip to content

Produce portable output (avoid generating system-dependent tests + configuration to improve type replacements) #424

Closed
@dimbleby

Description

@dimbleby

I prefer to generate my FFI code once and then distribute that, rather than generate it at build time. I see that you recommend the opposite, but even so: I expect that plenty of my potential users - especially on Windows - won't have the required dependencies installed. Better for me to figure out once how to get bindgen working, and be done with it.

At the moment, though, I have to do a little massaging of the code produced by bindgen to make it portable. My life would be that little bit easier if bindgen could be persuaded to produce portable output in the first place.

Ways in which I currently hand-modify output, and suggestions as to how this might be avoided:

  • The exact definition of various types defined in system headers varies. So I blacklist them, and then modify the autogenerated code to import a portable version of those types eg use libc::timeval

    • WIBNI I could tell bindgen where to get a type from
  • One consequence of this is that Debug can be wrongly derived. Eg it is derived on a structure containing an in_addr, which I obtain as libc::in_addr, which doesn't implement Debug.

    • (Actually libc::in_addr probably should be Debug - derive Debug on structures? libc#302).
    • But it isn't, so I have to manually un-derive Debug for structures that contain it
    • WIBNI bindgen didn't assume that things that it didn't know about (or which were blacklisted) were Debug
  • autogenerated testcases all assume that pointer size is per the machine on which they were generated. So I delete them.

    • WIBNI I could tell bindgen to not generate such testcases

None of this is a big deal for me - bindgen is great and the work I just described really isn't very much. Feel free to close this out if it's not of interest to you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions