From cae7531c2bd514a8836f0a03f54ee3792c286965 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Fri, 12 Mar 2021 16:03:44 +0200 Subject: [PATCH] Add extras --- .github/workflows/publish.yml | 2 +- extra/wapm-package/README.md | 112 ++++++++++++++++++++++++++++ extra/wapm-package/build/.gitignore | 4 + extra/wapm-package/wapm.toml | 25 +++++++ 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 extra/wapm-package/README.md create mode 100644 extra/wapm-package/build/.gitignore create mode 100644 extra/wapm-package/wapm.toml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fd338fe..b882400 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -95,7 +95,7 @@ jobs: cp ./build/wasm3.wasm ./wasm3-wasi.wasm - name: Configure, Build wasm3-strace env: - CFLAGS: -DDEBUG -Dd_m3EnableStrace=2 + CFLAGS: -DDEBUG -Dd_m3EnableStrace=2 -Dd_m3RecordBacktraces=1 run: | source $HOME/.wasienv/wasienv.sh mkdir build-strace diff --git a/extra/wapm-package/README.md b/extra/wapm-package/README.md new file mode 100644 index 0000000..3cf1189 --- /dev/null +++ b/extra/wapm-package/README.md @@ -0,0 +1,112 @@ +# Wasm3 + +[Wasm3](https://github.com/wasm3/wasm3) is a high performance `WebAssembly` interpreter written in C. +It's packaged into a `WebAssembly` package, so you can finally run `WebAssembly` on `WebAssembly` 😆 + +When running natively, wasm3 is: + +**∼ 8x faster** than other known wasm interpreters +**∼ 4-5x slower** than state of the art wasm `JIT` engines +**∼ 12x slower** than native execution + +Based on [**CoreMark 1.0** benchmark](https://github.com/wasm3/wasm3/blob/master/docs/Performance.md). Your mileage may vary. + +## Running on WebAssembly.sh + +First you need to make a wasm file you want to run available in the filesystem. +One way to do this is to get it from a server using `curl` command: + +```sh +$ curl https://raw.githubusercontent.com/wasm3/wasm3/master/test/lang/fib32.wasm -o /tmp/fib32.wasm + +$ ls -l /tmp/fib32.wasm +---------- 1 somebody somegroup 62 1970-01-19 05:45 /tmp/fib32.wasm +``` + +Now we can run `wasm3` in interactive mode: + +```sh +$ wasm3 --repl /tmp/fib32.wasm +wasm3> fib 20 +Result: 6765 +wasm3> fib 30 +Result: 832040 +wasm3> ^C +$ +``` + +Or run a specific function directly: + +```sh +$ wasm3 --func fib /tmp/fib32.wasm 30 +Result: 832040 +``` + +`wasm3` also supports `WASI`, so you can run: + +```sh +$ curl https://raw.githubusercontent.com/wasm3/wasm3/master/test/wasi/simple/test.wasm -o /tmp/test.wasm +$ wasm3 /tmp/test.wasm +``` + +or even... run wasm3 inside wasm3: + +```sh +$ curl https://registry-cdn.wapm.io/contents/vshymanskyy/wasm3/0.4.9/build/wasm3-wasi.wasm -o /tmp/wasm3.wasm +$ wasm3 /tmp/wasm3.wasm /tmp/test.wasm +``` + +## Tracing + +You can also get structured traces of arbitrary WASM file execution (and this requires no specific support from the runtime): + +```sh +$ wasm3-strace --repl /tmp/fib32.wasm +wasm3> fib 3 +fib (i32: 3) { + fib (i32: 1) { + } = 1 + fib (i32: 2) { + fib (i32: 0) { + } = 0 + fib (i32: 1) { + } = 1 + } = 1 +} = 2 +Result: 2 +``` + +WASI apps tracing is also supported: + +```sh +$ wasm3-strace /tmp/test.wasm trap +_start () { + __wasm_call_ctors () { + __wasilibc_populate_preopens () { + wasi_snapshot_preview1!fd_prestat_get(3, 65528) { } = 0 + malloc (i32: 2) { + dlmalloc (i32: 2) { + sbrk (i32: 0) { + } = 131072 + } = 70016 + } = 70016 +... + strcmp (i32: 70127, i32: 32) { + } = 0 + test_trap () { + a () { + b () { + c () { + } !trap = [trap] unreachable executed +... +==== wasm backtrace: + 0: 0x000c59 - .unnamed!c + 1: 0x000c5e - .unnamed!b + 2: 0x000c68 - .unnamed!a + 3: 0x000c72 - .unnamed!test_trap + 4: 0x000d2c - .unnamed!main + 5: 0x0037c9 - .unnamed!__main_void + 6: 0x000edb - .unnamed!__original_main + 7: 0x0002f3 - .unnamed!_start +Error: [trap] unreachable executed +``` diff --git a/extra/wapm-package/build/.gitignore b/extra/wapm-package/build/.gitignore new file mode 100644 index 0000000..86d0cb2 --- /dev/null +++ b/extra/wapm-package/build/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/extra/wapm-package/wapm.toml b/extra/wapm-package/wapm.toml new file mode 100644 index 0000000..d6e3a4a --- /dev/null +++ b/extra/wapm-package/wapm.toml @@ -0,0 +1,25 @@ +[package] +name = "vshymanskyy/wasm3" +version = "0.4.9" +description = "🚀 The fastest WebAssembly interpreter. You can finally run WebAssembly on WebAssembly 😆" +readme = "README.md" +repository = "https://github.com/wasm3/wasm3" +homepage = "https://github.com/wasm3/wasm3" + +[[module]] +name = "wasm3" +source = "build/wasm3-wasi.wasm" +abi = "wasi" + +[[module]] +name = "wasm3-strace" +source = "build/wasm3-strace.wasm" +abi = "wasi" + +[[command]] +name = "wasm3" +module = "wasm3" + +[[command]] +name = "wasm3-strace" +module = "wasm3-strace"