From abf0ada941a465054069dcfe98a8acd6040b09c5 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 9 Feb 2024 13:29:57 -0800 Subject: [PATCH] Set floor Go version at 1.20 (#2025) Signed-off-by: Takeshi Yoneda Co-authored-by: Edoardo Vacchi --- .github/workflows/commit.yaml | 8 +++--- .github/workflows/examples.yaml | 1 + .github/workflows/integration.yaml | 21 +++++++++++++++- .github/workflows/spectest.yaml | 8 +++--- go.mod | 2 +- imports/wasi_snapshot_preview1/fs_test.go | 14 ----------- internal/integration_test/fuzz/go.mod | 2 +- .../integration_test/stdlibs/bench_test.go | 3 +-- internal/integration_test/vs/time/go.mod | 2 +- internal/integration_test/vs/wasmedge/go.mod | 2 +- internal/integration_test/vs/wasmtime/go.mod | 2 +- internal/platform/platform.go | 9 ------- internal/platform/platform_test.go | 21 ---------------- internal/sysfs/adapter_test.go | 2 +- internal/sysfs/dirfs_test.go | 2 +- internal/sysfs/file_test.go | 25 ++----------------- internal/sysfs/futimens_windows.go | 7 ------ internal/sysfs/open_file_windows.go | 13 ++++------ internal/sysfs/readfs_test.go | 4 +-- internal/sysfs/stat_test.go | 6 ++--- internal/sysfs/sysfs_test.go | 8 ++---- internal/version/testdata/go.mod | 2 +- 22 files changed, 51 insertions(+), 113 deletions(-) diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index 5c95eadf7a..870bc844fe 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -73,8 +73,8 @@ jobs: - os: macos-14 arch: arm64 go-version: - - "1.21" # Current Go version - - "1.19" # Floor Go version of wazero (current - 2) + - "1.22" # Current Go version + - "1.20" # Floor Go version of wazero (current - 2) steps: @@ -114,8 +114,8 @@ jobs: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: # Use versions consistent with wazero's Go support policy. go-version: - - "1.21" # Current Go version - - "1.19" # Floor Go version of wazero (current - 2) + - "1.22" # Current Go version + - "1.20" # Floor Go version of wazero (current - 2) arch: - "amd64" - "arm64" diff --git a/.github/workflows/examples.yaml b/.github/workflows/examples.yaml index 5607bef903..0485dcabdc 100644 --- a/.github/workflows/examples.yaml +++ b/.github/workflows/examples.yaml @@ -34,6 +34,7 @@ jobs: strategy: matrix: # Use versions consistent with TinyGo. go-version: + # TODO: Add 1.22 when TinyGo supports it. - "1.20" # Latest Go version supported by TinyGo until its next version. - "1.19" # Floor Go version of latest TinyGo diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 2bf0ffa449..28d09ecdce 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -318,7 +318,8 @@ jobs: compiler: [baseline] arch: [amd64] go-version: - - "1.21" # Current Go version && The only version that supports wasip1. + - "1.21" + - "1.22" include: - os: version: macos-14 @@ -326,12 +327,24 @@ jobs: compiler: optimizing arch: "arm64" go-version: "1.21" + - os: + version: macos-14 + name: macOS + compiler: optimizing + arch: "arm64" + go-version: "1.22" - os: version: ubuntu-22.04 name: Ubuntu compiler: optimizing arch: "amd64" go-version: "1.21" + - os: + version: ubuntu-22.04 + name: Ubuntu + compiler: optimizing + arch: "amd64" + go-version: "1.22" steps: - id: setup-go @@ -357,6 +370,12 @@ jobs: cd ${{ env.STDLIB_TESTS }} make build.gowasip1 + # The wasip1 stdlib tests are really path sensitive, so they expect a writeable /tmp directory to be available. + # We create it at the root of `C:`. This is normally only necessary on GHA Windows runners. + - if: ${{ matrix.os.name == 'Windows' }} + run: | + mkdir /c/tmp + - name: Run built test binaries run: | cd ${{ env.STDLIB_TESTS }} diff --git a/.github/workflows/spectest.yaml b/.github/workflows/spectest.yaml index 0a795376f5..7a0a5ef40e 100644 --- a/.github/workflows/spectest.yaml +++ b/.github/workflows/spectest.yaml @@ -30,8 +30,8 @@ jobs: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: # Use versions consistent with wazero's Go support policy. go-version: - - "1.21" # Current Go version - - "1.19" # Floor Go version of wazero (current - 2) + - "1.22" # Current Go version + - "1.20" # Floor Go version of wazero (current - 2) spec-version: - "v1" - "v2" @@ -52,8 +52,8 @@ jobs: fail-fast: false # don't fail fast as sometimes failures are arch/OS specific matrix: # Use versions consistent with wazero's Go support policy. go-version: - - "1.21" # Current Go version - - "1.19" # Floor Go version of wazero (current - 2) + - "1.22" # Current Go version + - "1.20" # Floor Go version of wazero (current - 2) arch: - "arm64" - "riscv64" diff --git a/go.mod b/go.mod index 685fca63ad..b6906c6561 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/tetratelabs/wazero // Floor Go version of wazero (current - 2) -go 1.19 +go 1.20 // All the beta tags are retracted and replaced with "pre" to prevent users // from accidentally upgrading into the broken beta 1. diff --git a/imports/wasi_snapshot_preview1/fs_test.go b/imports/wasi_snapshot_preview1/fs_test.go index 301ce6483e..04fe783c14 100644 --- a/imports/wasi_snapshot_preview1/fs_test.go +++ b/imports/wasi_snapshot_preview1/fs_test.go @@ -9,7 +9,6 @@ import ( "math" "os" "path" - "runtime" "testing" gofstest "testing/fstest" "time" @@ -3558,11 +3557,6 @@ func Test_pathFilestatSetTimes(t *testing.T) { }, } - if runtime.GOOS == "windows" && !platform.IsAtLeastGo120 { - // Windows 1.19 returns ENOSYS on no_symlink_follow - tests = tests[:len(tests)-1] - } - for _, tt := range tests { tc := tt @@ -4951,10 +4945,6 @@ func requireOpenFile(t *testing.T, tmpDir string, pathName string, data []byte, // Test_fdReaddir_dotEntryHasARealInode because wasi-testsuite requires it. func Test_fdReaddir_dotEntryHasARealInode(t *testing.T) { - if runtime.GOOS == "windows" && !platform.IsAtLeastGo120 { - t.Skip("windows before go 1.20 has trouble reading the inode information on directories.") - } - root := t.TempDir() mod, r, _ := requireProxyModule(t, wazero.NewModuleConfig(). WithFSConfig(wazero.NewFSConfig().WithDirMount(root, "/")), @@ -5008,10 +4998,6 @@ func Test_fdReaddir_dotEntryHasARealInode(t *testing.T) { // is visible. This is significant on Windows. // https://github.com/ziglang/zig/blob/2ccff5115454bab4898bae3de88f5619310bc5c1/lib/std/fs/test.zig#L156-L184 func Test_fdReaddir_opened_file_written(t *testing.T) { - if runtime.GOOS == "windows" && !platform.IsAtLeastGo120 { - t.Skip("windows before go 1.20 has trouble reading the inode information on directories.") - } - tmpDir := t.TempDir() mod, r, _ := requireProxyModule(t, wazero.NewModuleConfig(). WithFSConfig(wazero.NewFSConfig().WithDirMount(tmpDir, "/")), diff --git a/internal/integration_test/fuzz/go.mod b/internal/integration_test/fuzz/go.mod index 3b4825e649..f9105bec10 100644 --- a/internal/integration_test/fuzz/go.mod +++ b/internal/integration_test/fuzz/go.mod @@ -1,6 +1,6 @@ module github.com/tetratelabs/wazero/internal/integration_test/fuzz -go 1.19 +go 1.20 require github.com/tetratelabs/wazero v0.0.0 diff --git a/internal/integration_test/stdlibs/bench_test.go b/internal/integration_test/stdlibs/bench_test.go index db1f85b769..f90542c3dd 100644 --- a/internal/integration_test/stdlibs/bench_test.go +++ b/internal/integration_test/stdlibs/bench_test.go @@ -109,8 +109,7 @@ var ( c, stdout, stderr = defaultModuleConfig() c = c.WithFSConfig( wazero.NewFSConfig(). - WithDirMount(sysroot, "/"). - WithDirMount(os.TempDir(), "/tmp")). + WithDirMount(sysroot, "/")). WithEnv("PWD", normalizedTestdir) args := []string{fname, "-test.short", "-test.v"} diff --git a/internal/integration_test/vs/time/go.mod b/internal/integration_test/vs/time/go.mod index 6324ae8129..bd65ba3b1a 100644 --- a/internal/integration_test/vs/time/go.mod +++ b/internal/integration_test/vs/time/go.mod @@ -1,6 +1,6 @@ module github.com/tetratelabs/wazero/internal/integration_test/vs/clock -go 1.19 +go 1.20 require golang.org/x/sys v0.1.0 diff --git a/internal/integration_test/vs/wasmedge/go.mod b/internal/integration_test/vs/wasmedge/go.mod index 170b52db80..a31d814535 100644 --- a/internal/integration_test/vs/wasmedge/go.mod +++ b/internal/integration_test/vs/wasmedge/go.mod @@ -1,6 +1,6 @@ module github.com/tetratelabs/wazero/internal/integration_test/vs/wasmedge -go 1.19 +go 1.20 require ( github.com/second-state/WasmEdge-go v0.12.1 diff --git a/internal/integration_test/vs/wasmtime/go.mod b/internal/integration_test/vs/wasmtime/go.mod index ee0b444950..f886f6d140 100644 --- a/internal/integration_test/vs/wasmtime/go.mod +++ b/internal/integration_test/vs/wasmtime/go.mod @@ -1,6 +1,6 @@ module github.com/tetratelabs/wazero/internal/integration_test/vs/wasmtime -go 1.19 +go 1.20 require ( github.com/bytecodealliance/wasmtime-go/v9 v9.0.0 diff --git a/internal/platform/platform.go b/internal/platform/platform.go index c7165034f2..0d91885655 100644 --- a/internal/platform/platform.go +++ b/internal/platform/platform.go @@ -5,18 +5,9 @@ package platform import ( - "regexp" "runtime" ) -// IsAtLeastGo120 checks features added in 1.20. We can remove this when Go -// 1.22 is out. -var IsAtLeastGo120 = isAtLeastGo120(runtime.Version()) - -func isAtLeastGo120(version string) bool { - return regexp.MustCompile("go1.[2-9][0-9][^0-9]").MatchString(version) -} - // archRequirementsVerified is set by platform-specific init to true if the platform is supported var archRequirementsVerified bool diff --git a/internal/platform/platform_test.go b/internal/platform/platform_test.go index 5cdce3f882..8fce9fa811 100644 --- a/internal/platform/platform_test.go +++ b/internal/platform/platform_test.go @@ -20,24 +20,3 @@ func Test_archRequirementsVerified(t *testing.T) { require.False(t, archRequirementsVerified) } } - -func Test_isAtLeastGo120(t *testing.T) { - tests := []struct { - input string - expected bool - }{ - {input: "go1.18.10", expected: false}, - {input: "go1.19.10", expected: false}, - {input: "go1.20.5", expected: true}, - {input: "devel go1.21-39c50707 Thu Jul 6 23:23:41 2023 +0000", expected: true}, - {input: "go1.21rc2", expected: true}, - {input: "go1.90.10", expected: true}, - {input: "go2.0.0", expected: false}, - } - - for _, tt := range tests { - tc := tt - - require.Equal(t, tc.expected, isAtLeastGo120(tc.input), tc.input) - } -} diff --git a/internal/sysfs/adapter_test.go b/internal/sysfs/adapter_test.go index 75b4f3b199..86c2fc51a2 100644 --- a/internal/sysfs/adapter_test.go +++ b/internal/sysfs/adapter_test.go @@ -97,7 +97,7 @@ func TestAdaptFS_Open_Read(t *testing.T) { // We can't correct operating system portability issues with os.DirFS on // windows. Use syscall.DirFS instead! - testOpen_Read(t, testFS, statSetsIno(), runtime.GOOS != "windows") + testOpen_Read(t, testFS, true, runtime.GOOS != "windows") t.Run("path outside root invalid", func(t *testing.T) { _, err := testFS.OpenFile("../foo", experimentalsys.O_RDONLY, 0) diff --git a/internal/sysfs/dirfs_test.go b/internal/sysfs/dirfs_test.go index d2826898ba..55e5ee1090 100644 --- a/internal/sysfs/dirfs_test.go +++ b/internal/sysfs/dirfs_test.go @@ -640,7 +640,7 @@ func TestDirFS_OpenFile(t *testing.T) { testFS := DirFS(tmpDir) - testOpen_Read(t, testFS, statSetsIno(), true) + testOpen_Read(t, testFS, true, true) testOpen_O_RDWR(t, tmpDir, testFS) diff --git a/internal/sysfs/file_test.go b/internal/sysfs/file_test.go index 44e7eb54c6..425cf34205 100644 --- a/internal/sysfs/file_test.go +++ b/internal/sysfs/file_test.go @@ -12,7 +12,6 @@ import ( experimentalsys "github.com/tetratelabs/wazero/experimental/sys" "github.com/tetratelabs/wazero/internal/fsapi" - "github.com/tetratelabs/wazero/internal/platform" "github.com/tetratelabs/wazero/internal/testing/require" "github.com/tetratelabs/wazero/sys" ) @@ -195,9 +194,7 @@ func TestFileIno(t *testing.T) { ino, errno := d.Ino() require.EqualErrno(t, 0, errno) // Results are inconsistent, so don't validate the opposite. - if statSetsIno() { - require.Equal(t, tc.expectedIno, ino) - } + require.Equal(t, tc.expectedIno, ino) }) } @@ -209,25 +206,10 @@ func TestFileIno(t *testing.T) { ino, errno := d.Ino() require.EqualErrno(t, 0, errno) // Results are inconsistent, so don't validate the opposite. - if statSetsIno() { - require.Equal(t, st.Ino, ino) - } + require.Equal(t, st.Ino, ino) }) } -// statSetsIno returns true if this will set sys.Stat_t Ino on stat. The -// reverse doesn't mean it won't. Rather it is inconsistent. This is needed -// because Windows on Go 1.19 sometimes, but not always returns non-zero inode. -func statSetsIno() bool { - if runtime.GOOS != "windows" { - return true - } else { - // Go can read the inode via a Windows file handle, but it is - // inconsistent on Go 1.19. - return platform.IsAtLeastGo120 - } -} - func TestFileIsDir(t *testing.T) { dirFS, embedFS, mapFS := dirEmbedMapFS(t, t.TempDir()) @@ -978,9 +960,6 @@ func TestFileUtimens(t *testing.T) { case "linux", "darwin": // supported case "freebsd": // TODO: support freebsd w/o CGO case "windows": - if !platform.IsAtLeastGo120 { - t.Skip("windows only works after Go 1.20") // TODO: possibly 1.19 ;) - } default: // expect ENOSYS and callers need to fall back to Utimens t.Skip("unsupported GOOS", runtime.GOOS) } diff --git a/internal/sysfs/futimens_windows.go b/internal/sysfs/futimens_windows.go index 3a5289b70b..e0c89f3039 100644 --- a/internal/sysfs/futimens_windows.go +++ b/internal/sysfs/futimens_windows.go @@ -4,7 +4,6 @@ import ( "syscall" "github.com/tetratelabs/wazero/experimental/sys" - "github.com/tetratelabs/wazero/internal/platform" ) func utimens(path string, atim, mtim int64) sys.Errno { @@ -12,12 +11,6 @@ func utimens(path string, atim, mtim int64) sys.Errno { } func futimens(fd uintptr, atim, mtim int64) error { - // Before Go 1.20, ERROR_INVALID_HANDLE was returned for too many reasons. - // Kick out so that callers can use path-based operations instead. - if !platform.IsAtLeastGo120 { - return sys.ENOSYS - } - // Per docs, zero isn't a valid timestamp as it cannot be differentiated // from nil. In both cases, it is a marker like sys.UTIME_OMIT. // See https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime diff --git a/internal/sysfs/open_file_windows.go b/internal/sysfs/open_file_windows.go index bcfbfbcd6b..717f8598af 100644 --- a/internal/sysfs/open_file_windows.go +++ b/internal/sysfs/open_file_windows.go @@ -8,7 +8,6 @@ import ( "unsafe" "github.com/tetratelabs/wazero/experimental/sys" - "github.com/tetratelabs/wazero/internal/platform" ) func openFile(path string, oflag sys.Oflag, perm fs.FileMode) (*os.File, sys.Errno) { @@ -150,13 +149,11 @@ func open(path string, mode int, perm uint32) (fd syscall.Handle, err error) { } } - if platform.IsAtLeastGo120 { - // This shouldn't be included before 1.20 to have consistent behavior. - // https://github.com/golang/go/commit/0f0aa5d8a6a0253627d58b3aa083b24a1091933f - if createmode == syscall.OPEN_EXISTING && access == syscall.GENERIC_READ { - // Necessary for opening directory handles. - attrs |= syscall.FILE_FLAG_BACKUP_SEMANTICS - } + // This shouldn't be included before 1.20 to have consistent behavior. + // https://github.com/golang/go/commit/0f0aa5d8a6a0253627d58b3aa083b24a1091933f + if createmode == syscall.OPEN_EXISTING && access == syscall.GENERIC_READ { + // Necessary for opening directory handles. + attrs |= syscall.FILE_FLAG_BACKUP_SEMANTICS } h, e := syscall.CreateFile(pathp, access, sharemode, sa, createmode, attrs, 0) diff --git a/internal/sysfs/readfs_test.go b/internal/sysfs/readfs_test.go index a8e21f1d9c..1daa6a6d7d 100644 --- a/internal/sysfs/readfs_test.go +++ b/internal/sysfs/readfs_test.go @@ -144,7 +144,7 @@ func TestReadFS_Open_Read(t *testing.T) { fs: func(tmpDir string) sys.FS { return &AdaptFS{FS: os.DirFS(tmpDir)} }, - expectFileIno: statSetsIno(), + expectFileIno: true, expectDirIno: runtime.GOOS != "windows", }, { @@ -152,7 +152,7 @@ func TestReadFS_Open_Read(t *testing.T) { fs: func(tmpDir string) sys.FS { return &AdaptFS{FS: &MaskOsFS{Fs: os.DirFS(tmpDir)}} }, - expectFileIno: statSetsIno(), + expectFileIno: true, expectDirIno: runtime.GOOS != "windows", }, { diff --git a/internal/sysfs/stat_test.go b/internal/sysfs/stat_test.go index 8dbaf5eb3a..bd9ae6dfcd 100644 --- a/internal/sysfs/stat_test.go +++ b/internal/sysfs/stat_test.go @@ -300,10 +300,8 @@ func requireDir(t *testing.T, d experimentalsys.File, st sys.Stat_t) { func requireDevIno(t *testing.T, f experimentalsys.File, st sys.Stat_t) { // Results are inconsistent, so don't validate the opposite. - if statSetsIno() { - require.NotEqual(t, uint64(0), st.Dev) - require.NotEqual(t, uint64(0), st.Ino) - } + require.NotEqual(t, uint64(0), st.Dev) + require.NotEqual(t, uint64(0), st.Ino) // Verify the special-cased properties supporting wasip2 "is_same_object" // See https://github.com/WebAssembly/wasi-filesystem/pull/81 diff --git a/internal/sysfs/sysfs_test.go b/internal/sysfs/sysfs_test.go index 75526e565f..9744c54b43 100644 --- a/internal/sysfs/sysfs_test.go +++ b/internal/sysfs/sysfs_test.go @@ -11,7 +11,6 @@ import ( "testing" experimentalsys "github.com/tetratelabs/wazero/experimental/sys" - "github.com/tetratelabs/wazero/internal/platform" "github.com/tetratelabs/wazero/internal/testing/require" "github.com/tetratelabs/wazero/sys" ) @@ -322,11 +321,8 @@ func testStat(t *testing.T, testFS experimentalsys.FS) { require.EqualErrno(t, 0, errno) require.True(t, st.Mode.IsDir()) - // windows before go 1.20 has trouble reading the inode information on directories. - if runtime.GOOS != "windows" || platform.IsAtLeastGo120 { - require.NotEqual(t, uint64(0), st.Dev) - require.NotEqual(t, uint64(0), st.Ino) - } + require.NotEqual(t, uint64(0), st.Dev) + require.NotEqual(t, uint64(0), st.Ino) } // requireReaddir ensures the input file is a directory, and returns its diff --git a/internal/version/testdata/go.mod b/internal/version/testdata/go.mod index 956c1476e8..55bc30b13c 100644 --- a/internal/version/testdata/go.mod +++ b/internal/version/testdata/go.mod @@ -1,6 +1,6 @@ module github.com/tetratelabs/wazero/internal/version/testdata -go 1.19 +go 1.20 require github.com/tetratelabs/wazero v0.0.0-20220818123113-1948909ec0b1 // indirect