Buck: rust_test()
Support Ukraine. Help Provide Humanitarian Aid to Ukraine.

rust_test()

This is liable to change in the future.

A rust_test() rule builds a Rust test native executable from the supplied set of Rust source files and dependencies and runs this test.

Note: Buck is currently tested with (and therefore supports) version 1.32.0 of Rust.

Arguments

  • name (required) #

    The short name for this build target.

  • framework (defaults to true) #

    Use the standard test framework. If this is set to false, then the result is a normal executable which requires a main(), etc. It is still expected to accept the same command-line parameters and produce the same output as the test framework.

  • contacts (defaults to []) #

    A list of organizational contacts for this test. These could be individuals who you would contact in the event of a test failure or other issue with the test.

    contacts = [ 'Joe Sixpack', 'Erika Mustermann' ]
    

  • srcs (required) #

    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 the crate_root rule parameter.

  • mapped_srcs (defaults to {}) #

    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 example mapped_srcs = { ":generate-module", "src/generated.rs" }. These are added to the regular srcs, so a file should not be listed in both.

  • deps (defaults to []) #

    The set of dependencies of this rule. Currently, this supports rust_library and prebuilt_rust_library rules.

  • named_deps (defaults to {}) #

    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.

  • platform_deps (defaults to []) #

    Platform specific dependencies. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is a list of dependencies (same format as deps) that are exported if the platform matches the regex. See deps for more information.

  • edition (required) #

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

  • features (defaults to []) #

    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}")].

  • rustc_flags (defaults to []) #

    The set of additional compiler flags to pass to rustc.

  • env (defaults to {}) #

    Set environment variables for this rule's invocations of rustc. The environment variable values may include macros which are expanded.

  • crate (defaults to rule name) #

    Set the generated crate name (for libraries) or executable name (for binaries), independent of the rule name. Defaults to the rule name.

  • crate_root (defaults to derived from crate name) #

    Set the name of the top-level source file for the crate, which can be used to override the default (see srcs).

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule as a dependency, for example, by listing it in their deps or exported_deps attributes. For more information, see visibility.

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

  • 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 attrfilter().

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',
  ],
)