Repository navigation
cmd/go: cgo compile cache ignores Go builder warning policy #81039
Description
Go version
go version go1.28-devel
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='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/mac/go/bin'
GOCACHE='/Users/mac/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/mac/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/tq/m955dwkd1519phkp2hwpv9_80000gn/T/go-build1415656419=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/mac/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPACKAGESDRIVER=''
GOPATH='/Users/mac/go'
GOPRIVATE=''
GOPROXY=''
GOROOT='/Users/mac/202609/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/mac/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/mac/202609/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.28-devel_d758038bdf Tue Aug 11 10:10:28 2026 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'What did you do?
Create a package containing a C compiler warning:
package m
/*
#cgo CFLAGS: -Wall
static int warning_function(void) {
int unused;
return 0;
}
*/
import "C"
func F() int { return int(C.warning_function()) }Then run:
`GOCACHE=/tmp/go-cache GO_BUILDER_NAME= go build . `
The build succeeds and stores the cgo compile result in the cache.
Using the same cache, run:
GOCACHE=/tmp/go-cache GO_BUILDER_NAME=builder go build .
What did you see happen?
The second command succeeds.
With an empty cache, the same command fails as expected:
warning: unused variable 'unused'
C compiler warning promoted to error on Go buildersWith the shared cache, go build -x shows that the C compiler output is copied from the cache instead of being compiled again. This bypasses the warning-to-error check in cmd/go/internal/work.ccompile.
What did you expect to see?
The second command should fail in the same way as a cold-cache build, because GO_BUILDER_NAME changes whether C compiler warnings are treated as errors.
The Go builder mode should therefore be represented in the cgo compile action ID, or the cgo compile cache should otherwise distinguish these two modes.
Activity
cuishuang commentedon Aug 23, 2026
The issue became observable after cgo compile actions started being cached independently. The relevant code is:
src/cmd/go/internal/work/exec.go: cgoCompileActionID ccompileA minimal fix is to include the boolean Go-builder mode in the cgo compile action ID.
I fix it in https://go-review.googlesource.com/c/go/+/819860
gopherbot commentedon Aug 23, 2026
Change https://go.dev/cl/819860 mentions this issue:
cmd/go: include Go builder mode in cgo compile cache keygabyhelp commentedon Aug 23, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
dr2chase commentedon Aug 28, 2026
@golang/go-command
cherrymui commentedon Aug 28, 2026
I don't think this, as well as the fix, is desirable. We want to test Go on builders as much as when user uses it for real. GO_BUILDER_NAME is often used for opting in stricter checks, and sometimes for addressing builder limitations. But it should not be a mechanism for diverging the behavior.
In general, GO_BUILDER_NAME is meant for builder only. Setting it by hand is not a supported use case.
It is probably true that repeated builds should behave the same, whether GO_BUILDER_NAME set or not. If the first build fails, it probably should not be cached at all. Why is it cached? I think we usually don't cache failed build.