Skip to content

feat(std/wasi) add wasi_snapshot_preview1 #6441

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

Merged
merged 8 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ jobs:
with:
rust-version: 1.44.0

- name: Install rust targets
run: |
# Necessary for the std/wasi tests
rustup target add wasm32-unknown-unknown
rustup target add wasm32-wasi

- name: Install clippy and rustfmt
if: matrix.config.kind == 'lint'
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ yarn.lock
# yarn creates this in error.
tools/node_modules/

# compiled wasm files
std/wasi/testdata/snapshot_preview1/

# MacOS generated files
.DS_Store
.DS_Store?
42 changes: 42 additions & 0 deletions std/wasi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# wasi

This module provides an implementation of the WebAssembly System Interface

## Supported Syscalls

## Usage

```typescript
import WASI from "https://deno.land/std/wasi/snapshot_preview1.ts";

const wasi = new WASI({
args: Deno.args,
env: Deno.env,
});

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

wasi.memory = module.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
```
Loading