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

Support complex macros. #2369

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Conversation

reitermarkus
Copy link
Contributor

@reitermarkus reitermarkus commented Dec 8, 2022

This supersedes #2268 which aimed to support casts in macros.

The cmacro crate I developed over the last months allows parsing casts in variable-like macros and even more complex macros, such as function-like macros and nested macros.

Macro parsing has been split from Var into a separate MacroDef type, since macros need to be parsed last. Variables can be evaluated at parse time, macros on the other hand can only be fully evaluated after all types, variables, functions and other macros have been parsed. This allows getting the correct final value and is needed for parsing nested macros.

@bors-servo
Copy link

☔ The latest upstream changes (presumably 5875949) made this pull request unmergeable. Please resolve the merge conflicts.

@reitermarkus
Copy link
Contributor Author

Can someone please take a look at this PR? It's been over three months without a review.

@pvdrz
Copy link
Contributor

pvdrz commented Mar 14, 2023

👋 Hi! Sorry for not giving you an answer in all this time. Somehow I missed this and wasn't aware of it.

I will properly review this PR as I think it might solve many issues regarding the type that is assigned to these define macros when they get translated as constants. Bindgen has depended for a long time on rust-cexpr but having someone breathe new life to this part of bindgen is good IMHO.

That being said, we still should figure out the logistics of maintenance due to bindgen using your crate and I don't have the whole picture in my head so I'll defer that part to @emilio

@pvdrz pvdrz changed the base branch from master to main March 14, 2023 17:29
Copy link
Contributor

@pvdrz pvdrz left a comment

Choose a reason for hiding this comment

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

I'm done with the review 🎉

I apologize in advance if I'm being harsh on some comments. I am really interested on understanding how all of this works 😁

.github/workflows/bindgen.yml Outdated Show resolved Hide resolved
@@ -2,6 +2,7 @@
name = "bindgen-integration"
description = "A package to test various bindgen features"
version = "0.1.0"
edition = "2018"
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to set this edition here? what's not working without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just checked. Exporting macros as items (pub __cmacro_MACRO as MACRO;) is not supported without it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... I think we might need to document this edition restriction somewhere. Not sure what's bindgen position about this but I could imagine someone having a code breakage due to certain macros now being supported.

bindgen-tests/tests/expectations/tests/macro_const.rs Outdated Show resolved Hide resolved
bindgen/ir/context.rs Show resolved Hide resolved
bindgen/ir/context.rs Show resolved Hide resolved
bindgen-tests/tests/expectations/tests/macro-cast.rs Outdated Show resolved Hide resolved
@overhacked
Copy link

@reitermarkus, this is really exciting because it would resolve a downstream bug I ran into with bssl-sys. The review comments above looked positive, any idea when it might be merged?

@reitermarkus
Copy link
Contributor Author

@overhacked, thanks for testing.

any idea when it might be merged?

No idea when this will be merged, I already split some of the changes into separate PRs to make them easier to review, but all of them seem to also have stalled.

@therishidesai
Copy link

Any update from the bindgen team on when this will get merged?

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 this pull request may close these issues.

8 participants