-
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 deno target #2176
add deno target #2176
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.
Thanks! Dealing with various kinds of import systems can be pretty finnicky and tough to maintain over time. Would it be possible to add a test for this on CI?
looks like the test finally passes. |
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.
Nice! I was also wondering, as well, would it be possible to run the full test suite in deno? For example cargo test --test wasm
should in theory work for the wasm target. I don't think it exercises any node-specific behavior.
Additionally can you update guide/src/reference/deployment.md
with the new deno option?
I'm not sure what would need to be done to run the test suit in deno. |
Something like that would work, yeah, although since it's so similar to node it might be best to control with an env var rather than in the code itself. Either way though it's not the most urgent thing in the world. Running the full test suite would provide a lot of confidence that the wrapper generation here is working for all use cases, but since this is a new feature it doesn't have to do everything right out of the gate. |
alright, I tried running the test suite in deno but there seem to be two problems:
|
also all the tests use |
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.
Ah ok I think it's fine in that case to go ahead and land this in the meantime. We can perhaps track in an issue what it might look like to run in Deno on CI? Ideally we'd just switch everything to ES imports instead of using the weird hacks that are there today.
It also looks like a wasm file was checked in here too?
All looks great to me, thanks! |
I know this has already been merged, but why does Why can't you just do |
To be honest I didn't quite understand why the init function was needed and thought there were some changes to be done anyway because for Deno the file wouldn't be |
maybe wasm-pack can instead have a deno target using // @deno-types=foo.d.ts
export * from "./foo.js";
import init from "./foo.js";
init(Deno.readFileSync(import.meta.url logic)); |
@jakobhellermann The If you pass in an
That won't work, because then you cannot access the exports of the Rust code: import init, * as exports from "./foo.js";
init(Deno.readFileSync("./foo_bg.wasm")).then(() => {
// Use exports...
}); Instead, I recommend using our Rollup plugin, which will automatically call rust({
importHook: function (path) {
return "Deno.readFileSync(" + JSON.stringify(path) + ")";
},
}) |
I think it might still makes sense to have a deno target for "it works similarly to node" where it auto-inits, but perhaps the generated could could be refactored to use top-level |
@alexcrichton I'm okay with that, though I'm a bit concerned that it might create a precedent for other targets. |
It's true yeah I don't want to create a proliferation of too many targets, and @Pauan if you'd like I think it's fine if we revert this and continue discussion on an issue (sorry should have consulted first!) |
adds a new
OutputMode
for Deno.Exports and js-imports are generated like
OutputMode::Web
orOutputMode::Node { experimental_modules: true }
.wasm
-files cannot be imported directly, so the file is read at runtime. If embedding the file as a base64 string or similar is preferable, I can try to do that.