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

Closed
dylan-bourque opened this issue Mar 2, 2022 · 5 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Milestone

Comments

@dylan-bourque
Copy link

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 2, 2022
@bcmills bcmills added this to the Go1.19 milestone Mar 2, 2022
@bcmills
Copy link
Contributor

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 cmd/go label Mar 2, 2022
@dylan-bourque
Copy link
Author

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.

@bcmills
Copy link
Contributor

bcmills commented Nov 9, 2022

I suspect that there may still be some related bugs in how we attribute errors for various failure modes, but it's been long enough that I don't expect to be able to chase this one down based on the original reproducer. 😞

I'm definitely still interested in fixing these bugs, but I'm going to close this particular issue as “probably not a productive avenue of investigation any more”.

@gopherbot
Copy link

Change https://go.dev/cl/448996 mentions this issue: slices: add old build constraint syntax to help old go versions

@gopherbot
Copy link

Change https://go.dev/cl/449175 mentions this issue: x/vuln/internal: add old build constraint syntax

gopherbot pushed a commit to golang/vuln that referenced this issue Nov 9, 2022
When a project transitively depends on x/vuln/internal,
go1.16 is confused and fails with errors like

"//go:build comment without // +build comment"

Even when conditionally import x/vuln/internal only for go1.18+,
this error is unavoidable.
Let's wait a bit longer and help users who are stuck with old go.

Updates golang/go#51436

Change-Id: I22fce4c037bef3621800a7cca31d31938025078a
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/449175
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopherbot pushed a commit to golang/exp that referenced this issue Nov 9, 2022
When a project transitively depends on x/exp/slices,
go1.16 is confused and fails with errors like:

"//go:build comment without // +build comment"

Even when import of x/exp/slices guarded with build tags, so this
is imported only when compiling with go1.18, this error is unavoidable.
Let's wait a bit longer and help users who are stuck with old go.

Updates golang/go#51436

Change-Id: I7ba589644475f55585c11ba1f7650c5ede6bc637
Reviewed-on: https://go-review.googlesource.com/c/exp/+/448996
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
sudo-suhas added a commit to goto/meteor that referenced this issue Mar 16, 2023
sudo-suhas added a commit to goto/meteor that referenced this issue Mar 16, 2023
sudo-suhas added a commit to goto/meteor that referenced this issue Mar 16, 2023
sudo-suhas added a commit to goto/meteor that referenced this issue Mar 16, 2023
- Upgrade Go version to 1.20. Go 1.16 has a bug that causes build
  failure (ex:
  https://github.com/goto/meteor/actions/runs/4434675833/jobs/7780899433#step:4:435).
  Go issue - golang/go#51436
softdev050 added a commit to softdev050/Golangvuln that referenced this issue Apr 5, 2023
When a project transitively depends on x/vuln/internal,
go1.16 is confused and fails with errors like

"//go:build comment without // +build comment"

Even when conditionally import x/vuln/internal only for go1.18+,
this error is unavoidable.
Let's wait a bit longer and help users who are stuck with old go.

Updates golang/go#51436

Change-Id: I22fce4c037bef3621800a7cca31d31938025078a
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/449175
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
sayjun0505 added a commit to sayjun0505/Golangvuln that referenced this issue Apr 8, 2023
When a project transitively depends on x/vuln/internal,
go1.16 is confused and fails with errors like

"//go:build comment without // +build comment"

Even when conditionally import x/vuln/internal only for go1.18+,
this error is unavoidable.
Let's wait a bit longer and help users who are stuck with old go.

Updates golang/go#51436

Change-Id: I22fce4c037bef3621800a7cca31d31938025078a
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/449175
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
stanislavkononiuk added a commit to stanislavkononiuk/Golangvuln that referenced this issue Jun 26, 2023
When a project transitively depends on x/vuln/internal,
go1.16 is confused and fails with errors like

"//go:build comment without // +build comment"

Even when conditionally import x/vuln/internal only for go1.18+,
this error is unavoidable.
Let's wait a bit longer and help users who are stuck with old go.

Updates golang/go#51436

Change-Id: I22fce4c037bef3621800a7cca31d31938025078a
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/449175
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
@golang golang locked and limited conversation to collaborators Nov 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Projects
None yet
Development

No branches or pull requests

3 participants