Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: Go modules initialised by go1.21.1 cannot be built using go1.20.8 #63279

Closed
soh-ew opened this issue Sep 28, 2023 · 3 comments
Closed
Labels

Comments

@soh-ew
Copy link

soh-ew commented Sep 28, 2023

What version of Go are you using (go version)?

$ go version 1.21.1

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/enwei.soh/Library/Caches/go-build'
GOENV='/Users/enwei.soh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/enwei.soh/gopath/pkg/mod'
GONOPROXY='none'
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/enwei.soh/gopath'
GOPRIVATE=''
GOPROXY='proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.1/libexec' 
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/40/90j35z011n14czs8pbg736rr0000gn/T/go-build3498449936=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

We are attempting to make builds for both current and previous Go language versions (1.21 and 1.20). However, this does not work for Go modules initialised by go1.21.1, or any go directive set to 1.21.1 in the go.mod file, as go1.20.8 does not recognise the go directive with a X.Y.Z format.

  1. Run go mod init in an empty folder
  2. add a dummy main file (e.g. https://go.dev/play/p/UPxh4-pRY1V)
  3. Run GOTOOLCHAIN=go1.20.8 go build main.go

What did you expect to see?

main binary created.

What did you see instead?

go: errors parsing go.mod:
/Users/enwei.soh/gopath/src/testgo21/go.mod:3: invalid go version '1.21.1': must match format 1.23
@bcmills
Copy link
Contributor

bcmills commented Sep 28, 2023

This is working as designed in #57001.

To select the minimum go version using Go 1.21 or higher, you can use go get go@1.20 or similar.

With older Go versions (back to Go 1.17), you can use go mod tidy -go=1.20.

@bcmills bcmills added the GoCommand cmd/go label Sep 28, 2023
@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@soh-ew
Copy link
Author

soh-ew commented Sep 29, 2023

Thanks for the response!

Just to clarify, does that mean that moving forward:

  1. If I want to build for the latest and previous go versions (e.g. go1.22 and go1.21), my Go modules will need to enforce a maximum go directive of the previous go version go1.21
  2. Extending from the above point, my go1.21 Go modules cannot use other modules as dependencies if these other modules declare the go directive to be higher than go1.21 (as per discussion in cmd/go: go get -u && go mod tidy behaves differently starting with Go 1.21.0, leading to unknown directive toolchain errors #62409 )

Is this understanding correct?

@seankhliao
Copy link
Member

yes, besides the fact that the new versions should include patch: go1.21.0 and go1.22.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants