-
Notifications
You must be signed in to change notification settings - Fork 736
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
feat: add custom attributes to fn
items
#3088
base: main
Are you sure you want to change the base?
Conversation
I'd love to add some tests as well but I'm not sure how I would do that, can't get anything other than basic tests to run. |
You can take a look at #2866, where I added some tests along with the support for custom attributes on other items ( |
I will be adding further changes to this PR. The I've made the following changes already:
- fn add_attributes(&self, _info: &AttributeInfo<'_>) -> Vec<String> { vec![] }
+ fn process_attributes(&self, _info: &AttributeInfo<'_>, _attributes: &mut HashSet<String>) {} Example usage: fn process_attributes(&self, info: &bindgen::callbacks::AttributeInfo<'_>, attrs: &mut HashSet<String>) {
match info.kind {
AttrKind::Var => {
attrs.insert(r#"#[cfg(feature="statics")]"#.to_owned());
}
AttrKind::Struct | AttrKind::Union | AttrKind::Enum => {
attrs.insert(r#"#[cfg(feature="structs")]"#.to_owned());
}
AttrKind::Function(_) => {
attrs.insert(r#"#[cfg(feature="functions")]"#.to_owned());
attrs.insert(if info.name.starts_with("NtUser") {
r#"#[link(name = "ntuser")]"#
} else {
r#"#[link(name = "ntdll")]"#
}.to_owned());
}
}
} Example output with #[cfg(feature = "functions")]
pub mod unsafe_extern_C_cfg_feature_functions_link_name_ntdll {
#[link(name = "ntdll")]
unsafe extern "C" {
pub fn NtCallbackReturn(
OutputBuffer: PVOID,
OutputLength: ULONG,
Status: NTSTATUS,
) -> NTSTATUS;
// ...
}
#[cfg(feature = "functions")]
pub use unsafe_extern_C_cfg_feature_functions_link_name_ntdll::*;
I still have to restore CLI functionality, we can possibly even add Progress can be tracked at https://github.com/oberrich/rust-bindgen/tree/alias for now, I will be merging them into this branch once it's ready for a review. |
I've rebased my changes onto upstream to simplify merging and cleaned up the commit history to make the changes more digestible. @jschwe, I noticed you've merged #3103, and I'm wondering about the usefulness of We could take a similar approach to The I'm open to feedback on the best approach—would love to hear any thoughts! |
Just to clarify: that PR only changed the behavior from using the last registered callback (where the implementation might very well be the default I find it very convenient to setup a default global implementation to process comments, e.g. converting doxygen to markdown, and then for specific header files specify another callback, which overrides the global implementation and perhaps works around some issues for that specific header file. I also don't really see a use case for layering different comment processing steps via different callbacks. Is there something that can't be done in one callback, or would be more convenient? I think it would be much harder to reason about, since the order of the steps matter.
I think that issue is easily fixable without any changes. Let me check.
For my use-case at least I would prefer getting the original comment, since parsing doxygen comments is easier, then the post-processed markdown I generate in my case. |
@emilio Since you're merging PRs kindly pinging again for #3088 (comment) Looking forward to a preliminary review. |
@emilio @pvdrz I've now been waiting on a review for over 2 months. I understand being busy and all but not getting a response from the Rust Foundation for over 2 months is frustrating and gives me little hope for this PR ever getting merged. Users are eagerly waiting for these changes and I'm blocked due to mismanagement... |
@rust-lang / @rust-lang-owner maybe more resources should be allocated to this very key piece of software? This is a necessary and long-awaited feature, yet I'm being ghosted by the organization since last Christmas [sic]. I don't think this is how contributors should be treated and hope this gets addressed quickly, multiple projects are blocked on this change. Despite having little time of my own, I made time to work on this change; as of now, I see now way forward for this change other than action on your side. Please let me know, if this is good to be merged once the remaining issues are resolved. I do understand that this is a rather large change and can take SOME time to review, certainly not 5 months of radio silence, however. The situation is very frustrating, I'm not sure why @emilio or @pvdrz refuse to even comment on this PR; I'm trying to stay positive here and not infer any malice, for now. |
👋 I'd like to clarify some points here to (hopefully) avoid any confusion. So first of all, I understand your frustration as I've been several times in your position as well and it is not nice. So, I think I speak for the both of us (Emilio and I) when I say I'm sorry. However, this is a project where all its maintainers dedicate their free (both as in non-busy and non-paid) time to it. We just maintain this project out of personal interest and maybe some guilt to see it go unmaintained for extended periods of time. Sadly, that means that whenever something else happens in our lives, the project goes unmaintained because simply there's no one to take care of the influx of PRs, issues and whatnot. Personally, I haven't found myself with time and the right head space to review any code on this project since the end of last year for personal reasons that I don't have the obligation to disclose here so I won't. I suspect Emilio finds himself in a similar position. So, you're right to not infer any malice here. We're simply not available. On a more technical front. I also think this is an important feature as it could fix several issues that otherwise would require a custom fix instead of having a general mechanism. However, I feel hesitant to review a PR with almost 70 commits, more than 1000 line changes, merge conflicts and without a passing CI check. I'm unsure if this came to be as a lack of acknowledgement from us or not. |
I've re-applied all changes on clean master tree, when I requested a review earlier.
I can understand this very well, I've recently been diagnosed with bipolar disorder. Maybe @jschwe and someone else wants to band together to create a fork where we can settle details more easily and send in a more complete product for a single review. I understand the changes here are massive as they touch codegen in a lot of places and attributes play into every aspect of code. More than happy to help as much as I can, my life is also busy, but it helps me to work a lot; I'm a bit of a workaholic, although I work on a massive amount of projects at a single time, so progress might be in weeks/months territory, before we can send in a meaningful version. If you want to help contribute, feel free to reach out at [email protected]; we can discuss details there and establish direct comms off-the-hub. P.S.: Anyone is welcome to contribute, the examples I mentioned are only because they've been contributing a lot already. |
This PR adds functionality to add custom attributes to function items (proposed in #2978).
I've implemented this by extending the
TypeKind
used byAttributeInfo
to include theFunction(FunctionKind)
variant (seeAttributeItemKind
).Unifying the callback this way is a breaking change when
--with_attribute_custom
or matching on thekind
field is used.