Skip to content

Commit

Permalink
Updates to AssemblyScript 0.21 which no longer includes WASI (#776)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
codefromthecrypt authored Aug 29, 2022
1 parent 17b8591 commit f2b141e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 11 deletions.
13 changes: 7 additions & 6 deletions assemblyscript/assemblyscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 9 additions & 1 deletion examples/assemblyscript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/assemblyscript/assemblyscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/assemblyscript/assemblyscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 removed examples/assemblyscript/testdata/assemblyscript.wasm
Binary file not shown.
File renamed without changes.
Binary file added examples/assemblyscript/testdata/index.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/assemblyscript/testdata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit f2b141e

Please sign in to comment.