From 37e582d5813b3cd05bcc6350876441bcbb430abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 17 Oct 2025 23:25:26 +0100 Subject: [PATCH] support Go versions with X: suffixes for GOEXPERIMENTs A workaround until https://github.com/golang/go/issues/75953 is fixed. See #978. --- main.go | 3 +++ testdata/script/goversion.txtar | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 56270a2..57b7abc 100644 --- a/main.go +++ b/main.go @@ -731,6 +731,9 @@ To install Go, see: https://go.dev/doc/install if err := json.Unmarshal(out, &sharedCache.GoEnv); err != nil { return fmt.Errorf(`cannot unmarshal from "go env -json": %w`, err) } + // TODO: remove once https://github.com/golang/go/issues/75953 is fixed, + // such that `go env GOVERSION` can always be parsed by go/version. + sharedCache.GoEnv.GOVERSION, _, _ = strings.Cut(sharedCache.GoEnv.GOVERSION, " ") // Some Go version managers switch between Go versions via a GOROOT which symlinks // to one of the available versions. Given that later we build a patched linker diff --git a/testdata/script/goversion.txtar b/testdata/script/goversion.txtar index 55eb2fe..7d5278e 100644 --- a/testdata/script/goversion.txtar +++ b/testdata/script/goversion.txtar @@ -12,7 +12,7 @@ stderr 'Go version is too old; please upgrade to go1\.25\.0 or newer' # A clearly invalid go version. env TOOLCHAIN_GOVERSION='bogus version' ! exec garble build -stderr 'Go version "bogus version" appears to be invalid or too old; use go1\.25\.0 or newer' +stderr 'Go version "bogus" appears to be invalid or too old; use go1\.25\.0 or newer' # We should error on a devel version that's too old; # note that they started with the string "devel", @@ -49,6 +49,12 @@ env TOOLCHAIN_GOVERSION='go1.25.0-somecustomversion' ! exec garble build stderr 'mocking the real build' +# A stable version with a build-time GOEXPERIMENT. +# See: https://github.com/golang/go/issues/75953 +env TOOLCHAIN_GOVERSION='go1.25.0 X:nodwarf5' +! 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.25.1' env TOOLCHAIN_GOVERSION='go1.25.0'