Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves host function imports into their own directory (#784)
Our root directory is getting crowded and it is also difficult to organize the "host imports" concept due to this. This moves common and language-specific imports into their own directory. This will break go import signatures on the next release, but is more sustainable overall. Signed-off-by: Adrian Cole <adrian@tetrate.io>
- Loading branch information
1 parent
15a774e
commit 5bd521e
Showing
83 changed files
with
127 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed
BIN
+36.9 KB
examples/wasi/testdata/zig-cc/cat.wasm → ...preview1/example/testdata/zig-cc/cat.wasm
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.