From 0d646d8e95ffa5ad8dcc466eea597dc8913823e8 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 13 Jan 2023 17:53:55 +0000 Subject: [PATCH] builder: add support for Go 1.20 Not all features work yet, but allow it to compile with this Go version. --- .circleci/config.yml | 8 ++++++++ Makefile | 1 - builder/config.go | 4 ++-- cgo/cgo_test.go | 15 +++++++++++---- cgo/testdata/errors.out.go | 4 ++-- testdata/stdlib.go | 2 +- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a7e17d5..95e2a491 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -105,6 +105,13 @@ jobs: - test-linux: llvm: "14" resource_class: large + test-llvm15-go120: + docker: + - image: golang:1.20-rc-buster + steps: + - test-linux: + llvm: "15" + resource_class: large workflows: test-all: @@ -112,3 +119,4 @@ workflows: # This tests our lowest supported versions of Go and LLVM, to make sure at # least the smoke tests still pass. - test-llvm14-go118 + - test-llvm15-go120 diff --git a/Makefile b/Makefile index cc359d56..97ba293c 100644 --- a/Makefile +++ b/Makefile @@ -286,7 +286,6 @@ TEST_PACKAGES_FAST = \ container/list \ container/ring \ crypto/des \ - crypto/internal/subtle \ crypto/md5 \ crypto/rc4 \ crypto/sha1 \ diff --git a/builder/config.go b/builder/config.go index c55ce1a2..a7df83f1 100644 --- a/builder/config.go +++ b/builder/config.go @@ -33,8 +33,8 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { if err != nil { return nil, fmt.Errorf("could not read version from GOROOT (%v): %v", goroot, err) } - if major != 1 || minor < 18 || minor > 19 { - return nil, fmt.Errorf("requires go version 1.18 through 1.19, got go%d.%d", major, minor) + if major != 1 || minor < 18 || minor > 20 { + return nil, fmt.Errorf("requires go version 1.18 through 1.20, got go%d.%d", major, minor) } clangHeaderPath := getClangHeaderPath(goenv.Get("TINYGOROOT")) diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go index e25da7a1..a44dd8e1 100644 --- a/cgo/cgo_test.go +++ b/cgo/cgo_test.go @@ -11,6 +11,7 @@ import ( "go/types" "os" "path/filepath" + "regexp" "runtime" "strings" "testing" @@ -21,9 +22,15 @@ var flagUpdate = flag.Bool("update", false, "Update images based on test output. // normalizeResult normalizes Go source code that comes out of tests across // platforms and Go versions. -func normalizeResult(result string) string { - actual := strings.ReplaceAll(result, "\r\n", "\n") - return actual +func normalizeResult(t *testing.T, result string) string { + result = strings.ReplaceAll(result, "\r\n", "\n") + + // This changed to 'undefined:', in Go 1.20. + result = strings.ReplaceAll(result, ": undeclared name:", ": undefined:") + // Go 1.20 added a bit more detail + result = regexp.MustCompile(`(unknown field z in struct literal).*`).ReplaceAllString(result, "$1") + + return result } func TestCGo(t *testing.T) { @@ -88,7 +95,7 @@ func TestCGo(t *testing.T) { if err != nil { t.Errorf("could not write out CGo AST: %v", err) } - actual := normalizeResult(buf.String()) + actual := normalizeResult(t, buf.String()) // Read the file with the expected output, to compare against. outfile := filepath.Join("testdata", name+".out.go") diff --git a/cgo/testdata/errors.out.go b/cgo/testdata/errors.out.go index b15a26b6..716fd771 100644 --- a/cgo/testdata/errors.out.go +++ b/cgo/testdata/errors.out.go @@ -8,9 +8,9 @@ // Type checking errors after CGo processing: // testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as C.char value in variable declaration (overflows) // testdata/errors.go:105: unknown field z in struct literal -// testdata/errors.go:108: undeclared name: C.SOME_CONST_1 +// testdata/errors.go:108: undefined: C.SOME_CONST_1 // testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows) -// testdata/errors.go:112: undeclared name: C.SOME_CONST_4 +// testdata/errors.go:112: undefined: C.SOME_CONST_4 package main diff --git a/testdata/stdlib.go b/testdata/stdlib.go index bc59d20c..f051eaf0 100644 --- a/testdata/stdlib.go +++ b/testdata/stdlib.go @@ -24,7 +24,7 @@ func main() { syscall.Getppid() // package math/rand - fmt.Println("pseudorandom number:", rand.Int31()) + fmt.Println("pseudorandom number:", rand.New(rand.NewSource(1)).Int31()) // package strings fmt.Println("strings.IndexByte:", strings.IndexByte("asdf", 'd'))