Skip to content

cmd/go: cgo compile cache ignores Go builder warning policy #81039

Open

Description

@cuishuang

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 builders

With 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

  1. cuishuang commented on Aug 23, 2026

    @cuishuang
    ContributorAuthor

    The issue became observable after cgo compile actions started being cached independently. The relevant code is:

        src/cmd/go/internal/work/exec.go:
        cgoCompileActionID
        ccompile

    A 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

  2. gopherbot commented on Aug 23, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/819860 mentions this issue: cmd/go: include Go builder mode in cgo compile cache key

  3. dr2chase commented on Aug 28, 2026

    @dr2chase
    Contributor

    @golang/go-command

  4. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Aug 28, 2026
  5. cherrymui commented on Aug 28, 2026

    @cherrymui
    Member

    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.

    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.

  6. added
    cgoIssues affecting runtime/cgo and cmd/go
    on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.cgoIssues affecting runtime/cgo and cmd/go

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions