Skip to content

Commit 4082171

Browse files
authored
feat(std/wasi): add wasi_snapshot_preview1 (denoland/deno#6441)
1 parent bd0f5b0 commit 4082171

File tree

9 files changed

+1552
-0
lines changed

9 files changed

+1552
-0
lines changed

wasi/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# wasi
2+
3+
This module provides an implementation of the WebAssembly System Interface
4+
5+
## Supported Syscalls
6+
7+
## Usage
8+
9+
```typescript
10+
import WASI from "https://deno.land/std/wasi/snapshot_preview1.ts";
11+
12+
const wasi = new WASI({
13+
args: Deno.args,
14+
env: Deno.env,
15+
});
16+
17+
const binary = Deno.readAll("path/to/your/module.wasm");
18+
const module = await WebAssembly.compile(binary);
19+
const instance = await WebAssembly.instantiate(module, {
20+
wasi_snapshot_preview1: wasi.exports,
21+
});
22+
23+
wasi.memory = module.exports.memory;
24+
25+
if (module.exports._start) {
26+
instance.exports._start();
27+
} else if (module.exports._initialize) {
28+
instance.exports._initialize();
29+
} else {
30+
throw new Error("No entry point found");
31+
}
32+
```
33+
34+
## Testing
35+
36+
The test suite for this module spawns rustc processes to compile various example
37+
Rust programs. You must have wasm targets enabled:
38+
39+
```
40+
rustup target add wasm32-wasi
41+
rustup target add wasm32-unknown-unknown
42+
```

0 commit comments

Comments
 (0)