rust_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 = ...,
incoming_transition: None | str = ...,
_apple_platforms: dict[str, str] = ...,
_cxx_toolchain: str = ...,
_exec_os_type: str = ...,
_rust_internal_tools_toolchain: str = ...,
_rust_toolchain: str = ...,
_target_os_type: str = ...,
_workspaces: list[str] = ...,
allow_cache_upload: None | bool = ...,
anonymous_link_groups: bool = ...,
auto_link_groups: bool = ...,
clippy_configuration: None | str = ...,
contacts: list[str] = ...,
coverage: bool = ...,
crate: None | str = ...,
crate_root: None | str = ...,
default_host_platform: None | str = ...,
default_platform: None | str = ...,
deps: list[str] = ...,
edition: None | str = ...,
enable_distributed_thinlto: bool = ...,
env: dict[str, str] = ...,
features: list[str] = ...,
flagged_deps: list[(str, list[str])] = ...,
incremental_build_mode: None | str = ...,
incremental_enabled: bool = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
link_group: None | str = ...,
link_group_map: None | str | list[(str, list[(None | str | list[None | str], str, None | str | list[str], None | str)], None | dict[str, typing.Any])] = ...,
link_group_min_binary_node_count: None | int = ...,
link_style: None | str = ...,
linker_flags: list[str] = ...,
mapped_srcs: dict[str, str] = ...,
named_deps: list[(str, str)] | dict[str, str] = ...,
resources: list[str] | dict[str, str] = ...,
rpath: bool = ...,
rustc_flags: list[str] = ...,
rustdoc_flags: list[str] = ...,
separate_debug_info: bool = ...,
srcs: list[str] = ...,
) -> None
A rust_binary() rule builds a native executable from the supplied set of Rust source files and dependencies.
Parameters
-
name
: name of the target -
default_target_platform
: specifies the default target platform, used when no platforms are specified on the command line -
target_compatible_with
: a list of constraints that are required to be satisfied for this target to be compatible with a configuration -
compatible_with
: a list of constraints that are required to be satisfied for this target to be compatible with a configuration -
exec_compatible_with
: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform -
visibility
: a list of visibility patterns restricting what targets can depend on this one -
within_view
: a list of visibility patterns restricting what this target can depend on -
metadata
: a key-value map of metadata associated with this target -
tests
: a list of targets that provide tests for this one -
modifiers
: an array of modifiers associated with this target -
incoming_transition
: specifies the incoming transition to apply to this target -
_workspaces
: Internal implementation detail of Rust workspaces. This should not be set manually and will be replaced in favor of metadata in a future version of buck2. -
allow_cache_upload
: Whether to allow uploading the output of this rule to be uploaded to cache when the action is executed locally if the configuration allows (i.e. there is a cache configured and the client has permission to write to it). -
crate_root
: Set the name of the top-level source file for the crate, which can be used to override the default (seesrcs
). -
deps
: The set of dependencies of this rule. Currently, this supports rust_library and prebuilt_rust_library rules. -
edition
: Set the language edition to be used for this rule. Can be set to any edition the compiler supports (2018
right now). If unset it uses the compiler's default (2015
). -
env
: Set environment variables for this rule's invocations of rustc. The environment variable values may include macros which are expanded. -
features
: The set of features to be enabled for this rule.These are passed to
rustc
with--cfg feature="{feature}"
, and can be used in the code with#[cfg(feature = "{feature}")]
. -
link_style
: Determines whether to build and link this rule's dependencies statically or dynamically. Can be eitherstatic
,static_pic
orshared
. -
linker_flags
: The set of additional flags to pass to the linker. -
mapped_srcs
: Add source files along with a local path mapping. Rust is sensitive to the layout of source files, as the directory structure follows the module structure. However this is awkward if the source file is, for example, generated by another rule. In this case, you can set up a mapping from the actual source path to something that makes sense locally. For examplemapped_srcs = {":generate-module", "src/generated.rs" }
. These are added to the regularsrcs
, so a file should not be listed in both. -
named_deps
: Add crate dependencies and define a local name by which to use that dependency by. This allows a crate to have multiple dependencies with the same crate name. For example:named_deps = {"local_name", ":some_rust_crate" }
. The dependencies may also be non-Rust, but the alias is ignored. It has no effect on the symbols provided by a C/C++ library. -
rpath
: Set the "rpath" in the executable when using a shared link style. -
rustc_flags
: The set of additional compiler flags to pass torustc
. -
srcs
: The set of Rust source files to be compiled by this rule.One of the source files is the root module of the crate. By default this is
lib.rs
for libraries,main.rs
for executables, or the crate's name with.rs
appended. This can be overridden with thecrate_root
rule parameter.
Details
If you invoke a build with the check
flavor, then Buck will invoke rustc
to check the code (typecheck, produce warnings, etc), but won't generate an executable code.
When applied to binaries it produces no output; for libraries it produces metadata for
consumers of the library.
Note: Buck is currently tested with (and therefore supports) version 1.32.0 of Rust.
Examples:
For more examples, check out our integration tests.
rust_binary(
name='greet',
srcs=[
'greet.rs',
],
deps=[
':greeting',
],
)
rust_library(
name='greeting',
srcs=[
'greeting.rs',
],
deps=[
':join',
],
)
rust_library(
name='join',
srcs=[
'join.rs',
],
)