Skip to main content
Version: 2.17 (deprecated)

go_mod


A first-party Go module (corresponding to a go.mod file).

Generates go_third_party_package targets based on the require directives in your go.mod.

If you have third-party packages, make sure you have an up-to-date go.sum. Run go mod tidy directly to update your go.mod and go.sum.

Backend: pants.backend.experimental.go


asan

bool | None
default: None

Enable 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] | None
default: None

Extra 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_mod targets, the assembler flags are used when building any package involving the module including both first-party (i.e., go_package targets) and third-party dependencies.

  • On go_binary targets, 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 any assembler_flags field set on the applicable go_mod target.

  • On go_package targets, 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 any assembler_flags field set on the applicable go_mod target or applicable go_binary target.

Run go doc cmd/asm to see the flags supported by go tool asm.

cgo_enabled

bool | None
default: None

Enable 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] | None
default: None

Extra 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_mod targets, the compiler flags are used when compiling any package involving the module including both first-party (i.e., go_package targets) and third-party dependencies.

  • On go_binary targets, 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 any compiler_flags field set on the applicable go_mod target.

  • On go_package targets, 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 any compiler_flags field set on the applicable go_mod target or applicable go_binary target.

Run go doc cmd/compile to see the flags supported by go tool compile.

description

str | None
default: None

A human-readable description of the target.

Use pants list --documented :: to see all targets with descriptions.

linker_flags

Iterable[str] | None
default: None

Extra 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_mod targets, the linker flags are used when linking any binary involving the module including both go_binary targets and test binaries for go_package targets within the module.

  • On go_binary targets, the linker flags are used when linking that binary. These linker flags will be added after any linker flags added by any linker_flags field set on the applicable go_mod target.

Run go doc cmd/link to see the flags supported by go tool link.

msan

bool | None
default: None

Enable 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.

race

bool | None
default: None

Enable 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.

tags

Iterable[str] | None
default: None

Arbitrary 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.