From 5c9a506de17bdeb692e6e12d5ab56a06c11b042c Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Mon, 21 Nov 2022 22:12:15 -0500 Subject: [PATCH] cmd/go: remove special case for prebuilt cgo library cache keys This was an oversight from CL 452457 that I noticed while investigating #56889. This change essentially undoes CL 335409, which is no longer needed after CL 450739 because we no longer attempt to use cgo by default when no C compiler is present. Updates #47257. Updates #40042. Updates #47215. Change-Id: I29c7ce777a9ec7ba5820dc1d836b12a61b86bc37 Reviewed-on: https://go-review.googlesource.com/c/go/+/452677 Auto-Submit: Bryan Mills Reviewed-by: Russ Cox TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills --- src/cmd/go/internal/work/exec.go | 9 ++------- .../testdata/script/cgo_stale_precompiled.txt | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 7569935926..8c143e4588 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -278,13 +278,8 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { fmt.Fprintf(h, "CC=%q %q %q %q\n", ccExe, cppflags, cflags, ldflags) // Include the C compiler tool ID so that if the C // compiler changes we rebuild the package. - // But don't do that for standard library packages like net, - // so that the prebuilt .a files from a Go binary install - // don't need to be rebuilt with the local compiler. - if !p.Standard { - if ccID, _, err := b.gccToolID(ccExe[0], "c"); err == nil { - fmt.Fprintf(h, "CC ID=%q\n", ccID) - } + if ccID, _, err := b.gccToolID(ccExe[0], "c"); err == nil { + fmt.Fprintf(h, "CC ID=%q\n", ccID) } if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 { cxxExe := b.cxxExe() diff --git a/src/cmd/go/testdata/script/cgo_stale_precompiled.txt b/src/cmd/go/testdata/script/cgo_stale_precompiled.txt index e446758ed8..eb7e10557b 100644 --- a/src/cmd/go/testdata/script/cgo_stale_precompiled.txt +++ b/src/cmd/go/testdata/script/cgo_stale_precompiled.txt @@ -16,13 +16,21 @@ go build -x runtime/cgo [!short] stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo' -# https://go.dev/issue/47215: a missing $(go env CC) caused the precompiled net to be stale. -[!GOOS:plan9] env PATH='' # Guaranteed not to include $(go env CC)! -[GOOS:plan9] env path='' -go build -x runtime/cgo -! stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo' - # https://go.dev/issue/50183: a mismatched GOROOT_FINAL caused net to be stale. +env oldGOROOT_FINAL=$GOROOT_FINAL env GOROOT_FINAL=$WORK${/}goroot go build -x runtime/cgo ! stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo' + +env GOROOT_FINAL=$oldGOROOT_FINAL + +# https://go.dev/issue/47215: a missing $(go env CC) caused the precompiled net +# to be stale. But as of https://go.dev/cl/452457 the precompiled libraries are +# no longer installed anyway! Since we're requiring a C compiler in order to +# build and use cgo libraries in the standard library, we should make sure it +# matches what's in the cache. +[!abscc] env CGO_ENABLED=1 +[!abscc] [!GOOS:plan9] env PATH='' # Guaranteed not to include $(go env CC)! +[!abscc] [GOOS:plan9] env path='' +[!abscc] ! go build -x runtime/cgo +[!abscc] stderr 'C compiler .* not found' -- 2.50.0