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 doesn't recognize forward go directive when tool section is present in go.mod #70949

Closed
andig opened this issue Dec 21, 2024 · 13 comments
Closed

Comments

@andig
Copy link
Contributor

andig commented Dec 21, 2024

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

$ go version
go version go1.23.4 darwin/arm64

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/andig/Library/Caches/go-build'
GOENV='/Users/andig/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/andig/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/andig/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.4/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.4/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/andig/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c  '
CGO_ENABLED='1'
GOMOD='/Users/andig/htdocs/evcc/go.mod'
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/sv/rs_453y57xj86xsbz3kw1mbc0000gn/T/go-build82831284=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOROOT/bin/go version: go version go1.23.4 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.23.4
uname -v: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
ProductName:		macOS
ProductVersion:		15.1.1
BuildVersion:		24B91
lldb --version: lldb-1600.0.39.109
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)

What did you do?

Follow-up to https://groups.google.com/g/golang-nuts/c/DknrmQ9hi60/m/rfgpCOXcAQAJ
Trying to go run evcc-io/evcc#17656 which contains a go.mod with

module github.com/evcc-io/evcc

go 1.24rc1

...

tool (
	github.com/dmarkham/enumer
	go.uber.org/mock/mockgen
)

running

❯ go version
go version go1.23.4 darwin/arm64

What did you expect to see?

Go 1.24rc1 downloaded and used

What did you see instead?

go: errors parsing go.mod:
go.mod:206: unknown block type: tool

/cc @prattmic

@seankhliao
Copy link
Member

GOTOOLCHAIN='local

you've explicitly asked that go not upgrade the toolchain for you.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2024
@andig
Copy link
Contributor Author

andig commented Dec 21, 2024

I don't think I did:

evcc chore/generate ≡
❯ go env -changed
evcc chore/generate ≡
❯ export | grep GOTOOL

So where does the local come from?

If I force it to auto this does not seem to be the default setting anymore:

evcc chore/generate ≡
❯ go env -w GOTOOLCHAIN=auto
evcc chore/generate ≡
❯ go env -changed
GOTOOLCHAIN='auto'

If local however is the default then it seems to defy the purpose if downloading newer toolchains.

According to https://go.dev/doc/toolchain:

In the standard configuration, the go command uses its own bundled toolchain when that toolchain is at least as new as the go or toolchain lines in the main module or workspace.

Since I have- afaikt- the standard configuration this is not what seems to be happening here.

@seankhliao
Copy link
Member

check /opt/homebrew/Cellar/go/1.23.4/libexec/go.env

@andig
Copy link
Contributor Author

andig commented Dec 21, 2024

local seems to be the default in any case:

If the $GOROOT/go.env file is missing or does not set a default, the go command assumes GOTOOLCHAIN=local.

@andig
Copy link
Contributor Author

andig commented Dec 21, 2024

❯ cat /opt/homebrew/Cellar/go/1.23.4/libexec/go.env
# This file contains the initial defaults for go command configuration.
# Values set by 'go env -w' and written to the user's go/env file override these.
# The environment overrides everything else.

# Use the Go module mirror and checksum database by default.
# See https://proxy.golang.org for details.
GOPROXY=https://proxy.golang.org,direct
GOSUMDB=sum.golang.org

# Automatically download newer toolchains as directed by go.mod files.
# See https://go.dev/doc/toolchain for details.
GOTOOLCHAIN=local

Automatically download newer toolchains as directed by go.mod files.

Is not happening...

@seankhliao
Copy link
Member

that appears to be a homebrew issue https://github.com/Homebrew/homebrew-core/blob/master/Formula/g/go.rb#L93

which deviates from upstream https://github.com/golang/go/blob/master/go.env

@seankhliao
Copy link
Member

see this line in particular https://github.com/Homebrew/homebrew-core/blob/b7a91605ef0a48dac1726cd989b429b3b0ca99c3/Formula/g/go.rb#L66
there's not much we can do about homebrew not updating the comments to reflect their policy

@andig
Copy link
Contributor Author

andig commented Dec 21, 2024

Thank you, that clarifies it. However, it is still confusing that

go env -changed

doesn't show this as changed. Seems go env reports against go.env but not against Go standard config?

@seankhliao
Copy link
Member

seankhliao commented Dec 21, 2024

yes, "standard" is defined by what's in go.env, cmd/go doesn't have any other default.

@carlocab
Copy link

see this line in particular Homebrew/homebrew-core@b7a9160/Formula/g/go.rb#L66 there's not much we can do about homebrew not updating the comments to reflect their policy

Setting GOTOOLCHAIN=local is documented whenever you [re]install/upgrade go using Homebrew:

❯ brew reinstall go
[snip]
==> Caveats
Homebrew's Go toolchain is configured with
  GOTOOLCHAIN=local
per Homebrew policy on tools that update themselves.
[snip]

But updating the comment in go.env is probably something we can do too.

carlocab added a commit to Homebrew/homebrew-core that referenced this issue Dec 21, 2024
See #202030 and golang/go#70949.

In particular, our current `go.env` contains

    # Automatically download newer toolchains as directed by go.mod files.
    # See https://go.dev/doc/toolchain for details.
    GOTOOLCHAIN=local

The comment about automatically downloading newer toolchains applies
only whenever `GOTOOLCHAIN=auto`, but we change that to
`GOTOOLCHAIN=local`. Therefore, let's get rid of the comment that no
longer applies after our `GOTOOLCHAIN` change.
gafreax pushed a commit to gafreax/homebrew-core that referenced this issue Dec 21, 2024
See Homebrew#202030 and golang/go#70949.

In particular, our current `go.env` contains

    # Automatically download newer toolchains as directed by go.mod files.
    # See https://go.dev/doc/toolchain for details.
    GOTOOLCHAIN=local

The comment about automatically downloading newer toolchains applies
only whenever `GOTOOLCHAIN=auto`, but we change that to
`GOTOOLCHAIN=local`. Therefore, let's get rid of the comment that no
longer applies after our `GOTOOLCHAIN` change.
@prattmic
Copy link
Member

cc @matloob @samthanawalla

I wonder if cmd/go should add a hint to go.mod parsing errors when the go line required a newer version, but GOTOOLCHAIN prevents an upgrade. We used to do something like this in the compiler IIRC.

I'm thinking something like:

go: errors parsing go.mod:
go.mod:206: unknown block type: tool
(Note: Out of date Go version? go.mod requires go1.24rc1, have go1.23.4, but GOTOOLCHAIN=local prevents upgrade)

@prattmic
Copy link
Member

Actually, come to think of it, even with GOTOOLCHAIN=local, due to forward compatibility, Go 1.23 would refuse to build this module even if go.mod did parse. So perhaps the real improvement here is just to move the version-based refusal earlier.

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

No branches or pull requests

5 participants