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

Commit

Permalink
Update to latest wazero (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored Nov 17, 2023
2 parents 7c24835 + 376bb4d commit f3b18e0
Show file tree
Hide file tree
Showing 401 changed files with 33,177 additions and 10,669 deletions.
5 changes: 1 addition & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

/internal/asm/ @mathetake
/internal/engine/compiler/ @mathetake

* @codefromthecrypt @mathetake
* @codefromthecrypt @mathetake @evacchi
4 changes: 2 additions & 2 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ jobs:
~/go/bin
key: check-${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum', 'Makefile') }}

- run: make check

- run: make build.spectest

- run: make check

test_amd64:
name: amd64, ${{ matrix.os }}, Go-${{ matrix.go-version }}
runs-on: ${{ matrix.os }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ on:

env:
EMSDK_VERSION: "3.1.40"
TINYGO_VERSION: "0.28.1"
ZIG_VERSION: "0.11.0-dev.3334+cd1417dbd"
TINYGO_VERSION: "0.30.0"
ZIG_VERSION: "0.11.0"

concurrency:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-to-cancel-any-in-progress-job-or-run
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Install Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
sudo sh -c 'wget -c https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: Cache Emscripten
id: cache-emsdk
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ defaults:

env: # Update this prior to requiring a higher minor version in go.mod
GO_VERSION: "1.21" # 1.xx == latest patch of 1.xx
TINYGO_VERSION: "0.28.1"
ZIG_VERSION: "0.11.0-dev.3334+cd1417dbd"
TINYGO_VERSION: "0.30.0"
ZIG_VERSION: "0.11.0"

concurrency:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-to-cancel-any-in-progress-job-or-run
Expand All @@ -46,21 +46,21 @@ jobs:
with:
# Use share the cache containing archives across OSes.
enableCrossOsArchive: true
key: zig-test-binary-${{ env.ZIG_VERSION }}
key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }}
path:
./zigbin/

- name: Install Zig build
if: steps.binary-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.ZIG_INSTALL }}
curl -sSL https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz | tar -xJ --strip-components=1 -C ${{ env.ZIG_INSTALL }}
curl -sSL https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz | tar -xJ --strip-components=1 -C ${{ env.ZIG_INSTALL }}
- name: Download Zig source code
if: steps.binary-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.ZIG_SOURCE }}
curl -sSL https://ziglang.org/builds/zig-${{ env.ZIG_VERSION }}.tar.xz | tar -xJ --strip-components=1 -C ${{ env.ZIG_SOURCE }}
curl -sSL https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-${{ env.ZIG_VERSION }}.tar.xz | tar -xJ --strip-components=1 -C ${{ env.ZIG_SOURCE }}
- name: Build Stdlib test binary
if: steps.binary-cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
enableCrossOsArchive: true
# We need this cache to run tests.
fail-on-cache-miss: true
key: zig-test-binary-${{ env.ZIG_VERSION }}
key: zig-stdlib-test-binary-${{ env.ZIG_VERSION }}
path:
./zigbin/

Expand Down Expand Up @@ -335,7 +335,8 @@ jobs:
- "1.21" # Current Go version && The only version that supports wasip1.

steps:
- uses: actions/setup-go@v4
- id: setup-go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

Expand All @@ -344,7 +345,8 @@ jobs:
uses: actions/cache@v3
with:
path: ~/tests
key: go-wasip1-binaries-${{ matrix.os }}-${{ matrix.go-version }}
# Use precise Go version from setup-go as patch version differences can effect tests.
key: go-wasip1-binaries-${{ matrix.os }}-${{ steps.setup-go.outputs.go-version }}

- if: ${{ steps.cache-go-test-binaries.outputs.cache-hit != 'true' }}
name: Build Test Binaries
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/spectest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
spec-version:
- "v1"
- "v2"
- "threads"

steps:
- uses: actions/checkout@v3
Expand All @@ -60,6 +61,7 @@ jobs:
spec-version:
- "v1"
- "v2"
- "threads"

steps:
- uses: actions/checkout@v3
Expand Down
34 changes: 28 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ spectest_v1_testdata_dir := $(spectest_v1_dir)/testdata
spec_version_v1 := wg-1.0
spectest_v2_dir := $(spectest_base_dir)/v2
spectest_v2_testdata_dir := $(spectest_v2_dir)/testdata
# Latest draft state as of May 23, 2023.
spec_version_v2 := 2e8912e88a3118a46b90e8ccb659e24b4e8f3c23
# Latest draft state as of Dec 16, 2022.
spec_version_v2 := 1782235239ddebaf2cb079b00fdaa2d2c4dedba3
spectest_threads_dir := $(spectest_base_dir)/threads
spectest_threads_testdata_dir := $(spectest_threads_dir)/testdata
spec_version_threads := cc01bf0d17ba3fb1dc59fb7c5c725838aff18b50

.PHONY: build.spectest
build.spectest:
@$(MAKE) build.spectest.v1
@$(MAKE) build.spectest.v2
@$(MAKE) build.spectest.threads

.PHONY: build.spectest.v1
build.spectest.v1: # Note: wabt by default uses >1.0 features, so wast2json flags might drift as they include more. See WebAssembly/wabt#1878
Expand Down Expand Up @@ -165,9 +169,21 @@ build.spectest.v2: # Note: SIMD cases are placed in the "simd" subdirectory.
wast2json --debug-names --no-check $$f; \
done

