-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Support importing wasm modules #2552
Comments
For reference, here is the README about the integration. It is a Stage 1 proposal (and the WebAssembly committee follows the TC39 stage process), which means it is still quite early. I think this could be important to Deno, so maybe getting involved early would be a good thing, but is likely to be a bit of a rough road. This will present interesting challenges for TypeScript and trying to understand the exports of a WASM module, but I suspect this would be an iterative process, where it would be just an untyped import, but eventually could try to figure out a way to evaluate/type on the fly the imports and exports of a WASM Module. It is going to be fairly complex I suspect, with some mediation between V8 and the compiler. |
Just an update, the standard has moved to Stage 2. An important note in the proposal is that TLA is potentially needed to evaluate the module and hand it back to the ESM importer, so it is likely we need a version of TLA in V8 before we can really address this. |
I have some ideas and I probably will work on this one. Compiler for that should produce smth like this: const { instance } = await WebAssembly.instantiate(Uint8Array.from(atob("<WASM as base64>"), c => c.charCodeAt(0)));
module.exports = instance.exports;
|
We should be able to close this with #3328 |
It'd be great to have a toy example in the docs/manual. |
@hayd that could be a good first issue 😄 |
@sh7dm Ooops, did not realize that you are working on this too... Only noticed this issue just now. Would love to hear your feedback since currently in #3348 we have double compilation issue (and I did a hack to placate TS compiler... which might not be the most elegant thing) |
@kevinkassimo I will add an example to the manual. |
@kevinkassimo am i missing something here:
Or is asc not doing the right thing? |
@hayd can you get asc output .wat format? |
@hayd I tried (module
;; ...
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
;; ...
) Looks like this result is prepared for const fs = require("fs");
const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm"));
const imports = {
env: {
abort(_msg, _file, line, column) {
console.error("abort called at index.ts:" + line + ":" + column);
}
}
};
Object.defineProperty(module, "exports", {
get: () => new WebAssembly.Instance(compiled, imports).exports
}); This is why there is an attempt to import |
@hayd Figured out. You need to compile with the following flags:
This basically disables builtin Now
|
@kevinkassimo no problem, just had an idea, didn't work on anything yet. |
Could it be useful to run/import text files (wat/wit/witx) in addition to binary files?
Some formats to keep an eye on: The formats that describe the types might be especially useful. |
Any reason why this hasn't been closed? |
Manual documentation for wasm import is not complete. #3351 (review) |
The manual notes that wasm can be imported as it had been added later that day: |
@SyrupThinker , I think @ry will close #2552 & #3351 |
Can we re-open this? Or add some tag at least to indicate it's waiting for ECMAScript Stage 3. I had to manually go through the thread to see why this was closed, only to find out the support was once added and then removed. |
Update This is the status page on the platform status: https://www.chromestatus.com/feature/5987156463976448#details There is no active development in Chromium and there doesn't look like there is a lot of interest or activity there. Seems everyone has accepted the "fetch" instantiate streaming method. The big challenges with that for Deno are:
It won't come down the TC39 proposal route, because it has "nothing" to do with ECMAScript. Currently the proposal does not use ECMAScript import assertions: https://webassembly.github.io/esm-integration/js-api/index.html#esm-integration. |
Has there been any progress on discussion on #2150? |
Yes. Within the core team. It is something we are going to discuss in depth soon. We just have to get over how we deal with |
There has been considerable movement on this (thanks @takikawa). There is now an experimental implementation of WASM imports in WebKit, behind a flag. We should implement WASM imports again as per the most up to date specs: https://webassembly.github.io/esm-integration/js-api/index.html#esm-integration and whatwg/html#4372. I think the general approach for us would be the following:
Part 2 could be simplified once V8 implements WASM modules itself. The |
I can work on the |
I'm curious in how the wasm module will be imported. If using the assert import or not. |
Is there any progress on it ? Wasm Modules is currently at Stage 2 and usually Deno implement interesting features at this stage ... |
Fyi, whatwg/html#10380 has been merged and the Wasm proposal is at phase 3 ("implementation phase"). |
It's finally back after 5 years 🥲 |
where foo will correspond to the exports of the wasm module.
The text was updated successfully, but these errors were encountered: