diff --git a/assemblyscript/assemblyscript.go b/assemblyscript/assemblyscript.go index 18a8c4626d..c8b697540b 100644 --- a/assemblyscript/assemblyscript.go +++ b/assemblyscript/assemblyscript.go @@ -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 ( diff --git a/examples/assemblyscript/README.md b/examples/assemblyscript/README.md index ed0a07a679..6e12af2ab9 100644 --- a/examples/assemblyscript/README.md +++ b/examples/assemblyscript/README.md @@ -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 diff --git a/examples/assemblyscript/assemblyscript.go b/examples/assemblyscript/assemblyscript.go index f50f6a56e4..87dac7225d 100644 --- a/examples/assemblyscript/assemblyscript.go +++ b/examples/assemblyscript/assemblyscript.go @@ -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 diff --git a/examples/assemblyscript/assemblyscript_test.go b/examples/assemblyscript/assemblyscript_test.go index 3faf3d0b75..b8d729c4ce 100644 --- a/examples/assemblyscript/assemblyscript_test.go +++ b/examples/assemblyscript/assemblyscript_test.go @@ -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) } diff --git a/examples/assemblyscript/testdata/assemblyscript.wasm b/examples/assemblyscript/testdata/assemblyscript.wasm deleted file mode 100644 index 74cef8b237..0000000000 Binary files a/examples/assemblyscript/testdata/assemblyscript.wasm and /dev/null differ diff --git a/examples/assemblyscript/testdata/assemblyscript.ts b/examples/assemblyscript/testdata/index.ts similarity index 100% rename from examples/assemblyscript/testdata/assemblyscript.ts rename to examples/assemblyscript/testdata/index.ts diff --git a/examples/assemblyscript/testdata/index.wasm b/examples/assemblyscript/testdata/index.wasm new file mode 100644 index 0000000000..3910ceba7c Binary files /dev/null and b/examples/assemblyscript/testdata/index.wasm differ diff --git a/examples/assemblyscript/testdata/package.json b/examples/assemblyscript/testdata/package.json index 27a30a9369..0264eb3d44 100644 --- a/examples/assemblyscript/testdata/package.json +++ b/examples/assemblyscript/testdata/package.json @@ -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" } }