fail early if we know we lack Go linker patches

Right now, we only have linker patches for Go 1.22.x.
We only ever maintain those for one or two major Go versions at a time.

If a user tries to use the Go toolchain from 1.21, we already fail
with "Go version too old" messages early on, but we don't for 1.23,
causing a relatively confusing error later on when we link a binary:

    cannot get modified linker: cannot retrieve linker patches: open patches/go1.23: file does not exist

Instead, fail early and with a good error message.
pull/838/head
Daniel Martí 2 months ago committed by pagran
parent d138afaf32
commit 9a2ef369b2

@ -268,7 +268,10 @@ type errJustExit int
func (e errJustExit) Error() string { return fmt.Sprintf("exit: %d", e) }
func goVersionOK() bool {
const minGoVersion = "go1.22"
const (
minGoVersion = "go1.22" // the first major version we support
maxGoVersion = "go1.23" // the first major version we don't support
)
// rxVersion looks for a version like "go1.2" or "go1.2.3" in `go env GOVERSION`.
rxVersion := regexp.MustCompile(`go\d+\.\d+(?:\.\d+)?`)
@ -285,6 +288,10 @@ func goVersionOK() bool {
fmt.Fprintf(os.Stderr, "Go version %q is too old; please upgrade to %s or newer\n", toolchainVersionFull, minGoVersion)
return false
}
if version.Compare(sharedCache.GoVersion, maxGoVersion) >= 0 {
fmt.Fprintf(os.Stderr, "Go version %q is too new; Go linker patches aren't available for %s or later yet\n", toolchainVersionFull, maxGoVersion)
return false
}
// Ensure that the version of Go that built the garble binary is equal or
// newer than cache.GoVersionSemver.

@ -32,15 +32,15 @@ env TOOLCHAIN_GOVERSION='go1.14'
! exec garble build
stderr 'Go version "go1\.14" is too old; please upgrade to go1\.22 or newer'
# We should accept a future stable version.
# We should reject a future stable version, as we don't have linker patches yet.
# Note that we need to bump the version of Go that supposedly built it, too.
env GARBLE_TEST_GOVERSION='go1.28.2'
env TOOLCHAIN_GOVERSION='go1.28.2'
! exec garble build
stderr 'mocking the real build'
stderr 'Go version "go1\.28\.2" is too new; Go linker patches aren''t available for go1\.23 or later yet'
# We should accept custom devel strings.
env TOOLCHAIN_GOVERSION='devel go1.23-somecustomversion'
env TOOLCHAIN_GOVERSION='devel go1.22-somecustomversion'
! exec garble build
stderr 'mocking the real build'

Loading…
Cancel
Save