please icon indicating copy to clipboard operation
please copied to clipboard

Support for go build flags...

Open sean- opened this issue 7 years ago • 6 comments

This is pretty simple but I couldn't figure it out:

// +build foo

package main

func main() {
}

How do I pass in the foo build tag when building a Go library/binary, etc?

sean- avatar Jan 14 '19 07:01 sean-

Hmmm good spot, we do seem to be missing that. How silly, we have the tool and it supports taking extra tags, they're just not plumbed through :) Should be easy to add.

peterebden avatar Jan 14 '19 09:01 peterebden

It seemed curious and like I must have been missing something or it isn't supported. :)

sean- avatar Jan 15 '19 09:01 sean-

OK I take that back, this is a surprisingly deep rabbit hole. #534 works about 90% but coverage (and I suspect cgo) fail because they don't know how to re-filter the sources (and irritatingly you have to repeat the tags argument on the tests too).

The correct fix to that seems to be to do the filtering in the source rule underneath each library. I think that would solve most of the above, but fails when sources are generated because it's no longer a filegroup (and so now there are two nontrivial rules outputting the same file).

I guess solving it really needs some kind of hybrid filegroup rule where we can still do something dynamic to filter down its sources.

peterebden avatar Jan 17 '19 09:01 peterebden

Ick. Hrm. Could you add a visitor callback to the filegroup struct that reevaluates the filegroup everytime the list of srcs is queried?

This isn't a critical bug for us - I have removed all of our build tags for the time being and am relying on logic in BUILD instead. This only flares up as an issue when someone cd foo/bar && go build and we have files with different build tags. Currently we have different BUILD targets but we want to be able to plz export and have that workflow "just work."

sean- avatar Jan 17 '19 14:01 sean-

This issue has been automatically marked as stale because it has not had any recent activity in the past 90 days. It will be closed if no further activity occurs. If you require additional support, please reply to this message. Thank you for your contributions.

stale[bot] avatar Aug 17 '20 13:08 stale[bot]

With the move to the go plugins, would it be appropriate to move this issue to the please-build/go-rules repo?

In particular, I am trying to use the go_repo rules and have need to set build flags/tags (e.g. noasm) for certain modules. I'd be happy to open a fresh/specific issue there and simply refer back to this one if that makes more sense.

numbsafari avatar Nov 02 '23 13:11 numbsafari