-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 first-class support for binary crates #1843
Conversation
this allows for first-class support of binary crates
Thanks for this! I agree that pattern matching and using inference here is the way to go. I think though what we need to do here is to perhaps inject a new function to be Currently this I believe will export a binding for |
considering that if i manually write
so hopefully replicating that verbatim is not actually necessary (especially bc a few pieces would be difficult or impossible to reliably replicate). zeroing out the arguments and dropping the return value is, unsurprisingly, far easier. |
I think you'll want to avoid calling Additionally can you be sure to add some tests for this change? |
I'm already synthesizing a replacement with walrus, but per your suggestion I've skipped i wasn't quite sure where to write tests, but wasm-bindgen/crates/cli/tests/wasm-bindgen/main.rs Lines 8 to 9 in 2e03961
|
Oh right sorry good point! I think though that none of And yeah that |
crates/cli-support/src/webidl/mod.rs
Outdated
.functions() | ||
.find(|x| x.name.as_ref().map_or(false, |x| x == "main")) | ||
.map(|x| (x.ty(), x.id())); | ||
if let Some((main_type, main_id)) = main_info { |
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.
Could this use a match
with an early return to de-indent the rest of this body?
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.
it could indeed!
|
Perfect, thanks! |
105: Simplify the example a bit r=grovesNL a=17cupsofcoffee Here's a few tweaks that make the example a bit simpler/up-to-date: * A seperate `wasm_main` is no longer required due to rustwasm/wasm-bindgen#1843. * The prelude import wasn't actually being used anywhere. * Nightly is no longer required to build this project, so I removed that from the instructions. * `--no-modules` has been replaced with `--target web`, which doesn't rely on global variables and allows support for [JS snippets](https://rustwasm.github.io/docs/wasm-bindgen/reference/js-snippets.html). * The only caveat to this is that the generates JS is a ES module instead of a basic JS file - but any browser that supports WASM will also support ES modules, so I don't think this is an issue in practice. Co-authored-by: Joe Clay <27cupsofcoffee@gmail.com>
105: Simplify the example a bit r=grovesNL a=17cupsofcoffee Here's a few tweaks that make the example a bit simpler/up-to-date: * A seperate `wasm_main` is no longer required due to rustwasm/wasm-bindgen#1843. * The prelude import wasn't actually being used anywhere. * Nightly is no longer required to build this project, so I removed that from the instructions. * `--no-modules` has been replaced with `--target web`, which doesn't rely on global variables and allows support for [JS snippets](https://rustwasm.github.io/docs/wasm-bindgen/reference/js-snippets.html). * The only caveat to this is that the generates JS is a ES module instead of a basic JS file - but any browser that supports WASM will also support ES modules, so I don't think this is an issue in practice. Co-authored-by: Joe Clay <27cupsofcoffee@gmail.com>
fixes #1630
Essentially, "if nothing was tagged
#[wasm_bindgen(start)]
and there is an exportedfn main(i32, i32) -> i32
then process it as though it were tagged that way."open questions before i'm confident this implementation is ready:
main
that is already tagged forwasm_bindgen
in some other way?shim_idx
field on the function descriptor be safely set to 0?argc
andargv
?