.PHONY: build.spectest.threads
build.spectest.threads:
@mkdir -p $(spectest_threads_testdata_dir)
@cd $(spectest_threads_testdata_dir) \
&& curl -sSL 'https://api.github.com/repos/WebAssembly/threads/contents/test/core?ref=$(spec_version_threads)' | jq -r '.[]| .download_url' | grep -E "atomic.wast" | xargs -Iurl curl -sJL url -O
# Fix broken CAS spectests
# https://github.com/WebAssembly/threads/issues/195#issuecomment-1318429506
@cd $(spectest_threads_testdata_dir) && patch < ../atomic.wast.patch
@cd $(spectest_threads_testdata_dir) && for f in `find . -name '*.wast'`; do \
wast2json --enable-threads --debug-names $$f; \
done

.PHONY: test
test:
@go test $(go_test_options) $$(go list ./... | grep -vE '$(spectest_v1_dir)|$(spectest_v2_dir)')
@go test $(go_test_options) $$(go list ./... | grep -vE '$(spectest_v1_dir)|$(spectest_v2_dir)|$(spectest_threads_dir)')
@cd internal/version/testdata && go test $(go_test_options) ./...

.PHONY: coverage
Expand All @@ -181,13 +197,17 @@ coverage: ## Generate test coverage
spectest:
@$(MAKE) spectest.v1
@$(MAKE) spectest.v2
@$(MAKE) spectest.threads

spectest.v1:
@go test $(go_test_options) $$(go list ./... | grep $(spectest_v1_dir))

spectest.v2:
@go test $(go_test_options) $$(go list ./... | grep $(spectest_v2_dir))

spectest.threads:
@go test $(go_test_options) $$(go list ./... | grep $(spectest_threads_dir))

golangci_lint_path := $(shell go env GOPATH)/bin/golangci-lint

$(golangci_lint_path):
Expand Down Expand Up @@ -218,6 +238,8 @@ check:
@GOARCH=wasm GOOS=js go build ./...
# Ensure we build on gojs. See #1526.
@GOARCH=wasm GOOS=wasip1 go build ./...
# Ensure we build on aix. See #1723
@GOARCH=ppc64 GOOS=aix go build ./...
# Ensure we build on windows:
@GOARCH=amd64 GOOS=windows go build ./...
# Ensure we build on an arbitrary operating system:
Expand Down Expand Up @@ -256,9 +278,9 @@ clean: ## Ensure a clean build
fuzz_timeout_seconds ?= 10
.PHONY: fuzz
fuzz:
@cd internal/integration_test/fuzz && cargo fuzz run basic -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
@cd internal/integration_test/fuzz && cargo fuzz run memory_no_diff -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
@cd internal/integration_test/fuzz && cargo fuzz run validation -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
@cd internal/integration_test/fuzz && cargo fuzz run no_diff --sanitizer=none -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
@cd internal/integration_test/fuzz && cargo fuzz run memory_no_diff --sanitizer=none -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)
@cd internal/integration_test/fuzz && cargo fuzz run validation --sanitizer=none -- -rss_limit_mb=8192 -max_total_time=$(fuzz_timeout_seconds)

#### CLI release related ####

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
This repository contains experimental changes to try with wasilibs code.
Do not use it outside the wasilibs organization.

# wazero: the zero dependency WebAssembly runtime for Go developers

[![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)
Expand Down
5 changes: 5 additions & 0 deletions api/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ const (
// Note: The instruction list is too long to enumerate in godoc.
// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md
CoreFeatureSIMD

// Update experimental/features.go when adding elements here.
)

// SetEnabled enables or disables the feature or group of features.
Expand Down Expand Up @@ -207,6 +209,9 @@ func featureName(f CoreFeatures) string {
case CoreFeatureSIMD:
// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md
return "simd"
case CoreFeatureSIMD << 1: // Defined in experimental/features.go
// match https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md
return "threads"
}
return ""
}
27 changes: 27 additions & 0 deletions experimental/checkpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package experimental

// Snapshot holds the execution state at the time of a Snapshotter.Snapshot call.
type Snapshot interface {
// Restore sets the Wasm execution state to the capture. Because a host function
// calling this is resetting the pointer to the executation stack, the host function
// will not be able to return values in the normal way. ret is a slice of values the
// host function intends to return from the restored function.
Restore(ret []uint64)
}

// Snapshotter allows host functions to snapshot the WebAssembly execution environment.
// Currently, only the Wasm stack is captured, but in the future, this may be expanded
// to things like globals.
type Snapshotter interface {
// Snapshot captures the current execution state.
Snapshot() Snapshot
}

// EnableSnapshotterKey is a context key to indicate that snapshotting should be enabled.
// The context.Context passed to a exported function invocation should have this key set
// to a non-nil value, and host functions will be able to retrieve it using SnapshotterKey.
type EnableSnapshotterKey struct{}

// SnapshotterKey is a context key to access a Snapshotter from a host function.
// It is only present if EnableSnapshotter was set in the function invocation context.
type SnapshotterKey struct{}
14 changes: 14 additions & 0 deletions experimental/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package experimental

import "github.com/tetratelabs/wazero/api"

// CoreFeaturesThreads enables threads instructions ("threads").
//
// # Notes
//
// - This is not yet implemented by default, so you will need to use
// wazero.NewRuntimeConfigInterpreter
// - The instruction list is too long to enumerate in godoc.
// See https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md
// - Atomic operations are guest-only until api.Memory or otherwise expose them to host functions.
const CoreFeaturesThreads = api.CoreFeatureSIMD << 1 // TODO: Implement the compiler engine
Loading

0 comments on commit f3b18e0

Please sign in to comment.