Deno: WASI support for Webassembly

Created on 22 Sep 2019  路  6Comments  路  Source: denoland/deno

I'd love to be able to use Deno as the glue for a bunch of backend wasm modules. The wasi interfaces is a systems interface for webassembly in non-web uses.

https://github.com/CraneStation/wasmtime is a wasi-implementing wasm runtime in rust, though It has a different sandboxing model than v8's.

I've seen WASI support mentioned in a few other issues, so I wanted to centralize that part of the discussion.

related: #2552 #672 #1325

Most helpful comment

A little while later (exactly one month of work to be precise); the current implementation status of snapshot_preview1 looks something like this

| Name | Status | Notes |
|---------------------------|:-------:|----------------------------------------------------------------------------------------|
| args_get | ✓ | |
| args_sizes_get | ✓ | |
| environ_get | ✓ | |
| environ_sizes_get | ✓ | |
| clock_res_get | ✓ | |
| clock_time_get | ✓ | |
| fd_advise | | This has no obvious path to implementation at this time. |
| fd_allocate | | This has no obvious path to implementation at this time. |
| fd_close | ✓ | |
| fd_datasync | | This is blocking on getting fdatasync(2) implemented upstream in Deno. |
| fd_fdstat_get | ✓ | This currently does not write flags and rights as we do not track those at the moment. |
| fd_fdstat_set_flags | | This has no obvious path to implementation at this time. |
| fd_fdstat_set_rights | | |
| fd_filestat_get | | This is blocking on getting fstat implemented upstream in Deno. |
| fd_filestat_set_size | | This is blocking on getting ftruncate implemented upstream in Deno. |
| fd_filestat_set_times | ✓ | |
| fd_pread | ✓ | |
| fd_prestat_get | ✓ | |
| fd_prestat_dir_name | ✓ | |
| fd_pwrite | ✓ | |
| fd_read | ✓ | |
| fd_readdir | | |
| fd_renumber | ✓ | |
| fd_seek | ✓ | |
| fd_sync | ✓ | This is blocking on getting fsync(2) implemented upstream in Deno. |
| fd_tell | ✓ | |
| fd_write | ✓ | |
| path_create_directory | ✓ | |
| path_filestat_get | ✓ | |
| path_filestat_set_times | ✓ | |
| path_link | ✓ | |
| path_open | ✓ | Opening directories is not portable |
| path_readlink | ✓ | |
| path_remove_directory | ✓ | |
| path_rename | ✓ | |
| path_symlink | ✓ | |
| path_unlink_file | ✓ | |
| poll_oneoff | ✓ | |
| proc_exit | ✓ | |
| proc_raise | | |
| sched_yield | | |
| random_get | ✓ | |
| sock_recv | | |
| sock_send | | |
| sock_shutdown | | |

Most of these blockers are in master already so will be working moving this into std soon.

All 6 comments

Yes, agreed, though WASI is still real early in its development. I think we would want to keep it quite experimental in Deno, even Deno being experimental, as I suspect there will be a lot of churn. We might also want to consider getting involved in the working group as well.

We will release soon a TypeScript package to run WASI modules very easily both in server-side and client-side. Perhaps Deno can be a great use case for integrating it!

Apart from this, the Wasmer runtime can also embedded easily in Rust. However it might make more sense to use v8 with a wrapper on top to be able to run WASI.

Either way, I'd love to help in any way!

And here we go!

Here's the @wasmer/wasi package: https://github.com/wasmerio/wasmer-js/tree/master/packages/wasi (npm package)

The announcement is here: https://medium.com/wasmer/wasmer-js-9a53e837b80

Hope you can find it useful!!

Node already has an experimental WASI support in v13:

It may be useful to see how it is implemented and used. Example:

const wasi = new WASI({
  args: process.argv,
  env: process.env,
  preopens: {
    '/sandbox': '/some/real/path/that/wasm/can/access'
  }
});

Published https://deno.land/x/wasi yesterday, it is still a work in progress as not every syscall can be mapped efficiently at the moment, for example:

  • Deno.read needs to be able to take an optional offset for a reasonable fd_pread implementation (https://github.com/denoland/deno/issues/3508).
  • Deno.write needs to be able to take an optional offset for a reasonable fd_pwrite implementation (https://github.com/denoland/deno/issues/3508).

But everything should be implementable as plain modules as Deno matures to have a set of sound syscalls.

A little while later (exactly one month of work to be precise); the current implementation status of snapshot_preview1 looks something like this

| Name | Status | Notes |
|---------------------------|:-------:|----------------------------------------------------------------------------------------|
| args_get | ✓ | |
| args_sizes_get | ✓ | |
| environ_get | ✓ | |
| environ_sizes_get | ✓ | |
| clock_res_get | ✓ | |
| clock_time_get | ✓ | |
| fd_advise | | This has no obvious path to implementation at this time. |
| fd_allocate | | This has no obvious path to implementation at this time. |
| fd_close | ✓ | |
| fd_datasync | | This is blocking on getting fdatasync(2) implemented upstream in Deno. |
| fd_fdstat_get | ✓ | This currently does not write flags and rights as we do not track those at the moment. |
| fd_fdstat_set_flags | | This has no obvious path to implementation at this time. |
| fd_fdstat_set_rights | | |
| fd_filestat_get | | This is blocking on getting fstat implemented upstream in Deno. |
| fd_filestat_set_size | | This is blocking on getting ftruncate implemented upstream in Deno. |
| fd_filestat_set_times | ✓ | |
| fd_pread | ✓ | |
| fd_prestat_get | ✓ | |
| fd_prestat_dir_name | ✓ | |
| fd_pwrite | ✓ | |
| fd_read | ✓ | |
| fd_readdir | | |
| fd_renumber | ✓ | |
| fd_seek | ✓ | |
| fd_sync | ✓ | This is blocking on getting fsync(2) implemented upstream in Deno. |
| fd_tell | ✓ | |
| fd_write | ✓ | |
| path_create_directory | ✓ | |
| path_filestat_get | ✓ | |
| path_filestat_set_times | ✓ | |
| path_link | ✓ | |
| path_open | ✓ | Opening directories is not portable |
| path_readlink | ✓ | |
| path_remove_directory | ✓ | |
| path_rename | ✓ | |
| path_symlink | ✓ | |
| path_unlink_file | ✓ | |
| poll_oneoff | ✓ | |
| proc_exit | ✓ | |
| proc_raise | | |
| sched_yield | | |
| random_get | ✓ | |
| sock_recv | | |
| sock_send | | |
| sock_shutdown | | |

Most of these blockers are in master already so will be working moving this into std soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justjavac picture justjavac  路  3Comments

ry picture ry  路  3Comments

metakeule picture metakeule  路  3Comments

ry picture ry  路  3Comments

sh7dm picture sh7dm  路  3Comments