Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Fix amd64 notify and rename module to wasilibs/wazerox (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Nov 17, 2023
1 parent f3b18e0 commit c68710e
Show file tree
Hide file tree
Showing 511 changed files with 1,530 additions and 1,620 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ main_packages := $(sort $(foreach f,$(dir $(main_sources)),$(if $(findstring ./,

go_test_options ?= -timeout 300s

ensureCompilerFastest := -ldflags '-X github.com/tetratelabs/wazero/internal/integration_test/vs.ensureCompilerFastest=true'
ensureCompilerFastest := -ldflags '-X github.com/wasilibs/wazerox/internal/integration_test/vs.ensureCompilerFastest=true'
.PHONY: bench
bench:
@go test -run=NONE -benchmem -bench=. ./internal/engine/compiler/...
Expand Down Expand Up @@ -320,7 +320,7 @@ define go-build
@echo "building $1"
@# $(go:go=) removes the trailing 'go', so we can insert cross-build variables
@$(go:go=) CGO_ENABLED=0 GOOS=$(call go-os,$1) GOARCH=$(call go-arch,$1) go build \
-ldflags "-s -w -X github.com/tetratelabs/wazero/internal/version.version=$(VERSION)" \
-ldflags "-s -w -X github.com/wasilibs/wazerox/internal/version.version=$(VERSION)" \
-o $1 $2 ./cmd/wazero
@echo build "ok"
endef
Expand Down
140 changes: 24 additions & 116 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,29 @@
This repository contains experimental changes to try with wasilibs code.
Do not use it outside the wasilibs organization.
# wazerox: wazero extended with bleeding-edge features and likely bugs

# wazero: the zero dependency WebAssembly runtime for Go developers
[![WebAssembly Core Specification Test](https://github.com/wasilibs/wazerox/actions/workflows/spectest.yaml/badge.svg)](https://github.com/wasilibs/wazerox/actions/workflows/spectest.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/wasilibs/wazerox.svg)](https://pkg.go.dev/github.com/wasilibs/wazerox) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

[![WebAssembly Core Specification Test](https://github.com/tetratelabs/wazero/actions/workflows/spectest.yaml/badge.svg)](https://github.com/tetratelabs/wazero/actions/workflows/spectest.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/tetratelabs/wazero.svg)](https://pkg.go.dev/github.com/tetratelabs/wazero) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[wazero][18] is a wonderful WebAssembly runtime for Go developers with a priority
on stability. This often means it can take time to add new incubating WebAssembly
features or completely non-standard ones - there is only so much a project can
take on.

WebAssembly is a way to safely run code compiled in other languages. Runtimes
execute WebAssembly Modules (Wasm), which are most often binaries with a `.wasm`
extension.
wazerox is a fork with a priority on running code for the wasilibs organization.
The reality is much existing code out there requires features that are not
supported by current WebAssembly or WASI specifications. wazerox allows wasilibs
to continue to provide wrappers with zero usage of cgo.

wazero is a WebAssembly Core Specification [1.0][1] and [2.0][2] compliant
runtime written in Go. It has *zero dependencies*, and doesn't rely on CGO.
This means you can run applications in other languages and still keep cross
compilation.
The additions to wazero should be considered mostly be an implementation detail
of wasilibs libraries. If you have code that requires these extensions to execute,
it is OK to try wazerox, but do expect bugs and best-effort or non-existing support.
It is never a good idea to try this library before trying wazero and see if it
supports your binary, if it does, use wazero.

Import wazero and extend your Go application with code written in any language!
Current extensions include:

## Example
- [WebAssembly Threads][19]
- Stack checkpoint/restore for [wasix][20] exception handling

The best way to learn wazero is by trying one of our [examples](examples/README.md). The
most [basic example](examples/basic) extends a Go application with an addition
function defined in WebAssembly.

## Runtime

There are two runtime configurations supported in wazero: _Compiler_ is default:

By default, ex `wazero.NewRuntime(ctx)`, the Compiler is used if supported. You
can also force the interpreter like so:
```go
r := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
```

### Interpreter
Interpreter is a naive interpreter-based implementation of Wasm virtual
machine. Its implementation doesn't have any platform (GOARCH, GOOS) specific
code, therefore _interpreter_ can be used for any compilation target available
for Go (such as `riscv64`).

### Compiler
Compiler compiles WebAssembly modules into machine code ahead of time (AOT),
during `Runtime.CompileModule`. This means your WebAssembly functions execute
natively at runtime. Compiler is faster than Interpreter, often by order of
magnitude (10x) or more. This is done without host-specific dependencies.

If interested, check out the [RATIONALE.md][8] and help us optimize further!

### Conformance

Both runtimes pass WebAssembly Core [1.0][7] and [2.0][14] specification tests
on supported platforms:

| Runtime | Usage | amd64 | arm64 | others |
|:-----------:|:--------------------------------------:|:-----:|:-----:|:------:|
| Interpreter | `wazero.NewRuntimeConfigInterpreter()` ||||
| Compiler | `wazero.NewRuntimeConfigCompiler()` ||||

## Support Policy

The below support policy focuses on compatability concerns of those embedding
wazero into their Go applications.

### wazero

wazero's [1.0 release][15] happened in March 2023, and is [in use][16] by many
projects and production sites.

We offer an API stability promise with semantic versioning. In other words, we
promise to not break any exported function signature without incrementing the
major version. This does not mean no innovation: New features and behaviors
happen with a minor version increment, e.g. 1.0.11 to 1.2.0. We also fix bugs
or change internal details with a patch version, e.g. 1.0.0 to 1.0.1.

You can get the latest version of wazero like this.
```bash
go get github.com/tetratelabs/wazero@latest
```

Please give us a [star][17] if you end up using wazero!

### Go

wazero has no dependencies except Go, so the only source of conflict in your
project's use of wazero is the Go version.

wazero follows the same version policy as Go's [Release Policy][10]: two
versions. wazero will ensure these versions work and bugs are valid if there's
an issue with a current Go version.

Additionally, wazero intentionally delays usage of language or standard library
features one additional version. For example, when Go 1.29 is released, wazero
can use language features or standard libraries added in 1.27. This is a
convenience for embedders who have a slower version policy than Go. However,
only supported Go versions may be used to raise support issues.

### Platform

wazero has two runtime modes: Interpreter and Compiler. The only supported operating
systems are ones we test, but that doesn't necessarily mean other operating
system versions won't work.

We currently test Linux (Ubuntu and scratch), MacOS and Windows as packaged by
[GitHub Actions][11], as well compilation of 32-bit Linux and 64-bit FreeBSD.

* Interpreter
* Linux is tested on amd64 (native) as well arm64 and riscv64 via emulation.
* MacOS and Windows are only tested on amd64.
* Compiler
* Linux is tested on amd64 (native) as well arm64 via emulation.
* MacOS and Windows are only tested on amd64.

wazero has no dependencies and doesn't require CGO. This means it can also be
embedded in an application that doesn't use an operating system. This is a main
differentiator between wazero and alternatives.

We verify zero dependencies by running tests in Docker's [scratch image][12].
This approach ensures compatibility with any parent image.

-----
wazero is a registered trademark of Tetrate.io, Inc. in the United States and/or other countries
For further details on the runtime, read about [wazero][18].

[1]: https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/
[2]: https://www.w3.org/TR/2022/WD-wasm-core-2-20220419/
Expand All @@ -127,12 +32,15 @@ wazero is a registered trademark of Tetrate.io, Inc. in the United States and/or
[6]: https://pkg.go.dev/golang.org/x/sys/unix
[7]: https://github.com/WebAssembly/spec/tree/wg-1.0/test/core
[8]: internal/engine/compiler/RATIONALE.md
[9]: https://github.com/tetratelabs/wazero/issues/506
[9]: https://github.com/wasilibs/wazerox/issues/506
[10]: https://go.dev/doc/devel/release
[11]: https://github.com/actions/virtual-environments
[12]: https://docs.docker.com/develop/develop-images/baseimages/#create-a-simple-parent-image-using-scratch
[13]: https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md
[14]: https://github.com/WebAssembly/spec/tree/d39195773112a22b245ffbe864bab6d1182ccb06/test/core
[15]: https://tetrate.io/blog/introducing-wazero-from-tetrate/
[16]: https://wazero.io/community/users/
[17]: https://github.com/tetratelabs/wazero/stargazers
[17]: https://github.com/wasilibs/wazerox/stargazers
[18]: https://github.com/testratelabs/wazero
[19]: https://github.com/WebAssembly/threads
[20]: https://wasix.org/
2 changes: 1 addition & 1 deletion api/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"testing"

"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/wasilibs/wazerox/internal/testing/require"
)

// TestCoreFeatures_ZeroIsInvalid reminds maintainers that a bitset cannot use zero as a flag!
Expand Down
2 changes: 1 addition & 1 deletion api/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"math"

"github.com/tetratelabs/wazero/internal/internalapi"
"github.com/wasilibs/wazerox/internal/internalapi"
)

// ExternType classifies imports and exports with their respective types.
Expand Down
2 changes: 1 addition & 1 deletion api/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"unsafe"

"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/wasilibs/wazerox/internal/testing/require"
)

func TestExternTypeName(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package wazero
import (
"context"

"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/wasilibs/wazerox/api"
"github.com/wasilibs/wazerox/internal/wasm"
)

// HostFunctionBuilder defines a host function (in Go), so that a
Expand Down
6 changes: 3 additions & 3 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"testing"

"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/wasilibs/wazerox/api"
"github.com/wasilibs/wazerox/internal/testing/require"
"github.com/wasilibs/wazerox/internal/wasm"
)

// TestNewHostModuleBuilder_Compile only covers a few scenarios to avoid duplicating tests in internal/wasm/host_test.go
Expand Down
8 changes: 4 additions & 4 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
goruntime "runtime"
"sync"

"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/filecache"
"github.com/tetratelabs/wazero/internal/version"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/wasilibs/wazerox/api"
"github.com/wasilibs/wazerox/internal/filecache"
"github.com/wasilibs/wazerox/internal/version"
"github.com/wasilibs/wazerox/internal/wasm"
)

// CompilationCache reduces time spent compiling (Runtime.CompileModule) the same wasm module.
Expand Down
2 changes: 1 addition & 1 deletion cache_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"os"

"github.com/tetratelabs/wazero"
wazero "github.com/wasilibs/wazerox"
)

// This is a basic example of using the file system compilation cache via wazero.NewCompilationCacheWithDir.
Expand Down
6 changes: 3 additions & 3 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
goruntime "runtime"
"testing"

"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/wasilibs/wazerox/internal/platform"
"github.com/wasilibs/wazerox/internal/testing/require"
"github.com/wasilibs/wazerox/internal/wasm"
)

//go:embed internal/integration_test/vs/testdata/fac.wasm
Expand Down
2 changes: 1 addition & 1 deletion cmd/wazero/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apk add --no-cache git
WORKDIR /build

# wazero doesn't publish a Docker image or binary, yet, so build on on demand.
RUN git clone --depth 1 https://github.com/tetratelabs/wazero.git \
RUN git clone --depth 1 https://github.com/wasilibs/wazerox.git \
&& (cd wazero; go build -o wazero -ldflags "-w -s" ./cmd/wazero)

# wazero has no dependencies, so it can run on scratch
Expand Down
24 changes: 12 additions & 12 deletions cmd/wazero/wazero.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import (
"strings"
"time"

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/experimental/gojs"
"github.com/tetratelabs/wazero/experimental/logging"
"github.com/tetratelabs/wazero/experimental/sock"
"github.com/tetratelabs/wazero/experimental/sysfs"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/platform"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/version"
"github.com/tetratelabs/wazero/sys"
wazero "github.com/wasilibs/wazerox"
"github.com/wasilibs/wazerox/api"
"github.com/wasilibs/wazerox/experimental"
"github.com/wasilibs/wazerox/experimental/gojs"
"github.com/wasilibs/wazerox/experimental/logging"
"github.com/wasilibs/wazerox/experimental/sock"
"github.com/wasilibs/wazerox/experimental/sysfs"
"github.com/wasilibs/wazerox/imports/wasi_snapshot_preview1"
"github.com/wasilibs/wazerox/internal/platform"
internalsys "github.com/wasilibs/wazerox/internal/sys"
"github.com/wasilibs/wazerox/internal/version"
"github.com/wasilibs/wazerox/sys"
)

func main() {
Expand Down
16 changes: 8 additions & 8 deletions cmd/wazero/wazero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"strings"
"testing"

"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental/logging"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/internalapi"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/internal/version"
"github.com/tetratelabs/wazero/sys"
"github.com/wasilibs/wazerox/api"
"github.com/wasilibs/wazerox/experimental/logging"
"github.com/wasilibs/wazerox/imports/wasi_snapshot_preview1"
"github.com/wasilibs/wazerox/internal/internalapi"
"github.com/wasilibs/wazerox/internal/platform"
"github.com/wasilibs/wazerox/internal/testing/require"
"github.com/wasilibs/wazerox/internal/version"
"github.com/wasilibs/wazerox/sys"
)

//go:embed testdata/infinite_loop.wasm
Expand Down
22 changes: 11 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
"net"
"time"

"github.com/tetratelabs/wazero/api"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/engine/compiler"
"github.com/tetratelabs/wazero/internal/engine/interpreter"
"github.com/tetratelabs/wazero/internal/filecache"
"github.com/tetratelabs/wazero/internal/internalapi"
"github.com/tetratelabs/wazero/internal/platform"
internalsock "github.com/tetratelabs/wazero/internal/sock"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/tetratelabs/wazero/sys"
"github.com/wasilibs/wazerox/api"
experimentalsys "github.com/wasilibs/wazerox/experimental/sys"
"github.com/wasilibs/wazerox/internal/engine/compiler"
"github.com/wasilibs/wazerox/internal/engine/interpreter"
"github.com/wasilibs/wazerox/internal/filecache"
"github.com/wasilibs/wazerox/internal/internalapi"
"github.com/wasilibs/wazerox/internal/platform"
internalsock "github.com/wasilibs/wazerox/internal/sock"
internalsys "github.com/wasilibs/wazerox/internal/sys"
"github.com/wasilibs/wazerox/internal/wasm"
"github.com/wasilibs/wazerox/sys"
)

// RuntimeConfig controls runtime behavior, with the default implementation as
Expand Down
4 changes: 2 additions & 2 deletions config_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
_ "embed"
"log"

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
wazero "github.com/wasilibs/wazerox"
"github.com/wasilibs/wazerox/api"
)

// This is a basic example of retrieving custom sections using RuntimeConfig.WithCustomSections.
Expand Down
20 changes: 10 additions & 10 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"testing"
"time"

"github.com/tetratelabs/wazero/api"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/fstest"
"github.com/tetratelabs/wazero/internal/platform"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/sysfs"
testfs "github.com/tetratelabs/wazero/internal/testing/fs"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/tetratelabs/wazero/sys"
"github.com/wasilibs/wazerox/api"
experimentalsys "github.com/wasilibs/wazerox/experimental/sys"
"github.com/wasilibs/wazerox/internal/fstest"
"github.com/wasilibs/wazerox/internal/platform"
internalsys "github.com/wasilibs/wazerox/internal/sys"
"github.com/wasilibs/wazerox/internal/sysfs"
testfs "github.com/wasilibs/wazerox/internal/testing/fs"
"github.com/wasilibs/wazerox/internal/testing/require"
"github.com/wasilibs/wazerox/internal/wasm"
"github.com/wasilibs/wazerox/sys"
)

func TestRuntimeConfig(t *testing.T) {
Expand Down
Loading

0 comments on commit c68710e

Please sign in to comment.