go_library
A go_library() rule builds a native library from the supplied set of Go source files and dependencies.
Function Signature
def go_library(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_build_tags: list[str] = [],
_cgo_enabled: None | bool = select({"prelude//go/constraints:cgo_enabled_false": False, "prelude//go/constraints:cgo_enabled_true": True, "DEFAULT": None}),
_coverage_mode: None | str = select({"prelude//go/constraints:coverage_mode_atomic": "atomic", "prelude//go/constraints:coverage_mode_count": "count", "prelude//go/constraints:coverage_mode_set": "set", "DEFAULT": None}),
_cxx_toolchain: str = "gh_facebook_buck2_shims_meta//:cxx",
_exec_os_type: str = "prelude//os_lookup/targets:os_lookup",
_go_stdlib: str = "prelude//go/tools:stdlib",
_go_toolchain: str = "gh_facebook_buck2_shims_meta//:go",
assembler_flags: list[str] = [],
compiler_flags: list[str] = [],
contacts: list[str] = [],
cxx_compiler_flags: list[str] = [],
cxx_preprocessor_flags: list[str] = [],
default_host_platform: None | str = None,
deps: list[str] = [],
embedcfg: None | str = None,
external_linker_flags: list[str] = [],
generate_exported_header: bool = False,
header_namespace: None | str = None,
headers: list[str] | dict[str, str] = [],
labels: list[str] = [],
licenses: list[str] = [],
link_style: None | str = None,
override_cgo_enabled: None | bool = None,
package_name: None | str = None,
package_root: None | str = None,
srcs: list[str] = [],
) -> None
Parameters
-
name: (required)name of the target
-
default_target_platform: (defaults to:None)specifies the default target platform, used when no platforms are specified on the command line
-
target_compatible_with: (defaults to:[])a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
compatible_with: (defaults to:[])a list of constraints that are required to be satisfied for this target to be compatible with a configuration
-
exec_compatible_with: (defaults to:[])a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
-
visibility: (defaults to:[])a list of visibility patterns restricting what targets can depend on this one
-
within_view: (defaults to:["PUBLIC"])a list of visibility patterns restricting what this target can depend on
-
metadata: (defaults to:{})a key-value map of metadata associated with this target
-
tests: (defaults to:[])a list of targets that provide tests for this one
-
modifiers: (defaults to:[])an array of modifiers associated with this target
-
assembler_flags: (defaults to:[])The set of additional assembler flags to pass to
go tool asm. -
compiler_flags: (defaults to:[])The set of additional compiler flags to pass to
go tool compile. -
contacts: (defaults to:[])A list of organizational contacts for this rule. These could be individuals who you would contact in the event of a failure or other issue with the rule.
contacts = [ 'Joe Sixpack', 'Erika Mustermann' ] -
cxx_compiler_flags: (defaults to:[])GCC/Clang flags to use when compiling any of the above C/C++ sources (which require compilation).
-
cxx_preprocessor_flags: (defaults to:[])GCC/Clang flags to use when preprocessing any of the above C/C++ sources (which require preprocessing).
-
deps: (defaults to:[])The set of dependencies of this rule. Currently, this only supports go_library rules.
-
external_linker_flags: (defaults to:[])Extra external linker flags passed to go link via
-extldargument. -
generate_exported_header: (defaults to:False)Generate header file with declaration for functions exported with
//exportThe header name for targetcell//foo/bar:libwill befoo/bar/lib.h -
header_namespace: (defaults to:None)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. Seeheadersfor more information. -
headers: (defaults to:[])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_NAMESPACEis the value of the target'sheader_namespaceattribute, and$HEADER_NAMEis the header name if specified, and the filename of the header file otherwise. Seeheader_namespacefor more information. -
labels: (defaults to:[])Set of arbitrary strings which allow you to annotate a build rule with tags that can be searched for over an entire dependency tree using
buck query(). -
licenses: (defaults to:[])Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query
-
link_style: (defaults to:None)Determines whether to build and link this rule's dependencies statically or dynamically. Can be one of the following values:
static,static_picorshared. This argument is relevant only if the cgo extension is enabled. Otherwise, Buck ignores this argument. -
override_cgo_enabled: (defaults to:None)Per-target analog of CGO_ENABLED env-var, overrides its value for the target, but not for its dependencies.
-
package_name: (defaults to:None)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: (defaults to:None)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"
-
srcs: (defaults to:[])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
#included by the assembler.
Examples
For more examples, check out our integration tests.
go_library(
name='greeting',
srcs=[
'greeting.go',
],
deps=[
':join',
],
)