Skip to content
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

Merged
merged 6 commits into from
Jul 22, 2024
Merged

Fixed deno support. #3990

merged 6 commits into from
Jul 22, 2024

Conversation

spigaz
Copy link
Contributor

@spigaz spigaz commented Jun 17, 2024

To be honest I just tried to minimize changes as much as possible to get it working.

@@ -30,7 +30,7 @@ wrap("info");
wrap("warn");
wrap("error");

cx = new wasm.WasmBindgenTestContext();
const cx = new wasm.WasmBindgenTestContext();
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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)

Copy link
Contributor Author

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...

Copy link
Collaborator

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;",
Copy link
Collaborator

@daxpedda daxpedda Jun 18, 2024

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@daxpedda daxpedda Jun 18, 2024

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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:

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.

Copy link
Contributor Author

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.

@daxpedda
Copy link
Collaborator

@Liamolucko is this something you are able to review?

@spigaz
Copy link
Contributor Author

spigaz commented Jul 2, 2024

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.

Copy link
Collaborator

@Liamolucko Liamolucko left a 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();
Copy link
Collaborator

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;",
Copy link
Collaborator

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:

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.

@spigaz
Copy link
Contributor Author

spigaz commented Jul 3, 2024

LGTM, thanks!

np

Could you add a changelog entry?

sure, done

I would've asked you to test this in CI, but it seems like that's already covered by #3920 anyway.

Yes, although I'm still working on improving them, so I tried to avoid conflicts as much as possible.

@spigaz
Copy link
Contributor Author

spigaz commented Jul 21, 2024

@daxpedda Is there anything missing for this one to be merged?

Copy link
Collaborator

@daxpedda daxpedda left a 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.

crates/cli/src/bin/wasm-bindgen-test-runner/deno.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@daxpedda daxpedda merged commit e8b023c into rustwasm:main Jul 22, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants