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: Builds using go1.16.x report an ambiguous error when an imported dependency contains '//go:build' but not '// +build' #51436

Open
dylan-bourque opened this issue Mar 2, 2022 · 2 comments
Assignees
Labels
GoCommand NeedsInvestigation
Milestone

Comments

@dylan-bourque
Copy link

@dylan-bourque dylan-bourque commented Mar 2, 2022

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

$ go version
go version go1.16.7 darwin/amd64

Does this issue reproduce with the latest release?

No. Both go1.17 and go1.18rc1 work correctly.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dbourque/Library/Caches/go-build"
GOENV="/Users/dbourque/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/dbourque/sdk/modcache"
GOOS="darwin"
GOPATH="/Users/dbourque/dev/golang"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/dbourque/sdk/go1.16.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/dbourque/sdk/go1.16.7/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.7"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/var/folders/3t/4048hqr5459dw83ksmkqxn7r0000gn/T/tmp.VldrLY60/go.mod"
CGO_CFLAGS=""
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="/usr/local/bin/pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3t/4048hqr5459dw83ksmkqxn7r0000gn/T/go-build405126792=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Several of our internal modules at work have recently started failing to build with an error that says nothing more than //go:build comment without // +build comment. We were able to determine that the error only happens for things that are still on Go 1.16.x and upgrading them to 1.17 made the error go away.

Further digging revealed that the actual problem was within the bitbucket.org/bertimus9/systemstat module, which removed // +build directive comments with this commit, purportedly to "update to play nice with go 1.17".

The snippet below is a minimal reproducible example (included here because go.dev/play doesn't seem to have an option to use go1.16.x):

package main

import (
	"fmt"

	"bitbucket.org/bertimus9/systemstat"
)

func main() {
	var v systemstat.CPUAverage

	fmt.Printf("%v\n", v)
}

Attempting to build the code above generates the following error when using Go 1.16.x:

$go run main.go
main.go:6:2: //go:build comment without // +build comment

The behavior is correct according to this proposal, but the error message gives no indication that the missing // +build directive inside of a dependency. Instead it shows the source/line information for the import of the "bad" package.

What did you expect to see?

An error with the source/line information pointing to the dependency's code, where the problem actually exists.

What did you see instead?

An error with the source/line information pointing at my own code with no explanation that the issue actually exists elsewhere.

@bcmills bcmills self-assigned this Mar 2, 2022
@bcmills bcmills added the NeedsInvestigation label Mar 2, 2022
@bcmills bcmills added this to the Go1.19 milestone Mar 2, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Mar 2, 2022

I'd like to figure out whether this also affects Go at tip (perhaps in a different form). If it doesn't, then this probably isn't worth fixing (since Go 1.16 is EOL in about a month), but the root cause may point to a similar or different symptom of a problem that still exists.

@bcmills bcmills added the GoCommand label Mar 2, 2022
@dylan-bourque
Copy link
Author

@dylan-bourque dylan-bourque commented Mar 2, 2022

Agreed. I don't think it needs to be addressed for 1.16.x given that 1.18 is due to be released presently (rc1 is available as I post this), but the abstract issue of the error not showing the "correct" source/line info is valid and should be addressed if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

2 participants