env: add wasip1/wasm wazero builder

This builder installs wazero, a pure Go Wasm runtime with
WASI support.

Fixes golang/go#59150

Change-Id: Id27f7eff79848d0aec1434dad1bf5b57cbfff874
Reviewed-on: https://go-review.googlesource.com/c/build/+/479118
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
diff --git a/dashboard/builders.go b/dashboard/builders.go
index f87e85e..0bef9ef 100644
--- a/dashboard/builders.go
+++ b/dashboard/builders.go
@@ -53,6 +53,7 @@
 	"illumos":               "illumos-amd64",
 	"ios":                   "ios-arm64-corellium",
 	"js":                    "js-wasm-node18",
+	"wasip1":                "wasip1-wasm-wazero",
 	"linux":                 "linux-amd64",
 	"linux-arm":             "linux-arm-aws",
 	"linux-loong64":         "linux-loong64-3a5000",
@@ -97,6 +98,7 @@
 	"solaris":               "solaris-amd64-oraclerel",
 	"solaris-amd64":         "solaris-amd64-oraclerel",
 	"wasm":                  "js-wasm-node18",
+	"wazero":                "wasip1-wasm-wazero",
 	"windows":               "windows-amd64-2016",
 	"windows-386":           "windows-386-2016",
 	"windows-amd64":         "windows-amd64-2016",
@@ -322,6 +324,11 @@
 		ContainerImage: "linux-x86-stretch:latest",
 		SSHUsername:    "root",
 	},
+	"host-linux-amd64-wasip1-wasm-wazero": {
+		Notes:          "Container with Wazero for testing wasip1/wasm.",
+		ContainerImage: "wasip1-wasm-wazero:latest",
+		SSHUsername:    "root",
+	},
 	"host-linux-amd64-wsl": {
 		Notes:     "Windows 10 WSL2 Ubuntu",
 		Owners:    []*gophers.Person{gh("mengzhuo")},
@@ -3089,6 +3096,37 @@
 		RunBench:     true,
 		SkipSnapshot: true,
 	})
+	addBuilder(BuildConfig{
+		Name:        "wasip1-wasm-wazero",
+		HostType:    "host-linux-amd64-wasip1-wasm-wazero",
+		KnownIssues: []int{58141},
+		buildsRepo: func(repo, branch, goBranch string) bool {
+			b := buildRepoByDefault(repo) && atLeastGo1(goBranch, 21)
+			switch repo {
+			case "benchmarks", "debug", "perf", "talks", "tools", "tour", "website":
+				// Don't test these golang.org/x repos.
+				b = false
+			}
+			if repo != "go" && !(branch == "master" && goBranch == "master") {
+				// For golang.org/x repos, don't test non-latest versions.
+				b = false
+			}
+			return b
+		},
+		distTestAdjust: func(run bool, distTest string, isNormalTry bool) bool {
+			if isNormalTry && (strings.Contains(distTest, "/internal/") || distTest == "reboot") {
+				// Skip some tests in an attempt to speed up normal trybots, inherited from CL 121938.
+				run = false
+			}
+			return run
+		},
+		numTryTestHelpers: 3,
+		env: []string{
+			"GOOS=wasip1", "GOARCH=wasm", "GOHOSTOS=linux", "GOHOSTARCH=amd64",
+			"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/workdir/go/misc/wasm",
+			"GO_DISABLE_OUTBOUND_NETWORK=1",
+		},
+	})
 }
 
 // addBuilder adds c to the Builders map after doing some checks.
diff --git a/dashboard/builders_test.go b/dashboard/builders_test.go
index 86e7bc0..4cfe50f 100644
--- a/dashboard/builders_test.go
+++ b/dashboard/builders_test.go
@@ -626,6 +626,23 @@
 		{b("js-wasm-node18", "tour"), none},
 		{b("js-wasm-node18", "website"), none},
 
