-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add exporting Rust functions as variadic JS functions #2954
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
Add exporting Rust functions as variadic JS functions #2954
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me! Could a typescript test be added to ensure that it shows up in the *.d.ts
file correctly too?
crates/macro-support/src/parser.rs
Outdated
// return Err(Diagnostic::span_error(*span, msg)); | ||
// } | ||
// Ok(()) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We shouldn't have dead code in there without a reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed!
crates/macro-support/src/parser.rs
Outdated
@@ -411,7 +411,7 @@ impl<'a> ConvertToAst<BindgenAttrs> for &'a mut syn::ItemStruct { | |||
}; | |||
|
|||
let attrs = BindgenAttrs::find(&mut field.attrs)?; | |||
assert_not_variadic(&attrs)?; | |||
// assert_not_variadic(&attrs)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have dead code in there? Can you please add a comment explaining why this is commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, no longer needed.
crates/macro-support/src/parser.rs
Outdated
// return Err(Diagnostic::span_error(*span, msg)); | ||
// } | ||
// Ok(()) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We shouldn't have dead code in there without a reason
I created tests for simple variadic functions inside Note: I needed to rebase this branch to pass on CI. |
Thanks! |
I think this regressed some part of processing somehow. I still haven't reduced a reproduction from my private codebase, but meanwhile here's the panic stacktrace I get:
Reverting the merge commit makes things working again. |
Nevermind, looks like it's just a schema breaking change and I need to align my project's dependency to the git version too. |
This is an attempt to solve #694.
I kept the
variadic
bindgen
attribute and assumed the last argument will be received as a JS Array object with the variadic values. Added avariadic
flag inside theFunction
s structures, and changed the export signature of functions flagged as variadic, then only the JS signature changed.I found a limitation in this implementation around the argument typing export. If we export a
variadic
function with a type different fromJsValue
, we can generate the TS exports with wrong types.For example:
Will generate:
The workaround I found is create a new type and export the
typescript_type
(I tested extending the Array structure and it worked as "expected").Suggestions are welcome.
TODO:
add the variadic "dots" in the JSDoc generation code.