Go Build Tags: Difference between revisions
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
package somepkg | package somepkg | ||
</syntaxhighlight> | |||
=Providing Tags on Command Line= | |||
<syntaxhighlight lang='bash'> | |||
go build|test -tags=tag_a | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 22:19, 7 March 2024
Internal
Overview
A build tag is an identifier added to a piece of code that determines when the file should be including in a package during the build process.
Build tags provide conditional compilation in Go. Go does not have a preprocessor, a macro system, or a #define declaration to control the inclusion of platform-specific code, it uses build tags instead.
Build tags are implemented as comments which must appear at the top of the file in any source file (not just go files). To differentiate between the package and build tags, there must be a blank line between them:
// +build tag_a tag_b
package somepkg
Providing Tags on Command Line
go build|test -tags=tag_a
Combining Tags
Multiple tags are supported, and they can be combined using an OR, AND or NOT logic.