+		{b("wasip1-wasm-wazero", "go"), onlyPost},
+		{b("wasip1-wasm-wazero@go1.21", "go"), onlyPost},
+		{b("wasip1-wasm-wazero@go1.20", "go"), none},
+		// Test wasip1/wasm on a subset of golang.org/x repos:
+		{b("wasip1-wasm-wazero", "arch"), onlyPost},
+		{b("wasip1-wasm-wazero", "crypto"), onlyPost},
+		{b("wasip1-wasm-wazero", "sys"), onlyPost},
+		{b("wasip1-wasm-wazero", "net"), onlyPost},
+		{b("wasip1-wasm-wazero", "benchmarks"), none},
+		{b("wasip1-wasm-wazero", "debug"), none},
+		{b("wasip1-wasm-wazero", "mobile"), none},
+		{b("wasip1-wasm-wazero", "perf"), none},
+		{b("wasip1-wasm-wazero", "talks"), none},
+		{b("wasip1-wasm-wazero", "tools"), none},
+		{b("wasip1-wasm-wazero", "tour"), none},
+		{b("wasip1-wasm-wazero", "website"), none},
+
 		// Race builders. Linux for all, GCE builders for
 		// post-submit, and only post-submit for "go" for
 		// Darwin (limited resources).
@@ -665,6 +682,7 @@
 		{b("freebsd-386-12_3", "exp"), none},
 		{b("freebsd-amd64-12_3", "exp"), none},
 		{b("js-wasm", "exp"), none},
+		{b("wasip1-wasm-wazero", "exp"), none},
 
 		// exp is experimental; it doesn't test against release branches.
 		{b("linux-amd64@go1.99", "exp"), none},
@@ -691,6 +709,7 @@
 		{b("linux-amd64@go1.20", "pkgsite-metrics"), both},
 
 		{b("js-wasm", "build"), none},
+		{b("wasip1-wasm-wazero", "build"), none},
 		{b("android-386-emu", "build"), none},
 		{b("android-amd64-emu", "build"), none},
 
diff --git a/env/wasip1-wasm-wazero/Dockerfile b/env/wasip1-wasm-wazero/Dockerfile
new file mode 100644
index 0000000..8795f53
--- /dev/null
+++ b/env/wasip1-wasm-wazero/Dockerfile
@@ -0,0 +1,16 @@
+# Copyright 2023 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+ARG REPO
+
+FROM golang:latest as builder
+LABEL maintainer="golang-dev@googlegroups.com"
+
+RUN go install github.com/tetratelabs/wazero/cmd/wazero@v1.0.1
+
+FROM ${REPO}/linux-x86-sid:20221109
+
+COPY --from=builder /go/bin/wazero /usr/local/bin/wazero
+
+CMD ["/usr/local/bin/stage0"]
diff --git a/env/wasip1-wasm-wazero/Makefile b/env/wasip1-wasm-wazero/Makefile
new file mode 100644
index 0000000..386325c
--- /dev/null
+++ b/env/wasip1-wasm-wazero/Makefile
@@ -0,0 +1,22 @@
+# Copyright 2023 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+IMAGE_NAME=$(shell basename $(CURDIR))
+PROD_REPO=gcr.io/symbolic-datum-552
+
+usage:
+	echo "Use prod or dev targets. For dev, specify your Docker repository with the REPO=foo argument." ; exit 1
+
+prod: Dockerfile
+	docker build -t $(PROD_REPO)/$(IMAGE_NAME):latest --build-arg REPO=$(PROD_REPO) -f Dockerfile .
+
+pushprod: prod
+	docker push $(PROD_REPO)/$(IMAGE_NAME):latest
+
+# You must provide a REPO=your-repo-name arg when you make
+# this target. REPO is the name of the Docker repository
+# that will be prefixed to the name of the image being built.
+dev: Dockerfile
+	docker build -t $(REPO)/$(IMAGE_NAME):latest --build-arg REPO=$(REPO) -f Dockerfile .
+	docker push $(REPO)/$(IMAGE_NAME):latest