-
Notifications
You must be signed in to change notification settings - Fork 769
Add support for custom per-field attributes #3307
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
base: main
Are you sure you want to change the base?
Conversation
12b3e2a to
6554574
Compare
This adds the ability to apply custom Rust attributes to individual
struct, union, and newtype fields in generated bindings through three
mechanisms:
1. HTML annotations in C/C++ comments:
```c
/// <div rustbindgen attribute="serde(rename = x_coord)"></div>
int x;
```
2. ParseCallbacks::field_attributes() method for programmatic control:
```rust
fn field_attributes(&self, info: &FieldAttributeInfo) -> Vec<String>
```
3. CLI flag and Builder API for pattern-based attributes:
```bash
--field-attr "Point::x=serde(rename = x_coord)"
```
```rust
.field_attribute("Point", "x", "serde(rename = x_coord)")
```
All three mechanisms can be used together, with attributes merged in
order: annotations, callbacks, then CLI/Builder patterns.
This is useful for adding serde attributes, documentation, or other
derive-related metadata to specific fields.
6554574 to
5b9816f
Compare
Summary: This includes 3 recent PRs: - rust-lang/rust-bindgen#3305 - Fix packed structs with flexible array members (merged) - rust-lang/rust-bindgen#3306 - Support nested flexible array members - rust-lang/rust-bindgen#3307 - Add support for custom per-field attributes The last one is specifically intended to allow per-field attributes from proc-macros to be applied. These have been cherry-picked onto the v0.72.1 release branch, as the main branch is still listed as v0.72.0 and I didn't want a backwards version step. The upstream branch is https://github.com/jsgf/rust-bindgen/tree/PR-merged Reviewed By: dtolnay Differential Revision: D85273915 fbshipit-source-id: 211916b9611cbfa409296a6854b4a94bba2c5195
Summary: This includes 3 recent PRs: - rust-lang/rust-bindgen#3305 - Fix packed structs with flexible array members (merged) - rust-lang/rust-bindgen#3306 - Support nested flexible array members - rust-lang/rust-bindgen#3307 - Add support for custom per-field attributes The last one is specifically intended to allow per-field attributes from proc-macros to be applied. These have been cherry-picked onto the v0.72.1 release branch, as the main branch is still listed as v0.72.0 and I didn't want a backwards version step. The upstream branch is https://github.com/jsgf/rust-bindgen/tree/PR-merged Reviewed By: dtolnay Differential Revision: D85273915 fbshipit-source-id: 211916b9611cbfa409296a6854b4a94bba2c5195
fa7c579 to
f2ef849
Compare
A single function gathers custom field attributes from cli, API and annotations, and then use it for both newtype and regular struct/union fields.
f2ef849 to
943d01a
Compare
|
@emilio Take another look? |
I think that's the rust-for-linux test, cc @ojeda I don't think the issue is caused by this PR in any case. |
|
Yeah, that is due to a change in |
This upgrade is also needed now since Rust 1.91.0 got released, which blocks the CI [1] due to the change in the target spec format in upstream Rust [2]. It was fixed in Linux v6.17-rc5 [3]. Link: rust-lang#3307 [1] Link: rust-lang/rust#144443 [2] Link: Rust-for-Linux/linux@8851e27 [3] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This upgrade is also needed now since Rust 1.91.0 got released, which blocks the CI [1] due to the change in the target spec format in upstream Rust [2]. Support for the new format was added in Linux v6.17-rc5 [3]. Link: rust-lang#3307 [1] Link: rust-lang/rust#144443 [2] Link: Rust-for-Linux/linux@8851e27 [3] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
|
Done: #3309. |
This adds the ability to apply custom Rust attributes to individual
struct, union, and newtype fields in generated bindings through three
mechanisms:
--field-attr "Point::x=serde(rename = x_coord)"All three mechanisms can be used together, with attributes merged in
order: annotations, callbacks, then CLI/Builder patterns.
This is useful for adding serde attributes, documentation, or other
derive-related metadata to specific fields.