Browse Source

builder: add support for Go 1.20

Not all features work yet, but allow it to compile with this Go version.
pull/3392/head
Ayke van Laethem 2 years ago
committed by Ron Evans
parent
commit
0d646d8e95
  1. 8
      .circleci/config.yml
  2. 1
      Makefile
  3. 4
      builder/config.go
  4. 15
      cgo/cgo_test.go
  5. 4
      cgo/testdata/errors.out.go
  6. 2
      testdata/stdlib.go

8
.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

1
Makefile

@ -286,7 +286,6 @@ TEST_PACKAGES_FAST = \
container/list \
container/ring \
crypto/des \
crypto/internal/subtle \
crypto/md5 \
crypto/rc4 \
crypto/sha1 \

4
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"))

15
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")

4
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

2
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'))

Loading…
Cancel
Save