-
-
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
Fixed deno support. #3990
Fixed deno support. #3990
Conversation
@@ -30,7 +30,7 @@ wrap("info"); | |||
wrap("warn"); | |||
wrap("error"); | |||
|
|||
cx = new wasm.WasmBindgenTestContext(); | |||
const cx = new wasm.WasmBindgenTestContext(); |
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 assume this is an unrelated change?
No need to remove it, just noting for other reviewers.
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.
No, that is required for deno, because deno implementation uses a part of the node implementation.
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 it would be good if you explain what you did exactly and why you did it in the OP or comments.
(maybe its more obvious for the actual reviewer)
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.
To be honest I don't remember all the details.
But by looking at the diffs, I don't think I made any decisions, I tried to follow the original intentions, I just added missing pieces and changed the order of some code to get it working.
I agree its hard to understand because the errors surfaced mainly in the generated run.js file, in this case, I was getting a variable missing error.
On another the variable was used before it was declared for instance...
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 the old version didn't work in Deno because it has strict mode enabled by default, which doesn't allow implicitly declaring global variables like that.
@@ -345,7 +345,8 @@ impl<'a> Context<'a> { | |||
}} | |||
|
|||
const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance; | |||
const wasm = wasmInstance.exports;", | |||
const wasm = wasmInstance.exports; | |||
export const __wasm = wasm;", |
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.
Note for reviewer: this is probably undesirable and at the very least should be limited to Deno.
EDIT: This part of the code already limits it to Deno.
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 didn't broke node or any of the implementations I tested so far, so I wasn't sure if deno was just being more strict than the others.
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'm more worried about exporting anything, even if prefixed by __
, unless its absolutely necessary. We don't want anyone starting to rely on it unless we intend to and we also don't want to occupy a name unless necessary.
Again, there is no real issue here, we should just double-check if this is really necessary.
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 understand your concerns, the generated code requires this variable both on node and on deno
const ok = await cx.run(tests.map(n => wasm.__wasm[n]))
For some reason, without the export it says its not declared on deno, perhaps because deno uses an import:
import * as wasm from "./{0}.js";
while node still uses a require:
const wasm = require("./{0}")
In practice it was being "exported" for node already, intentionally or not.
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 seems like this was added for Node only in #2012:
wasm-bindgen/crates/cli-support/src/js/mod.rs
Line 278 in ad82651
module.exports.__wasm = wasm; |
I don't like it very much, but this isn't making things any worse and removing it from Node is probably out of scope for this PR.
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'm not sure about the best approach either here or in other places, but it seems clear to me that some refactors are in order.
I don't think its just me, but when I'm just trying to fix issues, I try to avoid refactoring as much as possible to make the PR easier to review, but that strategy adds up, and its pretty clear that some refactors are in order.
Although, in this case and some others, I'm not sure the best approach is, as my point of view was quite narrow, focused on specific issues.
But I think opening issues with those changes, so that someone can pick up and provide a PR might be a very good idea.
@Liamolucko is this something you are able to review? |
Thanks to the multi target tests I was able to isolate an issue with the deno handling of the arguments, I already updated it to this PR also. |
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.
LGTM, thanks!
Could you add a changelog entry?
I would've asked you to test this in CI, but it seems like that's already covered by #3920 anyway.
@@ -30,7 +30,7 @@ wrap("info"); | |||
wrap("warn"); | |||
wrap("error"); | |||
|
|||
cx = new wasm.WasmBindgenTestContext(); | |||
const cx = new wasm.WasmBindgenTestContext(); |
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 the old version didn't work in Deno because it has strict mode enabled by default, which doesn't allow implicitly declaring global variables like that.
@@ -345,7 +345,8 @@ impl<'a> Context<'a> { | |||
}} | |||
|
|||
const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance; | |||
const wasm = wasmInstance.exports;", | |||
const wasm = wasmInstance.exports; | |||
export const __wasm = wasm;", |
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 seems like this was added for Node only in #2012:
wasm-bindgen/crates/cli-support/src/js/mod.rs
Line 278 in ad82651
module.exports.__wasm = wasm; |
I don't like it very much, but this isn't making things any worse and removing it from Node is probably out of scope for this PR.
np
sure, done
Yes, although I'm still working on improving them, so I tried to avoid conflicts as much as possible. |
@daxpedda Is there anything missing for this one to be merged? |
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.
As mentioned before, I can't really review this.
But seeing that Liamolucko has already approved it, I will go ahead and merge it after the nits are remedied.
…ort to CHANGELOG.
Co-authored-by: daxpedda <daxpedda@gmail.com>
To be honest I just tried to minimize changes as much as possible to get it working.