3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Deno v1.1.2でWebAssembly System Interface (WASI)が使えるようになったので試す

Posted at

Deno v1.1.2で実験的にWebAssembly System Interface (WASI)が使えるようになった
そこでとりあえず適当な.wasmファイルをstd/wasiを介して実行してみる

Rustで書かれた次のようなWebAssemblyコードがあったとする

main.rs
fn main() {
  println!("hello")
}
rustup target add wasm32-wasi
rustc --target wasm32-wasi main.rs # main.wasm がつくられる

つくられた .wasm ファイルを読み込み、 _start エントリーポイントを介して実行する

main.ts
import WASI from "https://deno.land/std/wasi/snapshot_preview1.ts";
const wasi = new WASI({});
const binary = await Deno.readFile("main.wasm");
const module = await WebAssembly.compile(binary);
const instance = await WebAssembly.instantiate(module, {
  wasi_snapshot_preview1: wasi.exports,
});
wasi.memory = instance.exports.memory;
instance.exports._start();
deno run --allow-read main.ts # => hello

実行できた
詳細とサポート状況に関しては std/wasi を参照してほしい

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?