Skip to content

Commit

Permalink
builder: add support for Go 1.20
Browse files Browse the repository at this point in the history
Not all features work yet, but allow it to compile with this Go version.
  • Loading branch information
aykevl committed Jan 16, 2023
1 parent b678295 commit 277b102
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,19 @@ jobs:
- test-linux:
llvm: "14"
resource_class: large
jobs:
test-llvm15-go120:
docker:
- image: golang:1.20-rc-buster
steps:
- test-linux:
llvm: "15"
resource_class: large

workflows:
test-all:
jobs:
# 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
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ TEST_PACKAGES_FAST = \
container/list \
container/ring \
crypto/des \
crypto/internal/subtle \
crypto/md5 \
crypto/rc4 \
crypto/sha1 \
Expand Down
4 changes: 2 additions & 2 deletions builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
15 changes: 11 additions & 4 deletions cgo/cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go/types"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cgo/testdata/errors.out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion testdata/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 277b102

Please sign in to comment.