1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/std/wasi
Casper Beyer 15649b61bd
test(std/wasi): explicitly list modules for deterministic test runs (#7245)
This explicitly lists std/wasi test modules in a pre-sorted array for deterministic test runs.

As a side effect it makes it a bit more visible when a test has been added or removed aside
from having to look at the submodule update.
2020-09-04 07:14:51 -04:00
..
testdata@c2a9246e01 fix(std/wasi): invalid number to bigint conversion in fd_tell (#7215) 2020-08-27 11:38:12 +02:00
README.md BREAKING(std/wasi): rename Module to Context (#7110) 2020-08-24 18:21:06 +02:00
snapshot_preview1.ts chore(std/wasi): fix no-inner-declarations lints (#7286) 2020-08-31 17:13:55 +02:00
snapshot_preview1_test.ts test(std/wasi): explicitly list modules for deterministic test runs (#7245) 2020-09-04 07:14:51 -04:00
snapshot_preview1_test_runner.ts fix(cli): use upstream type definitions for WebAssembly (#7216) 2020-08-31 12:04:47 +02:00

wasi

This module provides an implementation of the WebAssembly System Interface

Supported Syscalls

wasi_snapshot_preview1

  • args_get
  • args_sizes_get
  • environ_get
  • environ_sizes_get
  • clock_res_get
  • clock_time_get
  • fd_advise
  • fd_allocate
  • fd_close
  • fd_datasync
  • fd_fdstat_get
  • fd_fdstat_set_flags
  • fd_fdstat_set_rights
  • fd_filestat_get
  • fd_filestat_set_size
  • 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
  • fd_tell
  • fd_write
  • path_create_directory
  • path_filestat_get
  • path_filestat_set_times
  • path_link
  • path_open
  • 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

Usage

import Context from "https://deno.land/std/wasi/snapshot_preview1.ts";

const context = new Context({
  args: Deno.args,
  env: Deno.env,
});

const binary = await Deno.readFile("path/to/your/module.wasm");
const module = await WebAssembly.compile(binary);
const instance = await WebAssembly.instantiate(module, {
  wasi_snapshot_preview1: context.exports,
});

context.memory = context.exports.memory;

if (module.exports._start) {
  instance.exports._start();
} else if (module.exports._initialize) {
  instance.exports._initialize();
} else {
  throw new Error("No entry point found");
}

Testing

The test suite for this module spawns rustc processes to compile various example Rust programs. You must have wasm targets enabled:

rustup target add wasm32-wasi
rustup target add wasm32-unknown-unknown