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

Add support for cfg_attr for struct fields #4351

Merged
merged 6 commits into from
Jan 12, 2025

Conversation

fl0rek
Copy link
Contributor

@fl0rek fl0rek commented Dec 11, 2024

closes #2703

Overview

  • During #[wasm_bindgen] attribute macro expansion on struct, instead of generating ast for Program, it puts a #[derive(BindgenedStruct)] on it and preserves all the wasm_bindgen atributes as-is.
  • When #[derive(BindgenedStruct)] is expanded, cfg_attr are already evaluated, so macro can just processes the leftover attributes and generate the glue code required, as it's done now. Attributes are then automatically removed by the compiler, since macro is defined as #[proc_macro_derive(BindgenedStruct, attributes(wasm_bindgen))].

@fl0rek fl0rek force-pushed the feat/cfg_attr-structs-rel branch 3 times, most recently from d84f3d8 to e1034d4 Compare December 12, 2024 08:29
Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is a great improvement!

crates/macro-support/src/lib.rs Outdated Show resolved Hide resolved
crates/macro-support/src/parser.rs Outdated Show resolved Hide resolved
tests/wasm/classes.rs Show resolved Hide resolved
tests/wasm/classes.rs Show resolved Hide resolved
tests/wasm/classes.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
crates/macro-support/src/lib.rs Outdated Show resolved Hide resolved
@daxpedda daxpedda added the waiting for author Waiting for author to respond label Dec 15, 2024
@fl0rek fl0rek force-pushed the feat/cfg_attr-structs-rel branch 2 times, most recently from 4385c45 to a5ca4e9 Compare January 10, 2025 14:52
Copy link
Contributor Author

@fl0rek fl0rek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxpedda thanks for the review! Pushed the update after the prolonged xmas break

crates/macro-support/src/parser.rs Outdated Show resolved Hide resolved
tests/wasm/classes.rs Show resolved Hide resolved
tests/wasm/classes.rs Show resolved Hide resolved
tests/wasm/classes.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
crates/macro-support/src/lib.rs Outdated Show resolved Hide resolved
crates/macro-support/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@daxpedda
Copy link
Collaborator

Ah, apparently this requires a rebase! Otherwise LGTM!

@fl0rek fl0rek force-pushed the feat/cfg_attr-structs-rel branch from 3c59426 to dc4ed50 Compare January 12, 2025 09:16
@fl0rek fl0rek requested a review from daxpedda January 12, 2025 09:30
@daxpedda daxpedda merged commit 8acb195 into rustwasm:main Jan 12, 2025
67 checks passed
@daxpedda daxpedda mentioned this pull request Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author Waiting for author to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wasm_bindgen(skip) in cfg_attr
2 participants