all: replace target=wasi with target=wasip1

This eliminates the 'wasi' build tag in favor of 'GOOS=wasip1', introduced in Go 1.21.

For backwards compatablity, -target=wasi is a synonym for -target=wasip1.
This commit is contained in:
Randy Reddig
2024-03-04 10:26:41 -08:00
committed by Ron Evans
parent 62d8cdb218
commit 8e8ad9004f
28 changed files with 51 additions and 38 deletions
+5 -5
View File
@@ -427,17 +427,17 @@ tinygo-bench-fast:
# Same thing, except for wasi rather than the current platform. # Same thing, except for wasi rather than the current platform.
tinygo-test-wasi: tinygo-test-wasi:
$(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi $(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
tinygo-test-wasip1: tinygo-test-wasip1:
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
tinygo-test-wasi-fast: tinygo-test-wasi-fast:
$(TINYGO) test -target wasi $(TEST_PACKAGES_FAST) ./tests/runtime_wasi $(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
tinygo-test-wasip1-fast: tinygo-test-wasip1-fast:
GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) ./tests/runtime_wasi GOOS=wasip1 GOARCH=wasm $(TINYGO) test $(TEST_PACKAGES_FAST) ./tests/runtime_wasi
tinygo-bench-wasi: tinygo-bench-wasi:
$(TINYGO) test -target wasi -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) $(TINYGO) test -target wasip1 -bench . $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW)
tinygo-bench-wasi-fast: tinygo-bench-wasi-fast:
$(TINYGO) test -target wasi -bench . $(TEST_PACKAGES_FAST) $(TINYGO) test -target wasip1 -bench . $(TEST_PACKAGES_FAST)
# Test external packages in a large corpus. # Test external packages in a large corpus.
test-corpus: test-corpus:
@@ -445,7 +445,7 @@ test-corpus:
test-corpus-fast: test-corpus-fast:
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml
test-corpus-wasi: wasi-libc test-corpus-wasi: wasi-libc
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasi CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip1
tinygo-baremetal: tinygo-baremetal:
# Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest. # Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest.
+3 -3
View File
@@ -41,7 +41,7 @@ tinygo flash -target arduino examples/blinky1
TinyGo is very useful for compiling programs both for use in browsers (WASM) as well as for use on servers and other edge devices (WASI). TinyGo is very useful for compiling programs both for use in browsers (WASM) as well as for use on servers and other edge devices (WASI).
TinyGo programs can run in Fastly Compute@Edge (https://developer.fastly.com/learning/compute/go/), Fermyon Spin (https://developer.fermyon.com/spin/go-components), wazero (https://wazero.io/languages/tinygo/) and many other WebAssembly runtimes. TinyGo programs can run in [Fastly Compute](https://www.fastly.com/documentation/guides/compute/go/), [Fermyon Spin](https://developer.fermyon.com/spin/go-components), [wazero](https://wazero.io/languages/tinygo/) and many other WebAssembly runtimes.
Here is a small TinyGo program for use by a WASI host application: Here is a small TinyGo program for use by a WASI host application:
@@ -54,14 +54,14 @@ func add(x, y uint32) uint32 {
return x + y return x + y
} }
// main is required for the `wasi` target, even if it isn't used. // main is required for the `wasip1` target, even if it isn't used.
func main() {} func main() {}
``` ```
This compiles the above TinyGo program for use on any WASI runtime: This compiles the above TinyGo program for use on any WASI runtime:
```shell ```shell
tinygo build -o main.wasm -target=wasi main.go tinygo build -o main.wasm -target=wasip1 main.go
``` ```
## Installation ## Installation
+6 -1
View File
@@ -285,7 +285,7 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
// Tests are always run in the package directory. // Tests are always run in the package directory.
cmd.Dir = result.MainDir cmd.Dir = result.MainDir
// wasmtime is the default emulator used for `-target=wasi`. wasmtime // wasmtime is the default emulator used for `-target=wasip1`. wasmtime
// is a WebAssembly runtime CLI with WASI enabled by default. However, // is a WebAssembly runtime CLI with WASI enabled by default. However,
// only stdio are allowed by default. For example, while STDOUT routes // only stdio are allowed by default. For example, while STDOUT routes
// to the host, other files don't. It also does not inherit environment // to the host, other files don't. It also does not inherit environment
@@ -1548,6 +1548,11 @@ func main() {
options.PrintCommands = printCommand options.PrintCommands = printCommand
} }
// Compatibility with legacy -target=wasi
if options.Target == "wasi" {
options.Target = "wasip1"
}
err = options.Verify() err = options.Verify()
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build linux && !baremetal && !wasi //go:build linux && !baremetal && !wasip1
// This implementation of crypto/rand uses the /dev/urandom pseudo-file to // This implementation of crypto/rand uses the /dev/urandom pseudo-file to
// generate random numbers. // generate random numbers.
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build darwin || (linux && !baremetal && !js && !wasi && !386 && !arm) //go:build darwin || (linux && !baremetal && !js && !wasip1 && !386 && !arm)
package os_test package os_test
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build linux && !baremetal && !wasi && !wasip1 //go:build linux && !baremetal && !wasip1
package os package os
+2 -2
View File
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// This file was derived from src/os/dir_darwin.go since the logic for wasi is // This file was derived from src/os/dir_darwin.go since the logic for WASI is
// fairly similar: we use fdopendir, fdclosedir, and readdir from wasi-libc in // fairly similar: we use fdopendir, fdclosedir, and readdir from wasi-libc in
// a similar way that the darwin code uses functions from libc. // a similar way that the darwin code uses functions from libc.
//go:build wasi || wasip1 //go:build wasip1
package os package os
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !baremetal && !js && !wasi //go:build !baremetal && !js && !wasip1
// Copyright 2020 The Go Authors. All rights reserved. // Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build baremetal || (wasm && !wasi && !wasip1) //go:build baremetal || (wasm && !wasip1)
package os package os
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !wasi && !wasip1 //go:build !wasip1
package os_test package os_test
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build wasi || wasip1 //go:build wasip1
package os_test package os_test
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !baremetal && !js && !wasi && !wasip1 //go:build !baremetal && !js && !wasip1
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !windows && !baremetal && !js && !wasi && !wasip1 //go:build !windows && !baremetal && !js && !wasip1
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !baremetal && !js && !wasi && !wasip1 //go:build !baremetal && !js && !wasip1
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !baremetal && !js && !wasi && !wasip1 //go:build !baremetal && !js && !wasip1
package os package os
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build baremetal || (wasm && !wasi && !wasip1) //go:build baremetal || (wasm && !wasip1)
// Copyright 2016 The Go Authors. All rights reserved. // Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build !baremetal && !js && !wasi && !wasip1 //go:build !baremetal && !js && !wasip1
package os_test package os_test
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build (!wasi && !runtime_memhash_tsip && !runtime_memhash_leveldb) || (wasi && runtime_memhash_fnv) //go:build (!wasip1 && !runtime_memhash_tsip && !runtime_memhash_leveldb) || (wasip1 && runtime_memhash_fnv)
// This is the default for all targets except WASI, unless a more specific build // This is the default for all targets except WASI, unless a more specific build
// tag is set. // tag is set.
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build runtime_memhash_leveldb || (wasi && !runtime_memhash_fnv && !runtime_memhash_tsip) //go:build runtime_memhash_leveldb || (wasip1 && !runtime_memhash_fnv && !runtime_memhash_tsip)
// This is the default for WASI, but can also be used on other targets with the // This is the default for WASI, but can also be used on other targets with the
// right build tag. // right build tag.
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build linux && !baremetal && !nintendoswitch && !wasi && !wasm_unknown //go:build linux && !baremetal && !nintendoswitch && !wasip1 && !wasm_unknown
package runtime package runtime
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build (darwin || (linux && !baremetal && !wasi && !wasm_unknown)) && !nintendoswitch //go:build (darwin || (linux && !baremetal && !wasip1 && !wasm_unknown)) && !nintendoswitch
package runtime package runtime
@@ -1,4 +1,4 @@
//go:build tinygo.wasm && (wasi || wasip1) //go:build wasip1
package runtime package runtime
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build wasm && !wasi && !wasip1 //go:build wasm && !wasip1
package runtime package runtime
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !wasi && !wasip1 && !darwin //go:build !wasip1 && !darwin
package syscall package syscall
@@ -1,4 +1,4 @@
//go:build wasi || wasip1 //go:build wasip1
package syscall package syscall
@@ -397,8 +397,16 @@ func Chmod(path string, mode uint32) (err error) {
return Lstat(path, &stat) return Lstat(path, &stat)
} }
// wasmPageSize is the size of a page in WebAssembly's 32-bit memory. This
// is also its only unit of change.
//
// See https://www.w3.org/TR/wasm-core-1/#page-size
//
// FIXME: this is also defined in package runtime.
const wasmPageSize = 64 * 1024
func Getpagesize() int { func Getpagesize() int {
return libc_getpagesize() return wasmPageSize
} }
type Utsname struct { type Utsname struct {
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// //
//go:build !wasi && !wasip1 //go:build !wasip1
package testing_test package testing_test
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// //
//go:build wasi || wasip1 //go:build wasip1
package testing_test package testing_test
+3 -3
View File
@@ -2,9 +2,9 @@
"llvm-target": "wasm32-unknown-wasi", "llvm-target": "wasm32-unknown-wasi",
"cpu": "generic", "cpu": "generic",
"features": "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext", "features": "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext",
"build-tags": ["tinygo.wasm", "wasi"], "build-tags": ["tinygo.wasm"],
"goos": "linux", "goos": "wasip1",
"goarch": "arm", "goarch": "wasm",
"linker": "wasm-ld", "linker": "wasm-ld",
"libc": "wasi-libc", "libc": "wasi-libc",
"rtlib": "compiler-rt", "rtlib": "compiler-rt",