Buck: rust_library()

rust_library()

This is liable to change in the future.

A rust_library() rule builds a native library from the supplied set of Rust source files and dependencies.

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. When building with check, extra compiler flags from the rust.rustc_check_flags are added to the compiler's command line options, to allow for extra warnings, etc.

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

Arguments

  • name (required) #

    The name of the rule.

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

  • deps (defaults to []) #

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

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

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

  • preferred_linkage (defaults to any) #

    Controls how a library should be linked.

    any
    The library will be linked based on its dependents link_style.
    shared
    The library will be always be linked as a shared library.
    static
    The library will be linked as a static library.
    Note: since shared libraries re-export its dependencies, depending on multiple shared libraries which themselves have overlapping static dependencies will cause duplicate symbols.

  • tests (defaults to []) #

    List of build targets that identify the test rules that exercise this target.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • 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_library(
  name='greeting',
  srcs=[
    'greeting.rs',
  ],
  deps=[
    ':join',
  ],
)