Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI support for custom derives #2170

Closed
adamlesinski opened this issue Feb 24, 2022 · 1 comment · Fixed by #2328
Closed

CLI support for custom derives #2170

adamlesinski opened this issue Feb 24, 2022 · 1 comment · Fixed by #2328

Comments

@adamlesinski
Copy link

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.

hcldan added a commit to hcldan/rust-bindgen that referenced this issue Nov 1, 2022
hcldan added a commit to hcldan/rust-bindgen that referenced this issue Nov 1, 2022
hcldan added a commit to hcldan/rust-bindgen that referenced this issue Nov 1, 2022
@spease
Copy link

spease commented Nov 8, 2022

This would be useful to derive strum::*, Serialize, and Deserialize for enum types as well. It would also be useful if there were a way to specify the type rather than have it apply to every type (the current PR currently doesn't seem to have a way to be selective).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants