rust_test
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 = ...,
_inject_test_env: str = ...,
_remote_test_execution_toolchain: str = ...,
_rust_internal_tools_toolchain: str = ...,
_rust_toolchain: str = ...,
_target_os_type: str = ...,
_test_toolchain: str = ...,
_workspaces: list[str] = ...,
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 = ...,
default_roots: None | list[str] = ...,
deps: list[str] = ...,
edition: None | str = ...,
enable_distributed_thinlto: bool = ...,
env: dict[str, str] = ...,
features: list[str] = ...,
flagged_deps: list[(str, list[str])] = ...,
framework: bool = ...,
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] = ...,
remote_execution: None | str | dict[str, None | bool | int | str | list[dict[str, str]] | dict[str, str | list[str]]] = ...,
remote_execution_action_key_providers: None | str = ...,
resources: list[str] | dict[str, str] = ...,
rpath: bool = ...,
run_env: dict[str, str] = ...,
rustc_flags: list[str] = ...,
rustdoc_flags: list[str] = ...,
separate_debug_info: bool = ...,
srcs: list[str] = ...,
) -> None
A rust_test() rule builds a Rust test native executable from the supplied set of Rust source files and dependencies and runs this test.
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. -
crate_root
: Set the name of the top-level source file for the crate, which can be used to override the default (seesrcs
). -
default_roots
: Set the candidate source names to consider for crate root. Typically used to disambiguate between lib.rs or main.rs for rust_test, which may be declare a test suite for either library or binary rules. Has no effect if an explicitcrate_root
is provided. -
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 and during execution of the tests. 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}")]
. -
framework
: Use the standard test framework. If this is set to false, then the result is a normal executable which requires amain()
, etc. It is still expected to accept the same command-line parameters and produce the same output as the test framework. -
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. -
run_env
: Set environment variables during test execution. The environment variable values may include macros which are expanded. -
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
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_test(
name='greet',
srcs=[
'greet.rs',
],
deps=[
':greeting',
],
)
rust_library(
name='greeting',
srcs=[
'greeting.rs',
],
deps=[
':join',
],
)
rust_library(
name='join',
srcs=[
'join.rs',
],
)