2020-06-24 09:27:31 -04:00
|
|
|
# wasi
|
|
|
|
|
2020-10-03 16:19:11 -04:00
|
|
|
This module provides an implementation of the WebAssembly System Interface.
|
2020-06-24 09:27:31 -04:00
|
|
|
|
|
|
|
## Supported Syscalls
|
|
|
|
|
2020-06-24 17:03:40 -04:00
|
|
|
### wasi_snapshot_preview1
|
|
|
|
|
|
|
|
- [x] args_get
|
|
|
|
- [x] args_sizes_get
|
|
|
|
- [x] environ_get
|
|
|
|
- [x] environ_sizes_get
|
|
|
|
- [x] clock_res_get
|
|
|
|
- [x] clock_time_get
|
|
|
|
- [ ] fd_advise
|
|
|
|
- [ ] fd_allocate
|
|
|
|
- [x] fd_close
|
2020-06-29 10:44:08 -04:00
|
|
|
- [x] fd_datasync
|
2020-06-24 17:03:40 -04:00
|
|
|
- [x] fd_fdstat_get
|
|
|
|
- [ ] fd_fdstat_set_flags
|
|
|
|
- [ ] fd_fdstat_set_rights
|
2020-06-29 09:34:18 -04:00
|
|
|
- [x] fd_filestat_get
|
2020-06-29 14:36:22 -04:00
|
|
|
- [x] fd_filestat_set_size
|
2020-06-24 17:03:40 -04:00
|
|
|
- [x] fd_filestat_set_times
|
|
|
|
- [x] fd_pread
|
|
|
|
- [x] fd_prestat_get
|
|
|
|
- [x] fd_prestat_dir_name
|
|
|
|
- [x] fd_pwrite
|
|
|
|
- [x] fd_read
|
2020-07-05 18:08:05 -04:00
|
|
|
- [x] fd_readdir
|
2020-06-24 17:03:40 -04:00
|
|
|
- [x] fd_renumber
|
|
|
|
- [x] fd_seek
|
2020-06-29 17:45:39 -04:00
|
|
|
- [x] fd_sync
|
2020-06-24 17:03:40 -04:00
|
|
|
- [x] fd_tell
|
|
|
|
- [x] fd_write
|
|
|
|
- [x] path_create_directory
|
|
|
|
- [x] path_filestat_get
|
|
|
|
- [x] path_filestat_set_times
|
|
|
|
- [x] path_link
|
|
|
|
- [x] path_open
|
|
|
|
- [x] path_readlink
|
|
|
|
- [x] path_remove_directory
|
|
|
|
- [x] path_rename
|
|
|
|
- [x] path_symlink
|
|
|
|
- [x] path_unlink_file
|
|
|
|
- [x] poll_oneoff
|
|
|
|
- [x] proc_exit
|
|
|
|
- [ ] proc_raise
|
2020-10-24 10:05:30 -04:00
|
|
|
- [x] sched_yield
|
2020-06-24 17:03:40 -04:00
|
|
|
- [x] random_get
|
|
|
|
- [ ] sock_recv
|
|
|
|
- [ ] sock_send
|
|
|
|
- [ ] sock_shutdown
|
|
|
|
|
2020-06-24 09:27:31 -04:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```typescript
|
2020-10-04 08:18:36 -04:00
|
|
|
import Context from "https://deno.land/std@$STD_VERSION/wasi/snapshot_preview1.ts";
|
2020-06-24 09:27:31 -04:00
|
|
|
|
2020-08-24 12:21:06 -04:00
|
|
|
const context = new Context({
|
2020-06-24 09:27:31 -04:00
|
|
|
args: Deno.args,
|
2020-10-03 09:52:34 -04:00
|
|
|
env: Deno.env.toObject(),
|
2020-06-24 09:27:31 -04:00
|
|
|
});
|
|
|
|
|
2020-06-24 22:21:39 -04:00
|
|
|
const binary = await Deno.readFile("path/to/your/module.wasm");
|
2020-06-24 09:27:31 -04:00
|
|
|
const module = await WebAssembly.compile(binary);
|
|
|
|
const instance = await WebAssembly.instantiate(module, {
|
2020-10-03 09:52:34 -04:00
|
|
|
"wasi_snapshot_preview1": context.exports,
|
2020-06-24 09:27:31 -04:00
|
|
|
});
|
|
|
|
|
2020-10-03 09:52:34 -04:00
|
|
|
const {
|
|
|
|
_start: start,
|
|
|
|
_initialize: initialize,
|
|
|
|
memory,
|
|
|
|
} = instance.exports;
|
2020-06-24 09:27:31 -04:00
|
|
|
|
2020-10-03 09:52:34 -04:00
|
|
|
context.memory = memory as WebAssembly.Memory;
|
|
|
|
|
|
|
|
if (start instanceof Function) {
|
|
|
|
start();
|
|
|
|
} else if (initialize instanceof Function) {
|
|
|
|
initialize();
|
2020-06-24 09:27:31 -04:00
|
|
|
} else {
|
2020-10-03 09:52:34 -04:00
|
|
|
throw new Error(
|
|
|
|
"No '_start' or '_initialize' entry point found in WebAssembly module, make sure to compile with wasm32-wasi as the target.",
|
|
|
|
);
|
2020-06-24 09:27:31 -04:00
|
|
|
}
|
|
|
|
```
|