Description
I'd like to continue the discussion started here: #2059 (comment)
Support for adding custom derives exists in the Builder API. I would like to support this in the CLI as well.
I believe that the CLI syntax would need to accept a regex, and not just apply the custom derive to all types. The derive support that is built-in (Copy, Debug, Default, etc) benefits from knowing when they can be applied to a type, based on its fields. Custom derives do not have access to this knowledge, as their requirements are unknown to bindgen.
Therefore the user of the CLI must supply a regex to determine which types get the custom derive.
I was thinking something like: --with-custom-derive zerocopy::AsBytes,zerocopy::FromBytes/Foo.*
where the /
separator can be anything else we decide on, it just can't be any valid symbol in a type (including :
) or a special shell character (;|
).
The regex is useful because it also captures anonymous nested structs, whose names are generated from the outer struct.
Example:
struct Foo {
struct {
int a;
} nested;
};
generates both Foo
and Foo__bindgen_ty_1
. The regex Foo.*
would capture both types.