WIP: Add support for adding item attributes to generated types #671
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.
This adds support for parsing attributes in combination with the tree being generated. The idea is that the parsed attributes added to each item associated with the types being generated. That way, it's possible to selective add compile-time constraints like feature flags.
This patch only adds support for parsing feature flags right now. Also the generated attributes only apply to functions, see below for more.
Example
This would for example cause
XAudio2CreateWithVersionInfo
to be generated like this:Motivation
I want to be able use feature flags to determine which which linked libraries should be required for compiling my crate, and the above is enough to avoid a linker error in case
XAudio2_9
is not available and the feature is disabled.The attributes are currently only added to functions, because these are the only items which include
#[link]
attributes. Filtering these allows tree shaking in rustc to do the rest of the work right now. But in principle these could be added to any item that is recursively included.WIP
This is currently in WIP to garner feedback.
What I want to do before it's merged is:
TypeConstraints
. It is currently used to recursively addany(...)
dependencies for the complete intersection if features in use for any given item, but it's a bit messy.all(...)
andany(...)
.