go_binary
name
def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_apple_platforms: dict[str, str] = ...,
_asan: bool = ...,
_build_info: dict[str, typing.Any] = ...,
_build_tags: list[str] = ...,
_cxx_toolchain: str = ...,
_exec_os_type: str = ...,
_go_stdlib: str = ...,
_go_toolchain: str = ...,
_race: bool = ...,
asan: bool = ...,
assembler_flags: list[str] = ...,
build_tags: list[str] = ...,
cgo_enabled: None | bool = ...,
compiler_flags: list[str] = ...,
contacts: list[str] = ...,
cxx_compiler_flags: list[str] = ...,
cxx_preprocessor_flags: list[str] = ...,
default_host_platform: None | str = ...,
deps: list[str] = ...,
embedcfg: None | str = ...,
external_linker_flags: list[str] = ...,
header_namespace: None | str = ...,
headers: list[str] | dict[str, str] = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
link_mode: None | str = ...,
link_style: None | str = ...,
linker_flags: list[str] = ...,
package_name: None | str = ...,
package_root: None | str = ...,
platform: None | str = ...,
race: bool = ...,
resources: list[str] = ...,
srcs: list[str] = ...,
) -> None
A go_binary() rule builds a native executable from the supplied set of Go source files and dependencies. The files supplied are expected to be in the main package, implicitly.
Parameters
name
: name of the targetdefault_target_platform
: specifies the default target platform, used when no platforms are specified on the command linetarget_compatible_with
: a list of constraints that are required to be satisfied for this target to be compatible with a configurationcompatible_with
: a list of constraints that are required to be satisfied for this target to be compatible with a configurationexec_compatible_with
: a list of constraints that are required to be satisfied for this target to be compatible with an execution platformvisibility
: a list of visibility patterns restricting what targets can depend on this onewithin_view
: a list of visibility patterns restricting what this target can depend onmetadata
: a key-value map of metadata associated with this targettests
: a list of targets that provide tests for this onemodifiers
: an array of modifiers associated with this target_build_info
: Build info that is passed along here will be late-stamped into a fb_build_info section on the output binaryasan
: If true, enable ASAN.assembler_flags
: The set of additional assembler flags to pass togo tool asm
.build_tags
: Build tags to apply to this target and its dependencies.cgo_enabled
: Analog of CGO_ENABLED env-var, applies to this target and its dependencies. If None it will depend on the availability of CXX toolchain.compiler_flags
: The set of additional compiler flags to pass togo tool compile
.cxx_compiler_flags
: GCC/Clang flags to use when compiling any of the above C/C++ sources (which require compilation).cxx_preprocessor_flags
: GCC/Clang flags to use when preprocessing any of the above C/C++ sources (which require preprocessing).deps
: The set of dependencies of this rule. Currently, this only supports go_library rules.external_linker_flags
: Extra external linker flags passed to go link via-extld
argument.header_namespace
: A path prefix when including headers of this target. Defaults to the path from the root of the repository to the directory where this target is defined. Can contain forward slashes (/
), but cannot start with one. Seeheaders
for more information.headers
: The set of header files that are made available for inclusion to the source files in this target. These should be specified as either a list of header files or a dictionary of header names to header files. The header name can contain forward slashes (/
). The headers can be included with#include "$HEADER_NAMESPACE/$HEADER_NAME"
or#include <$HEADER_NAMESPACE/$HEADER_NAME>
, where$HEADER_NAMESPACE
is the value of the target'sheader_namespace
attribute, and$HEADER_NAME
is the header name if specified, and the filename of the header file otherwise. Seeheader_namespace
for more information.link_mode
: Determines the link mode (equivalent of-mode
). Can be one of the following values:internal
,external
. If no value is provided, the mode is set automatically depending on the other args.link_style
: Determines whether to build and link this rule's dependencies statically or dynamically. Can be one of the following values:static
,static_pic
orshared
. This argument is relevant only if the cgo extension is enabled. Otherwise, Buck ignores this argument.linker_flags
: Extra linker flags passed to go linkpackage_name
: Sets the full name of the package being compiled. This defaults to the path from the buck root. (e.g. given a ./.buckconfig, a rule in ./a/b/BUCK defaults to package "a/b")package_root
: Sets Go package direactory (relative to BUCK file). By default (or if None passes) package_root is being detected automatically. Empty string of Go package is on the same level as BUCK file otherwise the subdirectory name. Example for srcs = ["foo/bar.go"], package_root = "foo"race
: If true, enable data race detection.srcs
: The set of source files to be compiled by this rule. .go files will be compiled with the Go compiler, .s files will be compiled with the assembler, and everything else is assumed to be files that may be#include
d by the assembler.
Details
Examples:
For more examples, check out our integration tests.
go_binary(
name='greet',
srcs=[
'main.go',
],
deps=[
':greeting',
],
)
go_library(
name='greeting',
srcs=[
'greeting.go',
],
deps=[
':join',
],
)
go_library(
name='join',
srcs=[
'join.go',
],
)