go_binary
A Go binary.
Backend: pants.backend.experimental.go
asan
bool | NoneNoneEnable interoperation between Go code and the C/C++ "address sanitizer."
See https://github.com/google/sanitizers/wiki/AddressSanitizer for additional information about the C/C++ address sanitizer.
assembler_flags
Iterable[str] | NoneNoneExtra flags to pass to the Go assembler (i.e., go tool asm) when assembling Go-format assembly code.
Note: These flags will not be added to gcc/clang-format assembly that is assembled in packages using Cgo.
This field can be specified on several different target types:
-
On
go_modtargets, the assembler flags are used when building any package involving the module including both first-party (i.e.,go_packagetargets) and third-party dependencies. -
On
go_binarytargets, the assembler flags are used when building any packages comprising that binary including third-party dependencies. These assembler flags will be added after any assembler flags added by anyassembler_flagsfield set on the applicablego_modtarget. -
On
go_packagetargets, the assembler flags are used only for building that specific package and not for any other package. These assembler flags will be added after any assembler flags added by anyassembler_flagsfield set on the applicablego_modtarget or applicablego_binarytarget.
Run go doc cmd/asm to see the flags supported by go tool asm.
cgo_enabled
bool | NoneNoneEnable Cgo support, which allows Go and C code to interact. This option must be enabled for any packages making use of Cgo to actually be compiled with Cgo support.
This field can be specified on several different target types, including go_binary and go_mod target types. If this field is specified on a go_binary target, then that instance takes precedence over other configuration when building the applicable executable. The applicable go_mod target will be checked next as a fallback. Finally, if neither target specifies this field, then the value will be taken from the value of the [golang].cgo_enabled option. (Note: That option will be deprecated in a future Pants version.)
See https://go.dev/blog/cgo and https://pkg.go.dev/cmd/cgo for additional information about Cgo.
compiler_flags
Iterable[str] | NoneNoneExtra flags to pass to the Go compiler (i.e., go tool compile) when compiling Go code.
This field can be specified on several different target types:
-
On
go_modtargets, the compiler flags are used when compiling any package involving the module including both first-party (i.e.,go_packagetargets) and third-party dependencies. -
On
go_binarytargets, the compiler flags are used when compiling any packages comprising that binary including third-party dependencies. These compiler flags will be added after any compiler flags added by anycompiler_flagsfield set on the applicablego_modtarget. -
On
go_packagetargets, the compiler flags are used only for compiling that specific package and not for any other package. These compiler flags will be added after any compiler flags added by anycompiler_flagsfield set on the applicablego_modtarget or applicablego_binarytarget.
Run go doc cmd/compile to see the flags supported by go tool compile.
description
str | NoneNoneA human-readable description of the target.
Use pants list --documented :: to see all targets with descriptions.
environment
str | None'__local__'Specify which environment target to consume environment-sensitive options from.
Once environments are defined in [environments-preview].names, you can specify the environment for this target by its name. Any fields that are defined in that environment will override the values from options set by pants.toml, command line values, or environment variables.
You can specify multiple valid environments by using parametrize. If __local__ is specified, Pants will fall back to the local_environment defined for the current platform, or no environment if no such environment exists.
linker_flags
Iterable[str] | NoneNoneExtra flags to pass to the Go linker (i.e., go tool link) when linking Go binaries.
This field can be specified on several different target types:
-
On
go_modtargets, the linker flags are used when linking any binary involving the module including bothgo_binarytargets and test binaries forgo_packagetargets within the module. -
On
go_binarytargets, the linker flags are used when linking that binary. These linker flags will be added after any linker flags added by anylinker_flagsfield set on the applicablego_modtarget.
Run go doc cmd/link to see the flags supported by go tool link.
main
str | NoneNoneAddress of the go_package with the main for this binary.
If not specified, will default to the go_package for the same directory as this target's BUILD file. You should usually rely on this default.
msan
bool | NoneNoneEnable interoperation between Go code and the C/C++ "memory sanitizer."
See https://github.com/google/sanitizers/wiki/MemorySanitizer for additional information about the C/C++ memory sanitizer.
output_path
str | NoneNoneWhere the built asset should be located.
If undefined, this will use the path to the BUILD file, followed by the target name. For example, src/python/project:app would be src.python.project/app.ext.
When running pants package, this path will be prefixed by --distdir (e.g. dist/).
Warning: setting this value risks naming collisions with other package targets you may have.
race
bool | NoneNoneEnable compiling the binary with the Go data race detector.
See https://go.dev/doc/articles/race_detector for additional information about the Go data race detector.
restartable
boolFalseIf true, runs of this target with the run goal may be interrupted and restarted when its input files change.
tags
Iterable[str] | NoneNoneArbitrary strings to describe a target.
For example, you may tag some test targets with 'integration_test' so that you could run pants --tag='integration_test' test :: to only run on targets with that tag.