Skip to content

CLI support for custom derives #2170

Closed
@adamlesinski

Description

@adamlesinski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions