Emit cfg helper macros for struct-literal #define constants - #1181
Open
youknowone wants to merge 1 commit into
Open
Emit cfg helper macros for struct-literal #define constants #1181youknowone wants to merge 1 commit into
#define constants #1181youknowone wants to merge 1 commit into
Conversation
…a#955) `#if` cannot appear inside a macro replacement list, so `#[cfg]` on struct fields was silently dropped when a struct-literal constant was emitted as a `#define`. Emit one `__CBINDGEN_CFG_<condition>(...)` helper per condition that appears in such a literal and wrap each gated field initializer, including its trailing comma, in it. The macro name encodes the condition tree with node tags and lengths so structurally different conditions never share a name. Nested struct literals inside a `#define` in C++ also use the macro form instead of the constexpr `#if` form. Assisted-by: Claude
youknowone
force-pushed
the
cfg-define-macro
branch
from
August 28, 2026 23:11
9cd83de to
8e76b66
Compare
#define constants (#955)#define constants
youknowone
commented
Aug 29, 2026
Comment on lines
+281
to
+283
| out.push('D'); | ||
| out.push_str(&define.len().to_string()); | ||
| out.push('_'); |
Contributor
Author
There was a problem hiding this comment.
a little bit of mangling to avoid accidental name collision. please tell me a better approach if this is not the best
youknowone
marked this pull request as ready for review
August 29, 2026 12:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
another trial of #955