go: support enabling additional build tags
go supports enabling extra build tags while building via the -tags argument to go build. This behavior should be made available in Pants. Could be modeled as a build_tags field on go_binary.
I'd like to add support for this!
But, I have a question first. I've got a project that uses build constraints in two ways:
- There are some tests that should only build when specified (for acceptance tests).
- There are some tools that should only be built when using them (for a generator).
To that end, I'm curious why it would be on a go_binary rather than both go_binary and go_package? It seems like it breaks the locality of knowing what a target is going to do by only allowing it on a go_binary.
I can provide some more explanation of what I'm thinking. But I'll hold off for now, in case it's not necessary.
To that end, I'm curious why it would be on a go_binary rather than both go_binary and go_package? It seems like it breaks the locality of knowing what a target is going to do by only allowing it on a go_binary.
I can provide some more explanation of what I'm thinking. But I'll hold off for now, in case it's not necessary.
I wrote that suggestion before I performed further work on the Go backend. A build_tags field seems similar to the compiler_flags field which exists on go_package, go_binary, and go_mod. build_tags should probably be treated similarly. See https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/go/util_rules/build_opts.py.
Agreed this is much needed. We have tests that only run if a particular build flag is set. Without a build flag set pants reports an error building such a test package:
12:19:45.10 [ERROR] Failed to analyze monorepo/pkg/api-regression/service-one for dependency inference:
no buildable Go source files in golang/pkg/api-regression/service-one