Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go build with multiple tags

Tags:

go

build

tags

As seen here, go build accepts a "tags" flag that will include files that are "tagged," i.e.

// +build foo

package main

....

will be excluded from

go build

but included in

go build -tags=foo

Is there a way to include multiple tags? I.e.

go build -tags=foo && bar
like image 242
ryebread Avatar asked Oct 06 '16 22:10

ryebread


People also ask

What are build tags in go?

Developer and author at DigitalOcean. In Go, a build tag, or a build constraint, is an identifier added to a piece of code that determines when the file should be included in a package during the build process.

How to run a test only for the build tags?

So if you want to run the test only for the build tags func_test then you need to provide a different tag for the other tests. Here is an example: I have following 2 test files in my test directory.

What is the difference between releasetags and buildtags in go?

// ReleaseTags defaults to the list of Go releases the current release is compatible with. // BuildTags is not set for the Default build Context. // In addition to the BuildTags, ToolTags, and ReleaseTags, build constraints // consider the values of GOARCH and GOOS as satisfied tags.

How to include code in the compiled source using go build?

When running the go build command, we can use the -tags flag to conditionally include code in the compiled source by adding the tag itself as an argument. Let’s do this for the pro tag: Now we only get the extra features when we build the application using the pro build tag.


2 Answers

Multiple tags can be included in a space separated list:

go build -tags="foo bar"
like image 125
Tim Cooper Avatar answered Sep 26 '22 22:09

Tim Cooper


You should prefer including multiple tags in a comma separated list:

go build -tags=a,b

From Go 1.13 release notes:

The go build flag -tags now takes a comma-separated list of build tags, to allow for multiple tags in GOFLAGS. The space-separated form is deprecated but still recognized and will be maintained.

like image 27
AlexLiesenfeld Avatar answered Sep 26 '22 22:09

AlexLiesenfeld