pants icon indicating copy to clipboard operation
pants copied to clipboard

go: support enabling additional build tags

Open tdyas opened this issue 3 years ago • 3 comments

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.

tdyas avatar Nov 02 '22 18:11 tdyas

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:

  1. There are some tests that should only build when specified (for acceptance tests).
  2. 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.

joneshf avatar Apr 22 '23 17:04 joneshf

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.

tdyas avatar Apr 29 '23 20:04 tdyas

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

nickpalmer avatar Jan 17 '24 18:01 nickpalmer