-
Notifications
You must be signed in to change notification settings - Fork 1.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
Execute wasm file in NodeJS #161
Comments
https://github.com/devsnek/node-wasi may be what you want. |
Thanks @bjorn3 I managed to run the wasm package, but get into the first error defined in the You know how to pass params to wasm main function? const WASI = require('wasi');
const fs = require('fs');
const buf = fs.readFileSync('./demo.wasm');
const wasi = new WASI({
// preopenDirectories: { '.': '.' },
});
(async () => {
let res = await WebAssembly.instantiate(buf, {
wasi_unstable: wasi.exports
});
wasi.setMemory(res.instance.exports.memory);
res.instance.exports._start("./input.txt", "output.txt");
})() |
https://github.com/devsnek/node-wasi/blob/68902020ce28210ab1fc12dfaec090ef82c44263/index.js#L507 It seems like you can use |
It's overriding the 1st arg, so I tried passing the wasm executable path and the 2 other args but getting
Line 19 |
@Gregoirevda you'll need to run it with |
I managed to make it work with path.resolve
I'm getting the next error Is there a way to give capability with WASI like |
That's what |
@bjorn3 both input.txt and output.txt are in the same folder. I tried passing |
What are key:value used for? |
e.g. if you wanted to expose |
Thanks @devsnek const wasi = new WASI({
preopenDirectories: { '.': '.' },
args: [__dirname, 'test.txt', 'output.txt']
}); instead of I also went from node 11.x to node 12.3.0 and there only I could have access to the Arguments are now red correctly, files are opened, but the C code fails at writing. From this file. But it ofcourse works with wasmtime. I tried changing the out file to |
Same error with stdio |
* Treat all warnings as errors in the CI * Build only in release mode
I think this can be closed. It isn't related to Cranelift or Wasmtime. |
We have only ever used Unknown for the stdio streams, and I don't expect us to use it for anything else in the future, so rename it. Set the returned filetype to character device: Closes bytecodealliance#146. Also, fix some warnings.
Add support for WASM Global Variables
Verify integer min/max. These rules are a great demonstration of the new priority support, since the correctness of the `cmp_and_choose` helper rule for `fits_in_64` relies on the higher priority 16-bit case. Updates bytecodealliance#128
I'd like to expand the tutorial on how to run the wasm file in NodeJS after running it with wasmtime.
Normally you can simply run
WebAssembly.instantiate(buf)
, but here the demo.c contains arguments input.txt and output.txt.The WebAssembly requires a
wasi_unstable
object and within that afd_prestat_get
function, but I don't know how it should look like...index.js
The text was updated successfully, but these errors were encountered: