diff --git a/.github/workflows/examples.yaml b/.github/workflows/examples.yaml index 5098391314..ac25d3db17 100644 --- a/.github/workflows/examples.yaml +++ b/.github/workflows/examples.yaml @@ -5,12 +5,14 @@ on: paths: - '.github/workflows/examples.yaml' - 'examples/**' + - 'imports/**/example/**' - 'Makefile' push: branches: [main] paths: - '.github/workflows/examples.yaml' - 'examples/**' + - 'imports/**/example/**' - 'Makefile' env: @@ -103,5 +105,4 @@ jobs: run: make build.bench - name: Run example tests - # Also runs emscripten as its source is outside the examples directory. - run: go test ./examples/... ./emscripten/... + run: make test.examples diff --git a/Makefile b/Makefile index bb9524be86..acc3f40476 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ hugo := github.com/gohugoio/hugo@v0.101.0 all_sources := $(wildcard *.go */*.go */*/*.go */*/*/*.go */*/*/*.go */*/*/*/*.go) all_testdata := $(wildcard testdata/* */testdata/* */*/testdata/* */*/testdata/*/* */*/*/testdata/*) all_testing := $(wildcard internal/testing/* internal/testing/*/* internal/testing/*/*/*) -all_examples := $(wildcard examples/* examples/*/* examples/*/*/*) +all_examples := $(wildcard examples/* examples/*/* examples/*/*/* */*/example/* */*/example/*/* */*/example/*/*/*) all_it := $(wildcard internal/integration_test/* internal/integration_test/*/* internal/integration_test/*/*/*) # main_sources exclude any test or example related code main_sources := $(wildcard $(filter-out %_test.go $(all_testdata) $(all_testing) $(all_examples) $(all_it), $(all_sources))) @@ -42,27 +42,19 @@ bench_testdata_dir := internal/integration_test/bench/testdata build.bench: @tinygo build -o $(bench_testdata_dir)/case.wasm -scheduler=none --no-debug -target=wasi $(bench_testdata_dir)/case.go +.PHONY: test.examples +test.examples: + @go test ./examples/... ./imports/assemblyscript/example/... ./imports/go/example/... ./imports/wasi_snapshot_preview1/example/... + .PHONY: build.examples.as build.examples.as: - @cd ./examples/assemblyscript/testdata && npm install && npm run build + @cd ./imports/assemblyscript/example/testdata && npm install && npm run build .PHONY: build.examples.zig -build.examples.zig: examples/allocation/zig/testdata/greet.wasm - -%.wasm: %.zig - @(cd $(@D); zig build) - @mv $(@D)/zig-out/lib/$(@F) $(@D) - -go_sources := examples/wasm_exec/testdata/cat.go -.PHONY: build.examples.go -build.examples.go: $(go_sources) - @for f in $^; do \ - cd $$(dirname $$f); \ - GOARCH=wasm GOOS=js go build -o $$(basename $$f | sed -e 's/\.go/\.wasm/') .; \ - cd -; \ - done +build.examples.zig: + @cd examples/allocation/zig/testdata/ && zig build -Drelease-small=true && mv zig-out/lib/greet.wasm . -tinygo_sources := $(filter-out $(go_sources), $(wildcard examples/*/testdata/*.go examples/*/*/testdata/*.go examples/*/testdata/*/*.go)) +tinygo_sources := examples/allocation/tinygo/testdata/greet.go imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.go .PHONY: build.examples.tinygo build.examples.tinygo: $(tinygo_sources) @for f in $^; do \ @@ -70,11 +62,11 @@ build.examples.tinygo: $(tinygo_sources) done # We use zig to build C as it is easy to install and embeds a copy of zig-cc. -c_sources := $(wildcard examples/*/testdata/*.c examples/*/*/testdata/*.c examples/*/testdata/*/*.c) +c_sources := imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.c .PHONY: build.examples.zig-cc build.examples.zig-cc: $(c_sources) @for f in $^; do \ - zig cc --target=wasm32-wasi -O3 -o $$(echo $$f | sed -e 's/\.c/\.wasm/') $$f; \ + zig cc --target=wasm32-wasi -Oz -o $$(echo $$f | sed -e 's/\.c/\.wasm/') $$f; \ done # Here are the emcc args we use: @@ -90,7 +82,7 @@ build.examples.zig-cc: $(c_sources) # to one page (64KB). To do this, we have to reduce the stack size. # * `-s ALLOW_MEMORY_GROWTH` - allows "memory.grow" instructions to succeed, but # requires a function import "emscripten_notify_memory_growth". -emscripten_sources := $(wildcard emscripten/testdata/*.cc) +emscripten_sources := $(wildcard imports/emscripten/testdata/*.cc) .PHONY: build.examples.emscripten build.examples.emscripten: $(emscripten_sources) @for f in $^; do \ @@ -107,7 +99,7 @@ build.examples.emscripten: $(emscripten_sources) %/cat.wasm : cargo_target := wasm32-wasi .PHONY: build.examples.rust -build.examples.rust: examples/allocation/rust/testdata/greet.wasm examples/wasi/testdata/cargo-wasi/cat.wasm +build.examples.rust: examples/allocation/rust/testdata/greet.wasm imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.wasm # Builds rust using cargo normally, or cargo-wasi. %.wasm: %.rs diff --git a/README.md b/README.md index 3b7db38a67..013713abb2 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,9 @@ func main() { Notes: -* The Wasm binary is often called the "guest" in WebAssembly. * The embedding application is often called the "host" in WebAssembly. +* The Wasm binary is often called the "guest" in WebAssembly. Sometimes they + need [imports][imports] to implement features such as console output. * Many languages compile to (target) Wasm including AssemblyScript, C, C++, Rust, TinyGo and Zig! @@ -83,7 +84,8 @@ it has no scope to specify how system resources like files are accessed. Instead, WebAssembly defines "host functions" and the signatures they can use. In wazero, "host functions" are written in Go, and let you do anything including access files. The main constraint is that WebAssembly only allows -numeric types. +numeric types. wazero includes [imports][imports] for common languages and +compiler toolchains. For example, you can grant WebAssembly code access to your console by exporting a function written in Go. The below function can be imported into standard diff --git a/examples/README.md b/examples/README.md index 23ea5ed8af..9721b87c50 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,13 +2,21 @@ The following example projects can help you practice WebAssembly with wazero: -* [allocation](allocation) - how to pass strings in and out of WebAssembly functions defined in Rust or TinyGo. -* [assemblyscript](assemblyscript) - how to configure special imports needed by AssemblyScript when not using WASI. +* [allocation](allocation) - how to pass strings in and out of WebAssembly + functions defined in Rust or TinyGo. +* [assemblyscript](../imports/assemblyscript/example) - how to configure + special imports needed by AssemblyScript when not using WASI. * [basic](basic) - how to use both WebAssembly and Go-defined functions. -* [import-go](import-go) - how to define, import and call a Go-defined function from a WebAssembly-defined function. -* [multiple-results](multiple-results) - how to return more than one result from WebAssembly or Go-defined functions. -* [namespace](namespace) - how WebAssembly modules can import their own host module, such as "env". -* [replace-import](replace-import) - how to override a module name hard-coded in a WebAssembly module. -* [wasi](wasi) - how to use I/O in your WebAssembly modules using WASI (WebAssembly System Interface). +* [import-go](import-go) - how to define, import and call a Go-defined function + from a WebAssembly-defined function. +* [multiple-results](multiple-results) - how to return more than one result + from WebAssembly or Go-defined functions. +* [namespace](namespace) - how WebAssembly modules can import their own host + module, such as "env". +* [replace-import](replace-import) - how to override a module name hard-coded + in a WebAssembly module. +* [wasi](../imports/wasi_snapshot_preview1/example) - how to use I/O in your + WebAssembly modules using WASI (WebAssembly System Interface). -Please [open an issue](https://github.com/tetratelabs/wazero/issues/new) if you would like to see another example. +Please [open an issue](https://github.com/tetratelabs/wazero/issues/new) if you +would like to see another example. diff --git a/examples/allocation/tinygo/greet.go b/examples/allocation/tinygo/greet.go index d3829616b2..fcedabc281 100644 --- a/examples/allocation/tinygo/greet.go +++ b/examples/allocation/tinygo/greet.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" ) // greetWasm was compiled using `tinygo build -o greet.wasm -scheduler=none --no-debug -target=wasi greet.go` diff --git a/examples/allocation/zig/testdata/greet.wasm b/examples/allocation/zig/testdata/greet.wasm index 0f5ce48308..2e12633ac4 100755 Binary files a/examples/allocation/zig/testdata/greet.wasm and b/examples/allocation/zig/testdata/greet.wasm differ diff --git a/experimental/fs_example_test.go b/experimental/fs_example_test.go index d7d55b31cf..948b33b4b1 100644 --- a/experimental/fs_example_test.go +++ b/experimental/fs_example_test.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" ) // fsWasm was generated by the following: diff --git a/experimental/listener_example_test.go b/experimental/listener_example_test.go index 5f0b9aa1b0..12e0a03ced 100644 --- a/experimental/listener_example_test.go +++ b/experimental/listener_example_test.go @@ -10,7 +10,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" . "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" ) // listenerWasm was generated by the following: diff --git a/experimental/logging/log_listener_example_test.go b/experimental/logging/log_listener_example_test.go index 4462c98546..fdcd27ca97 100644 --- a/experimental/logging/log_listener_example_test.go +++ b/experimental/logging/log_listener_example_test.go @@ -9,7 +9,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" "github.com/tetratelabs/wazero/experimental/logging" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" ) // listenerWasm was generated by the following: diff --git a/experimental/logging/log_listener_test.go b/experimental/logging/log_listener_test.go index 531b756916..4db935879c 100644 --- a/experimental/logging/log_listener_test.go +++ b/experimental/logging/log_listener_test.go @@ -9,9 +9,9 @@ import ( "github.com/tetratelabs/wazero/api" "github.com/tetratelabs/wazero/experimental/logging" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/internal/testing/require" "github.com/tetratelabs/wazero/internal/wasm" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. diff --git a/imports/README.md b/imports/README.md new file mode 100644 index 0000000000..56cbdd747b --- /dev/null +++ b/imports/README.md @@ -0,0 +1,40 @@ +## wazero imports + +Packages in this directory implement the *host* imports needed for specific +languages or shared compiler toolchains. + +* [AssemblyScript](assemblyscript) Ex. `asc X.ts --debug -b none -o X.wasm` +* [Emscripten](emscripten) Ex. `em++ ... -s STANDALONE_WASM -o X.wasm X.cc` +* [Go](go) Ex. `GOARCH=wasm GOOS=js go build -o X.wasm X.go` +* [WASI](wasi_snapshot_preview1) Ex. `tinygo build -o X.wasm -target=wasi X.go` + +Note: You may not see a language listed here because it either works without +host imports, or it uses WASI. Refer to https://wazero.io/languages/ for more. + +Please [open an issue](https://github.com/tetratelabs/wazero/issues/new) if you +would like to see support for another compiled language or toolchain. + +## Overview + +WebAssembly has a virtual machine architecture where the *host* is the process +embedding wazero and the *guest* is a program compiled into the WebAssembly +Binary Format, also known as Wasm (`%.wasm`). + +The only features that work by default are computational in nature, and the +only way to communicate is via functions, memory or global variables. + +When a compiler targets Wasm, it often needs to import functions from the host +to satisfy system calls needed for functionality like printing to the console, +getting the time, or generating random values. The technical term for this +bridge is Application Binary Interface (ABI), but we'll call them simply host +imports. + +Packages in this directory are sometimes well re-used, such as the case in +[WASI](https://wazero.io/specs/#wasi). For example, Rust, TinyGo, and Zig can +all target WebAssembly in a way that imports the same "wasi_snapshot_preview1" +module in the compiled `%.wasm` file. To support any of these, wazero users can +invoke `wasi_snapshot_preview1.Instantiate` on their `wazero.Runtime`. + +Other times, host imports are either completely compiler-specific, such as the +case with `GOARCH=wasm GOOS=js`, or coexist alongside WASI, such as the case +with Emscripten. diff --git a/assemblyscript/assemblyscript.go b/imports/assemblyscript/assemblyscript.go similarity index 100% rename from assemblyscript/assemblyscript.go rename to imports/assemblyscript/assemblyscript.go diff --git a/assemblyscript/assemblyscript_example_test.go b/imports/assemblyscript/assemblyscript_example_test.go similarity index 95% rename from assemblyscript/assemblyscript_example_test.go rename to imports/assemblyscript/assemblyscript_example_test.go index 62f2c44a8d..0a7c695408 100644 --- a/assemblyscript/assemblyscript_example_test.go +++ b/imports/assemblyscript/assemblyscript_example_test.go @@ -6,7 +6,7 @@ import ( "log" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/assemblyscript" + "github.com/tetratelabs/wazero/imports/assemblyscript" ) // This shows how to instantiate AssemblyScript's special imports. diff --git a/assemblyscript/assemblyscript_test.go b/imports/assemblyscript/assemblyscript_test.go similarity index 100% rename from assemblyscript/assemblyscript_test.go rename to imports/assemblyscript/assemblyscript_test.go diff --git a/examples/assemblyscript/README.md b/imports/assemblyscript/example/README.md similarity index 100% rename from examples/assemblyscript/README.md rename to imports/assemblyscript/example/README.md diff --git a/examples/assemblyscript/assemblyscript.go b/imports/assemblyscript/example/assemblyscript.go similarity index 97% rename from examples/assemblyscript/assemblyscript.go rename to imports/assemblyscript/example/assemblyscript.go index 87dac7225d..ee27c04962 100644 --- a/examples/assemblyscript/assemblyscript.go +++ b/imports/assemblyscript/example/assemblyscript.go @@ -9,7 +9,7 @@ import ( "strconv" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/assemblyscript" + "github.com/tetratelabs/wazero/imports/assemblyscript" ) // asWasm compiled using `npm install && npm run build` diff --git a/examples/assemblyscript/assemblyscript_test.go b/imports/assemblyscript/example/assemblyscript_test.go similarity index 100% rename from examples/assemblyscript/assemblyscript_test.go rename to imports/assemblyscript/example/assemblyscript_test.go diff --git a/examples/assemblyscript/testdata/index.ts b/imports/assemblyscript/example/testdata/index.ts similarity index 100% rename from examples/assemblyscript/testdata/index.ts rename to imports/assemblyscript/example/testdata/index.ts diff --git a/examples/assemblyscript/testdata/index.wasm b/imports/assemblyscript/example/testdata/index.wasm similarity index 100% rename from examples/assemblyscript/testdata/index.wasm rename to imports/assemblyscript/example/testdata/index.wasm diff --git a/examples/assemblyscript/testdata/package.json b/imports/assemblyscript/example/testdata/package.json similarity index 100% rename from examples/assemblyscript/testdata/package.json rename to imports/assemblyscript/example/testdata/package.json diff --git a/emscripten/emscripten.go b/imports/emscripten/emscripten.go similarity index 100% rename from emscripten/emscripten.go rename to imports/emscripten/emscripten.go diff --git a/emscripten/emscripten_example_test.go b/imports/emscripten/emscripten_example_test.go similarity index 92% rename from emscripten/emscripten_example_test.go rename to imports/emscripten/emscripten_example_test.go index 8afe71efc5..0c52f2fac8 100644 --- a/emscripten/emscripten_example_test.go +++ b/imports/emscripten/emscripten_example_test.go @@ -6,8 +6,8 @@ import ( "log" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/emscripten" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" + "github.com/tetratelabs/wazero/imports/emscripten" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" ) // This shows how to instantiate Emscripten function imports. diff --git a/emscripten/emscripten_test.go b/imports/emscripten/emscripten_test.go similarity index 95% rename from emscripten/emscripten_test.go rename to imports/emscripten/emscripten_test.go index 6efaf4734d..efb65617e1 100644 --- a/emscripten/emscripten_test.go +++ b/imports/emscripten/emscripten_test.go @@ -9,9 +9,9 @@ import ( "github.com/tetratelabs/wazero" . "github.com/tetratelabs/wazero/experimental" "github.com/tetratelabs/wazero/experimental/logging" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/internal/testing/require" "github.com/tetratelabs/wazero/sys" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // growWasm was compiled from testdata/grow.cc diff --git a/emscripten/testdata/grow.cc b/imports/emscripten/testdata/grow.cc similarity index 100% rename from emscripten/testdata/grow.cc rename to imports/emscripten/testdata/grow.cc diff --git a/emscripten/testdata/grow.wasm b/imports/emscripten/testdata/grow.wasm similarity index 100% rename from emscripten/testdata/grow.wasm rename to imports/emscripten/testdata/grow.wasm diff --git a/imports/go/README.md b/imports/go/README.md new file mode 100644 index 0000000000..de025f9f4c --- /dev/null +++ b/imports/go/README.md @@ -0,0 +1,28 @@ +# Overview + +Wazero's "github.com/tetratelabs/wazero/imports/go" package allows you to run +a `%.wasm` file compiled by Go. See https://wazero.io/languages/go/ for more. + +## Usage + +When `GOOS=js` and `GOARCH=wasm`, Go's compiler targets WebAssembly 1.0 +Binary format (%.wasm). + +Ex. +```bash +GOOS=js GOARCH=wasm go build -o cat.wasm . +``` + +After compiling `cat.wasm` with wazero.Runtime's `CompileModule`, Run it. + +Under the scenes, the compiled Wasm calls host functions that support the +runtime.GOOS. This is similar to what is implemented in [wasm_exec.js][1]. + +## Experimental + +Go defines js "EXPERIMENTAL... exempt from the Go compatibility promise." +Accordingly, wazero cannot guarantee this will work from release to release, +or that usage will be relatively free of bugs. Due to this and the +relatively high implementation overhead, most will choose TinyGo instead. + +[1]: https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js diff --git a/examples/gojs/.gitignore b/imports/go/example/.gitignore similarity index 100% rename from examples/gojs/.gitignore rename to imports/go/example/.gitignore diff --git a/examples/gojs/README.md b/imports/go/example/README.md similarity index 100% rename from examples/gojs/README.md rename to imports/go/example/README.md diff --git a/examples/gojs/stars.go b/imports/go/example/stars.go similarity index 98% rename from examples/gojs/stars.go rename to imports/go/example/stars.go index bc83285441..561576f892 100644 --- a/examples/gojs/stars.go +++ b/imports/go/example/stars.go @@ -13,7 +13,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/experimental/gojs" + gojs "github.com/tetratelabs/wazero/imports/go" "github.com/tetratelabs/wazero/sys" ) diff --git a/examples/gojs/stars/go.mod b/imports/go/example/stars/go.mod similarity index 100% rename from examples/gojs/stars/go.mod rename to imports/go/example/stars/go.mod diff --git a/examples/gojs/stars/main.go b/imports/go/example/stars/main.go similarity index 100% rename from examples/gojs/stars/main.go rename to imports/go/example/stars/main.go diff --git a/examples/gojs/stars_test.go b/imports/go/example/stars_test.go similarity index 100% rename from examples/gojs/stars_test.go rename to imports/go/example/stars_test.go diff --git a/experimental/gojs/gojs.go b/imports/go/gojs.go similarity index 100% rename from experimental/gojs/gojs.go rename to imports/go/gojs.go diff --git a/wasi_snapshot_preview1/args.go b/imports/wasi_snapshot_preview1/args.go similarity index 100% rename from wasi_snapshot_preview1/args.go rename to imports/wasi_snapshot_preview1/args.go diff --git a/wasi_snapshot_preview1/args_test.go b/imports/wasi_snapshot_preview1/args_test.go similarity index 100% rename from wasi_snapshot_preview1/args_test.go rename to imports/wasi_snapshot_preview1/args_test.go diff --git a/wasi_snapshot_preview1/clock.go b/imports/wasi_snapshot_preview1/clock.go similarity index 100% rename from wasi_snapshot_preview1/clock.go rename to imports/wasi_snapshot_preview1/clock.go diff --git a/wasi_snapshot_preview1/clock_test.go b/imports/wasi_snapshot_preview1/clock_test.go similarity index 100% rename from wasi_snapshot_preview1/clock_test.go rename to imports/wasi_snapshot_preview1/clock_test.go diff --git a/wasi_snapshot_preview1/environ.go b/imports/wasi_snapshot_preview1/environ.go similarity index 100% rename from wasi_snapshot_preview1/environ.go rename to imports/wasi_snapshot_preview1/environ.go diff --git a/wasi_snapshot_preview1/environ_test.go b/imports/wasi_snapshot_preview1/environ_test.go similarity index 100% rename from wasi_snapshot_preview1/environ_test.go rename to imports/wasi_snapshot_preview1/environ_test.go diff --git a/wasi_snapshot_preview1/errno.go b/imports/wasi_snapshot_preview1/errno.go similarity index 100% rename from wasi_snapshot_preview1/errno.go rename to imports/wasi_snapshot_preview1/errno.go diff --git a/examples/wasi/README.md b/imports/wasi_snapshot_preview1/example/README.md similarity index 100% rename from examples/wasi/README.md rename to imports/wasi_snapshot_preview1/example/README.md diff --git a/examples/wasi/cat.go b/imports/wasi_snapshot_preview1/example/cat.go similarity index 97% rename from examples/wasi/cat.go rename to imports/wasi_snapshot_preview1/example/cat.go index d4ba95c597..bf8513fe7a 100644 --- a/examples/wasi/cat.go +++ b/imports/wasi_snapshot_preview1/example/cat.go @@ -9,8 +9,8 @@ import ( "os" "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/sys" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // catFS is an embedded filesystem limited to test.txt diff --git a/examples/wasi/cat_test.go b/imports/wasi_snapshot_preview1/example/cat_test.go similarity index 100% rename from examples/wasi/cat_test.go rename to imports/wasi_snapshot_preview1/example/cat_test.go diff --git a/examples/wasi/testdata/cargo-wasi/.gitignore b/imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/.gitignore similarity index 100% rename from examples/wasi/testdata/cargo-wasi/.gitignore rename to imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/.gitignore diff --git a/examples/wasi/testdata/cargo-wasi/Cargo.toml b/imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/Cargo.toml similarity index 100% rename from examples/wasi/testdata/cargo-wasi/Cargo.toml rename to imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/Cargo.toml diff --git a/examples/wasi/testdata/cargo-wasi/cat.rs b/imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.rs similarity index 100% rename from examples/wasi/testdata/cargo-wasi/cat.rs rename to imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.rs diff --git a/examples/wasi/testdata/cargo-wasi/cat.wasm b/imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.wasm similarity index 100% rename from examples/wasi/testdata/cargo-wasi/cat.wasm rename to imports/wasi_snapshot_preview1/example/testdata/cargo-wasi/cat.wasm diff --git a/examples/wasi/testdata/sub/test.txt b/imports/wasi_snapshot_preview1/example/testdata/sub/test.txt similarity index 100% rename from examples/wasi/testdata/sub/test.txt rename to imports/wasi_snapshot_preview1/example/testdata/sub/test.txt diff --git a/examples/wasi/testdata/test.txt b/imports/wasi_snapshot_preview1/example/testdata/test.txt similarity index 100% rename from examples/wasi/testdata/test.txt rename to imports/wasi_snapshot_preview1/example/testdata/test.txt diff --git a/examples/wasi/testdata/tinygo/cat.go b/imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.go similarity index 100% rename from examples/wasi/testdata/tinygo/cat.go rename to imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.go diff --git a/examples/wasi/testdata/tinygo/cat.wasm b/imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.wasm similarity index 100% rename from examples/wasi/testdata/tinygo/cat.wasm rename to imports/wasi_snapshot_preview1/example/testdata/tinygo/cat.wasm diff --git a/examples/wasi/testdata/zig-cc/cat.c b/imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.c similarity index 100% rename from examples/wasi/testdata/zig-cc/cat.c rename to imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.c diff --git a/examples/wasi/testdata/zig-cc/cat.wasm b/imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.wasm similarity index 61% rename from examples/wasi/testdata/zig-cc/cat.wasm rename to imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.wasm index 3bdbcd3bdc..b42eeeabae 100755 Binary files a/examples/wasi/testdata/zig-cc/cat.wasm and b/imports/wasi_snapshot_preview1/example/testdata/zig-cc/cat.wasm differ diff --git a/wasi_snapshot_preview1/example_test.go b/imports/wasi_snapshot_preview1/example_test.go similarity index 100% rename from wasi_snapshot_preview1/example_test.go rename to imports/wasi_snapshot_preview1/example_test.go diff --git a/wasi_snapshot_preview1/fs.go b/imports/wasi_snapshot_preview1/fs.go similarity index 100% rename from wasi_snapshot_preview1/fs.go rename to imports/wasi_snapshot_preview1/fs.go diff --git a/wasi_snapshot_preview1/fs_test.go b/imports/wasi_snapshot_preview1/fs_test.go similarity index 100% rename from wasi_snapshot_preview1/fs_test.go rename to imports/wasi_snapshot_preview1/fs_test.go diff --git a/wasi_snapshot_preview1/poll.go b/imports/wasi_snapshot_preview1/poll.go similarity index 100% rename from wasi_snapshot_preview1/poll.go rename to imports/wasi_snapshot_preview1/poll.go diff --git a/wasi_snapshot_preview1/poll_test.go b/imports/wasi_snapshot_preview1/poll_test.go similarity index 100% rename from wasi_snapshot_preview1/poll_test.go rename to imports/wasi_snapshot_preview1/poll_test.go diff --git a/wasi_snapshot_preview1/proc.go b/imports/wasi_snapshot_preview1/proc.go similarity index 100% rename from wasi_snapshot_preview1/proc.go rename to imports/wasi_snapshot_preview1/proc.go diff --git a/wasi_snapshot_preview1/proc_test.go b/imports/wasi_snapshot_preview1/proc_test.go similarity index 100% rename from wasi_snapshot_preview1/proc_test.go rename to imports/wasi_snapshot_preview1/proc_test.go diff --git a/wasi_snapshot_preview1/random.go b/imports/wasi_snapshot_preview1/random.go similarity index 100% rename from wasi_snapshot_preview1/random.go rename to imports/wasi_snapshot_preview1/random.go diff --git a/wasi_snapshot_preview1/random_test.go b/imports/wasi_snapshot_preview1/random_test.go similarity index 100% rename from wasi_snapshot_preview1/random_test.go rename to imports/wasi_snapshot_preview1/random_test.go diff --git a/wasi_snapshot_preview1/sched.go b/imports/wasi_snapshot_preview1/sched.go similarity index 100% rename from wasi_snapshot_preview1/sched.go rename to imports/wasi_snapshot_preview1/sched.go diff --git a/wasi_snapshot_preview1/sched_test.go b/imports/wasi_snapshot_preview1/sched_test.go similarity index 100% rename from wasi_snapshot_preview1/sched_test.go rename to imports/wasi_snapshot_preview1/sched_test.go diff --git a/wasi_snapshot_preview1/sock.go b/imports/wasi_snapshot_preview1/sock.go similarity index 100% rename from wasi_snapshot_preview1/sock.go rename to imports/wasi_snapshot_preview1/sock.go diff --git a/wasi_snapshot_preview1/sock_test.go b/imports/wasi_snapshot_preview1/sock_test.go similarity index 100% rename from wasi_snapshot_preview1/sock_test.go rename to imports/wasi_snapshot_preview1/sock_test.go diff --git a/wasi_snapshot_preview1/testdata/exit_on_start.wasm b/imports/wasi_snapshot_preview1/testdata/exit_on_start.wasm similarity index 100% rename from wasi_snapshot_preview1/testdata/exit_on_start.wasm rename to imports/wasi_snapshot_preview1/testdata/exit_on_start.wasm diff --git a/wasi_snapshot_preview1/testdata/exit_on_start.wat b/imports/wasi_snapshot_preview1/testdata/exit_on_start.wat similarity index 100% rename from wasi_snapshot_preview1/testdata/exit_on_start.wat rename to imports/wasi_snapshot_preview1/testdata/exit_on_start.wat diff --git a/wasi_snapshot_preview1/testdata/wasi_arg.wasm b/imports/wasi_snapshot_preview1/testdata/wasi_arg.wasm similarity index 100% rename from wasi_snapshot_preview1/testdata/wasi_arg.wasm rename to imports/wasi_snapshot_preview1/testdata/wasi_arg.wasm diff --git a/wasi_snapshot_preview1/testdata/wasi_arg.wat b/imports/wasi_snapshot_preview1/testdata/wasi_arg.wat similarity index 100% rename from wasi_snapshot_preview1/testdata/wasi_arg.wat rename to imports/wasi_snapshot_preview1/testdata/wasi_arg.wat diff --git a/wasi_snapshot_preview1/usage_test.go b/imports/wasi_snapshot_preview1/usage_test.go similarity index 100% rename from wasi_snapshot_preview1/usage_test.go rename to imports/wasi_snapshot_preview1/usage_test.go diff --git a/wasi_snapshot_preview1/wasi.go b/imports/wasi_snapshot_preview1/wasi.go similarity index 100% rename from wasi_snapshot_preview1/wasi.go rename to imports/wasi_snapshot_preview1/wasi.go diff --git a/wasi_snapshot_preview1/wasi_bench_test.go b/imports/wasi_snapshot_preview1/wasi_bench_test.go similarity index 100% rename from wasi_snapshot_preview1/wasi_bench_test.go rename to imports/wasi_snapshot_preview1/wasi_bench_test.go diff --git a/wasi_snapshot_preview1/wasi_test.go b/imports/wasi_snapshot_preview1/wasi_test.go similarity index 100% rename from wasi_snapshot_preview1/wasi_test.go rename to imports/wasi_snapshot_preview1/wasi_test.go diff --git a/internal/gojs/compiler_test.go b/internal/gojs/compiler_test.go index 69a58ba2f5..6858fcf193 100644 --- a/internal/gojs/compiler_test.go +++ b/internal/gojs/compiler_test.go @@ -18,7 +18,7 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/experimental" - "github.com/tetratelabs/wazero/experimental/gojs" + gojs "github.com/tetratelabs/wazero/imports/go" ) func compileAndRun(ctx context.Context, arg string, config wazero.ModuleConfig) (stdout, stderr string, err error) { diff --git a/internal/gojs/http_test.go b/internal/gojs/http_test.go index 86bd29991a..178eb451bf 100644 --- a/internal/gojs/http_test.go +++ b/internal/gojs/http_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/experimental/gojs" + gojs "github.com/tetratelabs/wazero/imports/go" "github.com/tetratelabs/wazero/internal/testing/require" ) diff --git a/internal/integration_test/bench/bench_test.go b/internal/integration_test/bench/bench_test.go index 9a7c29e120..f08cc8e48e 100644 --- a/internal/integration_test/bench/bench_test.go +++ b/internal/integration_test/bench/bench_test.go @@ -11,8 +11,8 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" "github.com/tetratelabs/wazero/experimental" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/internal/platform" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. diff --git a/internal/integration_test/bench/codec_test.go b/internal/integration_test/bench/codec_test.go index 656d29a55c..a186b52c3f 100644 --- a/internal/integration_test/bench/codec_test.go +++ b/internal/integration_test/bench/codec_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/internal/testing/require" "github.com/tetratelabs/wazero/internal/wasm" "github.com/tetratelabs/wazero/internal/wasm/binary" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) // example holds the latest supported features as described in the comments of exampleText diff --git a/internal/integration_test/fs/fs_test.go b/internal/integration_test/fs/fs_test.go index 18d6b205cc..ca0a349efb 100644 --- a/internal/integration_test/fs/fs_test.go +++ b/internal/integration_test/fs/fs_test.go @@ -12,8 +12,8 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/internal/testing/require" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) var testCtx = context.Background() diff --git a/internal/integration_test/vs/runtime.go b/internal/integration_test/vs/runtime.go index c200c75f7e..c18f8fbddd 100644 --- a/internal/integration_test/vs/runtime.go +++ b/internal/integration_test/vs/runtime.go @@ -7,8 +7,8 @@ import ( "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" "github.com/tetratelabs/wazero/internal/wasm" - "github.com/tetratelabs/wazero/wasi_snapshot_preview1" ) type RuntimeConfig struct { diff --git a/site/content/languages/go.md b/site/content/languages/go.md index a10688a1fb..505d96e5a5 100644 --- a/site/content/languages/go.md +++ b/site/content/languages/go.md @@ -242,4 +242,4 @@ the Go stack. [11]: https://github.com/WebAssembly/proposals [12]: https://github.com/golang/go/blob/go1.19/src/cmd/link/internal/ld/data.go#L2457 [13]: https://github.com/golang/go/blob/go1.19/src/syscall/tables_js.go#L371-L494 -[14]: https://github.com/tetratelabs/wazero/tree/main/examples/gojs +[14]: https://github.com/tetratelabs/wazero/tree/main/imports/go/example diff --git a/site/content/languages/rust.md b/site/content/languages/rust.md index 79d779a6f6..2bafcb2642 100644 --- a/site/content/languages/rust.md +++ b/site/content/languages/rust.md @@ -222,8 +222,8 @@ source code may reduce binary size further. [7]: https://github.com/tetratelabs/wazero/stargazers [8]: https://rustwasm.github.io/docs/book/reference/which-crates-work-with-wasm.html [9]: https://github.com/tetratelabs/wazero/tree/main/examples/allocation/rust -[10]: https://github.com/tetratelabs/wazero/tree/main/examples/wasi -[11]: https://github.com/tetratelabs/wazero/tree/main/examples/wasi/testdata/cargo-wasi +[10]: https://github.com/tetratelabs/wazero/tree/main/imports/wasi_snapshot_preview1/example +[11]: https://github.com/tetratelabs/wazero/tree/main/imports/wasi_snapshot_preview1/example/testdata/cargo-wasi [12]: https://github.com/rustwasm/wee_alloc [13]: https://doc.rust-lang.org/cargo/reference/profiles.html#profile-settings [14]: https://github.com/bytecodealliance/cargo-wasi diff --git a/site/content/languages/tinygo.md b/site/content/languages/tinygo.md index 458df810ba..b65ee9101b 100644 --- a/site/content/languages/tinygo.md +++ b/site/content/languages/tinygo.md @@ -378,8 +378,8 @@ functions, such as `fmt.Println`, which can require 100KB of wasm. [18]: https://github.com/tinygo-org/tinygo/issues/447 [19]: https://github.com/tinygo-org/tinygo/issues/3068 [20]: https://github.com/tinygo-org/tinygo/blob/v0.25.0/src/runtime/arch_tinygowasm.go#L47-L62 -[21]: https://github.com/tetratelabs/wazero/tree/main/examples/wasi -[22]: https://github.com/tetratelabs/wazero/tree/main/examples/wasi/testdata/tinygo +[21]: https://github.com/tetratelabs/wazero/tree/main/imports/wasi_snapshot_preview1/example +[22]: https://github.com/tetratelabs/wazero/tree/main/imports/wasi_snapshot_preview1/example/testdata/tinygo [23]: https://github.com/WebAssembly/binaryen/blob/main/src/passes/Asyncify.cpp [24]: http://tleyden.github.io/blog/2014/10/30/goroutines-vs-threads/ [25]: https://github.com/tinygo-org/tinygo/issues/3095