Updates to AssemblyScript 0.21 which no longer includes WASI (#776)

This updates to AssemblyScript 0.21 which no longer includes WASI. This
updates guidance to use the shim, which I verified works.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-08-29 16:55:32 +08:00
committed by GitHub
parent 17b8591dcc
commit f2b141ef9c
8 changed files with 20 additions and 11 deletions

View File

@@ -12,15 +12,16 @@
// - "seed" - uses wazero.ModuleConfig WithRandSource as the source of seed
// values.
//
// See https://www.assemblyscript.org/concepts.html#special-imports
//
// # Relationship to WASI
//
// A program compiled to use WASI, via "import wasi" in any file, won't import
// these functions.
// AssemblyScript supports compiling JavaScript functions that use I/O, such
// as `console.log("hello")`. However, WASI is not built-in to AssemblyScript.
// Use the `wasi-shim` to compile if you get import errors.
//
// See wasi_snapshot_preview1.Instantiate and
// - https://www.assemblyscript.org/concepts.html#special-imports
// - https://www.assemblyscript.org/concepts.html#targeting-wasi
// - https://www.assemblyscript.org/compiler.html#compiler-options
// See https://github.com/AssemblyScript/wasi-shim#usage and
// wasi_snapshot_preview1.Instantiate for more.
package assemblyscript
import (

View File

@@ -13,5 +13,13 @@ Ex.
```bash
$ go run assemblyscript.go 7
hello_world returned: 10
sad sad world at assemblyscript.ts:7:3
sad sad world at index.ts:7:3
```
Note: [index.ts](testdata/index.ts) avoids use of JavaScript functions that use
I/O, such as [console.log][1]. If your code uses these, compile your code with
the [wasi-shim][2] and configure in wazero using
`wasi_snapshot_preview1.Instantiate`.
[1]: https://github.com/AssemblyScript/assemblyscript/blob/v0.21.2/std/assembly/bindings/dom.ts#L143
[2]: https://github.com/AssemblyScript/wasi-shim#usage

View File

@@ -14,7 +14,7 @@ import (
// asWasm compiled using `npm install && npm run build`
//
//go:embed testdata/assemblyscript.wasm
//go:embed testdata/index.wasm
var asWasm []byte
// main shows how to interact with a WebAssembly function that was compiled

View File

@@ -13,5 +13,5 @@ import (
func Test_main(t *testing.T) {
stdout, stderr := maintester.TestMain(t, main, "assemblyscript", "7")
require.Equal(t, "hello_world returned: 10", stdout)
require.Equal(t, "sad sad world at assemblyscript.ts:7:3\n", stderr)
require.Equal(t, "sad sad world at index.ts:7:3\n", stderr)
}

Binary file not shown.

View File

@@ -2,9 +2,9 @@
"name": "hello-assemblyscript",
"version": "0.0.1",
"scripts": {
"build": "asc assemblyscript.ts --debug -b none -o assemblyscript.wasm"
"build": "asc index.ts --debug -b none -o index.wasm"
},
"devDependencies": {
"assemblyscript": "^0.20.6"
"assemblyscript": "^0.21.2"
}
}