-
Notifications
You must be signed in to change notification settings - Fork 708
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
Consider making generated TokenStream public #1916
Comments
Not really opposed to this, I think... But why can't you use If that somehow doesn't work, I think a PR with either |
I must be overlooked |
My use case for this is to convert all function declarations to types (for dynamic loading instead of linking):
Becomes:
Currently I have to do this with the string manipulation as the TokenStream is not there. P.S. I figured I wouldn't have to do this if there was way to get |
This would also be useful for using |
I have two questions/comments about this topic:
|
Another case where this would prove useful is when the bound library has an online searchable documentation (or OpenGrok instance, etc). This would allow auto-linking the sys crate docs to the library ones, by adding a doc-comment on top of each type, i.e: extern "C" {
/// See: <https://libfoo.example/docs/search?definition=libfoo_init>
pub fn libfoo_init();
} Currently, doing that requires reparsing thousands of LOCs which hurts build-times a lot... |
not opposed to implementing this but maybe @emilio has opinions on it |
Effectively, yes. This is probably an extremely low-hanging fruit for build times for what must now be hundreds of projects like pgrx which don't simply take the code as-given but instead massage it with their own handling. We are generating north of 40KLOC at build time, and that's after I've made several efforts to reduce the amount of code we emit (before it was around 70KLOC). That's a lot of work to reparse. |
There's a need for an API for manipulating generated items according to some open issues here. For a library I'm working on, I run an extra step which generates some glue code on top of the bindgen output.
Unfortunately, I have to write out the bindings to a file first and then re-read them back, because tokens are made private here:
https://github.com/rust-lang/rust-bindgen/blob/master/src/lib.rs#L1914
Please consider making it public (maybe under a feature flag with re-exporting of
proc_macro2::TokenStream
) This is a safe change and will make it possible to manipulate the tokens (or just reuse them to generate some extra code ).The text was updated successfully, but these errors were encountered: