Skip to content

Commit

Permalink
drop support for Go 1.20
Browse files Browse the repository at this point in the history
Go 1.21.0 was released in August 2023, so our upcoming release
will no longer support the Go 1.20 release series.

The first Go 1.22 release candidate is also due in December 2023,
less than a month from now, so dropping 1.20 will simplify 1.22 work.
  • Loading branch information
mvdan authored and pagran committed Nov 12, 2023
1 parent abcdc1f commit 126618a
Show file tree
Hide file tree
Showing 39 changed files with 60 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x, 1.21.x]
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module mvdan.cc/garble

go 1.20
go 1.21

require (
github.com/bluekeyes/go-gitdiff v0.7.1
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUU
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (e errJustExit) Error() string { return fmt.Sprintf("exit: %d", e) }

func goVersionOK() bool {
const (
minGoVersionSemver = "v1.20.0"
minGoVersionSemver = "v1.21.0"
suggestedGoVersion = "1.21"
)

Expand Down Expand Up @@ -1329,7 +1329,7 @@ func (tf *transformer) processImportCfg(flags []string, requiredPkgs []string) (
// See exporttest/*.go in testdata/scripts/test.txt.
// For now, spot the pattern and avoid the unnecessary error;
// the dependency is unused, so the packagefile line is redundant.
// This still triggers as of go1.20.
// This still triggers as of go1.21.
if strings.HasSuffix(tf.curPkg.ImportPath, ".test]") && strings.HasPrefix(tf.curPkg.ImportPath, impPath) {
continue
}
Expand Down Expand Up @@ -2195,7 +2195,7 @@ func alterTrimpath(flags []string) []string {
return flagSetValue(flags, "-trimpath", sharedTempDir+"=>;"+trimpath)
}

// forwardBuildFlags is obtained from 'go help build' as of Go 1.20.
// forwardBuildFlags is obtained from 'go help build' as of Go 1.21.
var forwardBuildFlags = map[string]bool{
// These shouldn't be used in nested cmd/go calls.
"-a": false,
Expand Down Expand Up @@ -2235,7 +2235,7 @@ var forwardBuildFlags = map[string]bool{
"-workfile": true,
}

// booleanFlags is obtained from 'go help build' and 'go help testflag' as of Go 1.20.
// booleanFlags is obtained from 'go help build' and 'go help testflag' as of Go 1.21.
var booleanFlags = map[string]bool{
// Shared build flags.
"-a": true,
Expand Down
8 changes: 1 addition & 7 deletions runtime_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"strconv"
"strings"

"golang.org/x/mod/semver"

ah "mvdan.cc/garble/internal/asthelper"
)

Expand Down Expand Up @@ -238,11 +236,7 @@ func stripRuntime(basename string, file *ast.File) {
"printAncestorTracebackFuncInfo", "goroutineheader", "tracebackothers", "tracebackHexdump", "printCgoTraceback":
funcDecl.Body.List = nil
case "printOneCgoTraceback":
if semver.Compare(sharedCache.GoVersionSemver, "v1.21") >= 0 {
funcDecl.Body = ah.BlockStmt(ah.ReturnStmt(ast.NewIdent("false")))
} else {
funcDecl.Body = ah.BlockStmt(ah.ReturnStmt(ah.IntLit(0)))
}
funcDecl.Body = ah.BlockStmt(ah.ReturnStmt(ast.NewIdent("false")))
default:
if strings.HasPrefix(funcDecl.Name.Name, "print") {
funcDecl.Body.List = nil
Expand Down
6 changes: 2 additions & 4 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type sharedCacheType struct {
// GoVersionSemver is a semver-compatible version of the Go toolchain
// currently being used, as reported by "go env GOVERSION".
// Note that the version of Go that built the garble binary might be newer.
// Also note that a devel version like "go1.21-231f290e51" is
// currently represented as "v1.21".
// Also note that a devel version like "go1.22-231f290e51" is
// currently represented as "v1.22".
GoVersionSemver string

// Filled directly from "go env".
Expand Down Expand Up @@ -266,8 +266,6 @@ func appendListedPackages(packages []string, mainBuild bool) error {
// Some packages in runtimeLinknamed need a build tag to be importable,
// like crypto/internal/boring/fipstls with boringcrypto,
// so any pkg.Error should be ignored when the build tag isn't set.
} else if pkg.ImportPath == "maps" && semver.Compare(sharedCache.GoVersionSemver, "v1.21") < 0 {
// added in Go 1.21, so Go 1.20 runs into a "not found" error.
} else if pkg.ImportPath == "math/rand/v2" && semver.Compare(sharedCache.GoVersionSemver, "v1.22") < 0 {
// added in Go 1.22, so Go 1.21 runs into a "not found" error.
} else {
Expand Down
2 changes: 1 addition & 1 deletion testdata/script/asm.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ binsubstr main$exe 'addJmp' 'AddImpl'
-- go.mod --
module test/with.many.dots/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/atomic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cmp stderr main.stderr
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/basic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ binsubstr main$exe 'garble_main.go' 'globalVar' 'globalFunc' $gofullversion
-- go.mod --
module test/mainfoo

go 1.20
go 1.21
-- garble_main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/cache.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cmp stderr main.stderr
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/cgo.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ binsubstr main$exe 'privateAdd'
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/crossbuild.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stderr 'intrinsic substitution for Len64.*BitLen64'
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/ctrlflow.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ grep 'func\(int\) int' $WORK/debug/test/main/GARBLE_controlflow.go
-- go.mod --
module test/main

go 1.20
go 1.21
-- garble_main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/debugdir.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ stderr 'test/main' # we force rebuilds with -debugdir
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/embed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cmp stdout main.stdout
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/goenv.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exec $NAME/garble$exe build
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/gogarble.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bincmp out_rebuild out
-- go.mod --
module test/main

go 1.20
go 1.21
-- standalone/main.go --
package main

Expand Down
24 changes: 12 additions & 12 deletions testdata/script/goversion.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,45 @@ env TOOLCHAIN_GOVERSION='go1.28.2'
stderr 'mocking the real build'

# We should accept custom devel strings.
env TOOLCHAIN_GOVERSION='devel go1.20-somecustomversion'
env TOOLCHAIN_GOVERSION='devel go1.22-somecustomversion'
! exec garble build
stderr 'mocking the real build'

# The current toolchain may be older than the one that built garble.
env GARBLE_TEST_GOVERSION='go1.21'
env TOOLCHAIN_GOVERSION='go1.20.3'
env GARBLE_TEST_GOVERSION='go1.22'
env TOOLCHAIN_GOVERSION='go1.21.3'
! exec garble build
stderr 'mocking the real build'

# The current toolchain may be equal to the one that built garble.
env GARBLE_TEST_GOVERSION='devel go1.20-6673d5d701 Sun Mar 20 16:05:03 2023 +0000'
env TOOLCHAIN_GOVERSION='devel go1.20-6673d5d701 Sun Mar 20 16:05:03 2023 +0000'
env GARBLE_TEST_GOVERSION='devel go1.21-6673d5d701 Sun Mar 20 16:05:03 2023 +0000'
env TOOLCHAIN_GOVERSION='devel go1.21-6673d5d701 Sun Mar 20 16:05:03 2023 +0000'
! exec garble build
stderr 'mocking the real build'

# The current toolchain must not be newer than the one that built garble.
env GARBLE_TEST_GOVERSION='go1.18'
env TOOLCHAIN_GOVERSION='go1.20.1'
env TOOLCHAIN_GOVERSION='go1.21.1'
! exec garble build
stderr 'garble was built with "go1\.18" and is being used with "go1\.20\.1"; rebuild '
stderr 'garble was built with "go1\.18" and is being used with "go1\.21\.1"; rebuild '

# We'll error even if the difference is a minor (bugfix) level.
# In practice it probably wouldn't matter, but in theory it could still lead to tricky bugs.
env GARBLE_TEST_GOVERSION='go1.20.11'
env TOOLCHAIN_GOVERSION='go1.20.14'
env GARBLE_TEST_GOVERSION='go1.21.11'
env TOOLCHAIN_GOVERSION='go1.21.14'
! exec garble build
stderr 'garble was built with "go1\.20\.11" and is being used with "go1\.20\.14"; rebuild '
stderr 'garble was built with "go1\.21\.11" and is being used with "go1\.21\.14"; rebuild '

# If garble builds itself and is then used, it won't know what version built it.
# As a fallback, we drop the comparison against the toolchain's version.
env GARBLE_TEST_GOVERSION='bogus version'
env TOOLCHAIN_GOVERSION='go1.20.3'
env TOOLCHAIN_GOVERSION='go1.21.3'
! exec garble build
stderr 'mocking the real build'
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
5 changes: 2 additions & 3 deletions testdata/script/help.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ stderr 'must precede command, like: garble -seed=random build \./pkg'
stderr 'did you run.*instead of "garble \[command\]"'

! exec garble build badpackage
[!go1.21] stderr 'package badpackage is not in GOROOT'
[go1.21] stderr 'package badpackage is not in std'
stderr 'package badpackage is not in std'
! stdout .

! exec garble build ./badpackage
Expand Down Expand Up @@ -118,6 +117,6 @@ stderr 'usage: garble version'
-- go.mod --
module dummy

go 1.20
go 1.21
-- dummy.go --
package dummy
2 changes: 1 addition & 1 deletion testdata/script/implement.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cmp stdout main.stdout
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/imports.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cmp stdout main.stdout
-- go.mod --
module test/main

go 1.20
go 1.21

require (
gopkg.in/garbletest.v2 v2.999.0
Expand Down
2 changes: 1 addition & 1 deletion testdata/script/init.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cmp stderr main.stderr
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/ldflags.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ binsubstr main$exe 'unexportedVersion' 'ExportedUnset' 'v1.22.33' 'garble_replac
-- go.mod --
module domain.test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/linker.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cmp stderr main.stderr
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
4 changes: 2 additions & 2 deletions testdata/script/linkname.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmp stderr main.stderr
-- go.mod --
module test/main

go 1.20
go 1.21

replace big.chungus/meme => ./big.chungus/meme

Expand Down Expand Up @@ -149,7 +149,7 @@ func ByteIndex(s string, c byte) int
-- big.chungus/meme/go.mod --
module test/main

go 1.20
go 1.21
-- big.chungus/meme/dante.go --
package meme

Expand Down
11 changes: 3 additions & 8 deletions testdata/script/list_error.txtar
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
! exec garble build ./...
[!go1.21] cmpenv stderr stderr-go1.20.golden
[go1.21] cmpenv stderr stderr-go1.21.golden
cmpenv stderr stderr.golden

-- stderr-go1.20.golden --
# test/main/broken
broken${/}broken.go:5:16: cannot use 123 (untyped int constant) as string value in variable declaration
imports_missing${/}imports.go:5:8: package test/main/missing is not in GOROOT (${GOROOT}${/}src${/}test${/}main${/}missing)
-- stderr-go1.21.golden --
-- stderr.golden --
# test/main/broken
broken${/}broken.go:5:16: cannot use 123 (untyped int constant) as string value in variable declaration
imports_missing${/}imports.go:5:8: package test/main/missing is not in std (${GOROOT}${/}src${/}test${/}main${/}missing)
-- go.mod --
module test/main

go 1.20
go 1.21
-- broken/broken.go --
package broken

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/literals.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exec garble -literals build std
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/modinfo.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ stdout 'build\s*vcs.revision='${HEAD_COMMIT_SHA}
-- go.mod --
module test/main

go 1.20
go 1.21
-- main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/plugin.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cmp stderr main.stderr
-- go.mod --
module test/main

go 1.20
go 1.21
-- plugin/main.go --
package main

Expand Down
2 changes: 1 addition & 1 deletion testdata/script/position.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ stdout 'varPositions is sorted'
-- go.mod --
module test/main

go 1.20
go 1.21
-- garble_main.go --
package main

Expand Down
Loading

0 comments on commit 126618a

Please sign in to comment.