Skip to content

cmd/go: confusing situation with 'go run' and '//go:build ignore' #73152

@josharian

Description

@josharian

Go version

go version go1.24.2 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/josh/bin'
GOCACHE='/Users/josh/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/josh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/vm/htvrhp4177v2dfhdjlvl0pqh0000gn/T/go-build275806226=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD=[redacted]
GOMODCACHE='/Users/josh/pkg/mod'
GONOPROXY=[redacted]
GONOSUMDB=[redacted]
GOOS='darwin'
GOPATH='/Users/josh'
GOPRIVATE=[redacted]
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/josh/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/josh/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/josh/pkg/mod/golang.org/[email protected]/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Here's my terminal transcript:

$ go run x.go
go: updates to go.mod needed; to update it:
	go mod tidy
$ go mod tidy
$ go run x.go
go: updates to go.mod needed; to update it:
	go mod tidy
$ go mod tidy
$ go run x.go
go: updates to go.mod needed; to update it:
	go mod tidy

After quite a while spend debugging, it turns out the problem is that x.go had //go:build ignore, and so go mod tidy ignored it...leaving it in a broken state when actually running it.

Even once I had a diagnosis, it was non-trivial to work around, because go mod tidy has no place to specify build tags. I had to move the file to a new location, remove the build tag, run go mod tidy, and then put it all back together again.

What did you see happen?

covered above.

What did you expect to see?

again, covered above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.DevExpanything around developer experienceGoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions