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: 'go test' and 'go vet' require GCC even when 'go build' does not #56755

Closed
candlerb opened this issue Nov 16, 2022 · 1 comment
Closed
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@candlerb
Copy link

candlerb commented Nov 16, 2022

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

$ go version
go version go1.19.3 linux/amd64

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="amd64"
GOBIN=""
GOCACHE="/home/brian/.cache/go-build"
GOENV="/home/brian/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/brian/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/brian/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/brian/repro/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2864122989=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This is tested inside an Ubuntu 22.04 lxd container, started from images:ubuntu/22.04/cloud. This provides the "ubuntu-minimal" distribution, which doesn't have gcc / build-essential packages installed by default.

-- go.mod --
module example.com/repro

go 1.19

-- main.go --
package main

import _ "net/http"

func main() {
}

-- main_test.go --
package main

import "testing"

func TestFoo(t *testing.T) {
}

Then in this directory:

$ go run .
$ go test .
$ go vet .

What did you expect to see?

All these commands to succeed.

What did you see instead?

go build . succeeds, but go test . and go vet . fail.

$ go build .
$ go test .
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
FAIL	example.com/repro [build failed]
FAIL
$ go vet .
# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
$ 

Additional info

I have found that:

  • go test -vet=off . works
  • If you comment out the import of net/http, then go test . works.
  • If you change the import from net/http to net/netip, then go test . works
  • If you change the import from net/http to net, then go test . still fails
  • Running go mod tidy makes no difference

Therefore this appears to be something to do with importing specific net libraries in the presence of go vet

I expect most people don't notice this because most developers do have gcc installed.

Workaround

CGO_ENABLED=0 go test .

or:

go test -vet=off .

I don't like the first option, because it makes me worry that the artefact from go build is different to the one being tested. I guess I could also use CGO_ENABLED=0 go build . to ensure the build product is consistent.

I don't like the second one because I lose the vet checks.

But splitting vet and test looks to be a reasonable solution:

CGO_ENABLED=0 go vet
go test -vet=off .

Linked / related issues

Forked from #28065 on request. See also #27639, #27303.

This new issue removes any ambiguity around Alpine Linux / musl libc or GOPATH mode; neither is relevant.

@candlerb candlerb changed the title cmd/go: 'go test' and go vet require GCC even when go build does not cmd/go: 'go test' and 'go vet' require GCC even when 'go build' does not Nov 16, 2022
@bcmills bcmills added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 16, 2022
@bcmills bcmills added this to the Backlog milestone Nov 16, 2022
5HT2 added a commit to effectindex/tripreporter that referenced this issue Apr 25, 2023
5HT2 added a commit to effectindex/tripreporter that referenced this issue Apr 25, 2023
@candlerb
Copy link
Author

With go1.20 this now works as expected - thanks to clue in comment here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants