From 0d91a9487552da4e75e0b4c62a5d7141cf5c74ae Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Fri, 11 Aug 2023 08:09:14 +1000 Subject: [PATCH] Go 1.21 (#92) See https://go.dev/blog/go1.21 --- .github/workflows/test.yml | 30 ++++++++++++++++++++++++------ Makefile | 16 ++++++++++++---- README.md | 11 ++++++----- go.mod | 2 +- wasitest/system.go | 2 +- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6671bdd..bee7942 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,8 @@ on: pull_request: jobs: - Go: + go-test: + name: Go Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -14,9 +15,9 @@ jobs: submodules: recursive - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version-file: go.mod check-latest: true # We run the tests 20 times because sometimes it helps highlight flaky @@ -24,7 +25,24 @@ jobs: - name: Go Tests run: make test count=20 - WASI: + golangci-lint: + name: Go Lint + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version-file: go.mod + check-latest: true + - run: go mod download + - uses: golangci/golangci-lint-action@v3 + with: + version: v1.54.0 + args: --timeout 5m --issues-exit-code 0 # warn only + + wasi-test: + name: WASI Test Suite runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -32,9 +50,9 @@ jobs: submodules: recursive - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version-file: go.mod check-latest: true - name: WASI Tests diff --git a/Makefile b/Makefile index 0684551..2237d4b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -.PHONY: all clean test testdata wasi-libc wasi-testsuite +.PHONY: all clean fmt lint test testdata wasi-libc wasi-testsuite + +GO ?= go count ?= 1 @@ -33,7 +35,13 @@ clean: rm -f $(testdata.files) test: testdata - go test -count=$(count) ./... + $(GO) test -count=$(count) ./... + +fmt: + $(GO) fmt ./... + +lint: + which golangci-lint >/dev/null && golangci-lint run testdata: $(testdata.files) @@ -61,13 +69,13 @@ testdata/c/http/http.wasm: testdata/c/http/http.c clang $< -o $@ -Wall -Os -target wasm32-unknown-wasi testdata/c/http/proxy.c testdata/c/http/proxy_component_type.o testdata/go/%.wasm: testdata/go/%.go - GOARCH=wasm GOOS=wasip1 gotip build -o $@ $< + GOARCH=wasm GOOS=wasip1 $(GO) build -o $@ $< testdata/tinygo/%.wasm: testdata/tinygo/%.go tinygo build -target=wasi -o $@ $< wasirun: go.mod $(wasirun.src) - go build -o wasirun ./cmd/wasirun + $(GO) build -o wasirun ./cmd/wasirun wasi-libc: testdata/.sysroot/lib/wasm32-wasi/libc.a diff --git a/README.md b/README.md index edbe394..cb71268 100644 --- a/README.md +++ b/README.md @@ -109,9 +109,8 @@ As the providers of a Go implementation of WASI, we're naturally interested in Go's support for WebAssembly and WASI, and are championing the efforts to make Go a first class citizen in the ecosystem (along with Rust and Zig). -Go v1.21, scheduled for release in August 2023, has native support for -WebAssembly and WASI. To test these features before release, use [`gotip`][gotip] -in place of `go`: +[Go v1.21][go-121] has native support for WebAssembly and WASI: + ```go package main @@ -124,7 +123,9 @@ func main() { ``` ```console -$ GOOS=wasip1 GOARCH=wasm gotip build -o hello.wasm hello.go +# go version +go version go1.21.0 darwin/arm64 +$ GOOS=wasip1 GOARCH=wasm go build -o hello.wasm hello.go $ wasirun hello.wasm Hello, World! ``` @@ -150,7 +151,7 @@ Remember to be respectful and open minded! [wasitest]: https://github.com/stealthrocket/wasi-go/tree/main/wasitest [tracer]: https://github.com/stealthrocket/wasi-go/blob/main/tracer.go [sockets-extension]: https://github.com/stealthrocket/wasi-go/blob/main/sockets_extension.go -[gotip]: https://pkg.go.dev/golang.org/dl/gotip +[go-121]: https://go.dev/blog/go1.21 [go-script]: https://github.com/stealthrocket/wasi-go/blob/main/share/go_wasip1_wasm_exec [wasmer]: https://github.com/wasmerio/wasmer [wasmedge]: https://github.com/WasmEdge/WasmEdge diff --git a/go.mod b/go.mod index c643ec9..695529d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/stealthrocket/wasi-go -go 1.20 +go 1.21 require ( github.com/stealthrocket/wazergo v0.19.1 diff --git a/wasitest/system.go b/wasitest/system.go index e674830..3d3c4a0 100644 --- a/wasitest/system.go +++ b/wasitest/system.go @@ -2,11 +2,11 @@ package wasitest import ( "context" + "slices" "testing" "github.com/stealthrocket/wasi-go" "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) // TestSystem is a test suite which validates the behavior of wasi.System