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: suggestion to fail to build, or emit warning, on unused build tags #47020

dans-stuff opened this issue Jul 1, 2021 · 2 comments
FeatureRequest GoCommand NeedsInvestigation


Copy link

@dans-stuff dans-stuff commented Jul 1, 2021

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

$ go version
go version go1.16.3 darwin/arm64

What did you expect to see?

I added a build tag (specifically go build -tags lambda.norpc), which is a build tag honored by

However, it just so happened that the build tag was introduced in a version later than the version I had pinned. My go mod had v1.13, the build tag was introduced in v1.18

This was incredibly difficult to discover, therefor I am suggesting that passing a build tag should produce an error if that build tag is not found anywhere. At least a warning should be displayed, if not failing the build entirely.

Copy link

@ianlancetaylor ianlancetaylor commented Jul 1, 2021

I think this would be fairly difficult in practice. For example there is a standard library build tag osusergo, used only by the "os/user" package. Some people routinely build with go build -tags=osusergo. They don't want the build to fail just because the specific program they happen to be building doesn't import the "os/user" package.

Copy link

@dans-stuff dans-stuff commented Jul 2, 2021

@ianlancetaylor Good to know! Perhaps a list of known common build tags could be omitted from the check? Normally I feel something like this would be in go vet but as it's a build argument, there's no way to include it there.

Conversely, if the tags are not found during normal compilation, a scan could be performed of all relevant source codes - all of stdlib, all of vendor - and if it is still not found that could be cause for a build failure? The problem you mentioned would still exist but in much rarer cases, perhaps rare enough that it is unlikely to have happened.

Edit: Random idea, but a vet flag for build could be a very cool addition. go build -vet could fail on all normal vet conditions, as well as some extras that only occur during a build.

@dmitshur dmitshur added FeatureRequest GoCommand NeedsInvestigation labels Jul 2, 2021
@dmitshur dmitshur changed the title Suggestion: Fail to build, or emit warning, on unused build tags cmd/go: suggestion to fail to build, or emit warning, on unused build tags Jul 2, 2021
@dmitshur dmitshur added this to the Backlog milestone Jul 2, 2021
@jayconrod jayconrod removed this from the Backlog milestone Jul 12, 2021
@jayconrod jayconrod added this to the Unplanned milestone Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
FeatureRequest GoCommand NeedsInvestigation
None yet

No branches or pull requests

4 participants