1# Rust rules 2 3* [CrateInfo](#CrateInfo) 4* [DepInfo](#DepInfo) 5* [RustWasmBindgenInfo](#RustWasmBindgenInfo) 6* [StdLibInfo](#StdLibInfo) 7* [capture_clippy_output](#capture_clippy_output) 8* [cargo_bootstrap_repository](#cargo_bootstrap_repository) 9* [cargo_build_script](#cargo_build_script) 10* [cargo_dep_env](#cargo_dep_env) 11* [cargo_env](#cargo_env) 12* [error_format](#error_format) 13* [extra_rustc_flag](#extra_rustc_flag) 14* [extra_rustc_flags](#extra_rustc_flags) 15* [fail_when_enabled](#fail_when_enabled) 16* [incompatible_flag](#incompatible_flag) 17* [rules_rust_dependencies](#rules_rust_dependencies) 18* [rust_analyzer_aspect](#rust_analyzer_aspect) 19* [rust_analyzer_toolchain](#rust_analyzer_toolchain) 20* [rust_analyzer_toolchain_repository](#rust_analyzer_toolchain_repository) 21* [rust_binary](#rust_binary) 22* [rust_bindgen](#rust_bindgen) 23* [rust_bindgen_dependencies](#rust_bindgen_dependencies) 24* [rust_bindgen_library](#rust_bindgen_library) 25* [rust_bindgen_register_toolchains](#rust_bindgen_register_toolchains) 26* [rust_bindgen_toolchain](#rust_bindgen_toolchain) 27* [rust_clippy](#rust_clippy) 28* [rust_clippy_aspect](#rust_clippy_aspect) 29* [rust_doc](#rust_doc) 30* [rust_doc_test](#rust_doc_test) 31* [rust_grpc_library](#rust_grpc_library) 32* [rust_library](#rust_library) 33* [rust_library_group](#rust_library_group) 34* [rust_proc_macro](#rust_proc_macro) 35* [rust_prost_dependencies](#rust_prost_dependencies) 36* [rust_prost_library](#rust_prost_library) 37* [rust_prost_toolchain](#rust_prost_toolchain) 38* [rust_prost_transitive_repositories](#rust_prost_transitive_repositories) 39* [rust_proto_library](#rust_proto_library) 40* [rust_proto_protobuf_dependencies](#rust_proto_protobuf_dependencies) 41* [rust_proto_protobuf_register_toolchains](#rust_proto_protobuf_register_toolchains) 42* [rust_proto_protobuf_toolchain](#rust_proto_protobuf_toolchain) 43* [rust_proto_protobuf_transitive_repositories](#rust_proto_protobuf_transitive_repositories) 44* [rust_register_toolchains](#rust_register_toolchains) 45* [rust_repositories](#rust_repositories) 46* [rust_repository_set](#rust_repository_set) 47* [rust_shared_library](#rust_shared_library) 48* [rust_static_library](#rust_static_library) 49* [rust_stdlib_filegroup](#rust_stdlib_filegroup) 50* [rust_test](#rust_test) 51* [rust_test_suite](#rust_test_suite) 52* [rust_toolchain](#rust_toolchain) 53* [rust_toolchain_repository](#rust_toolchain_repository) 54* [rust_toolchain_repository_proxy](#rust_toolchain_repository_proxy) 55* [rust_toolchain_tools_repository](#rust_toolchain_tools_repository) 56* [rust_wasm_bindgen](#rust_wasm_bindgen) 57* [rust_wasm_bindgen_dependencies](#rust_wasm_bindgen_dependencies) 58* [rust_wasm_bindgen_register_toolchains](#rust_wasm_bindgen_register_toolchains) 59* [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain) 60* [rustfmt_aspect](#rustfmt_aspect) 61* [rustfmt_test](#rustfmt_test) 62* [rustfmt_toolchain](#rustfmt_toolchain) 63 64 65<a id="capture_clippy_output"></a> 66 67## capture_clippy_output 68 69<pre> 70capture_clippy_output(<a href="#capture_clippy_output-name">name</a>) 71</pre> 72 73Control whether to print clippy output or store it to a file, using the configured error_format. 74 75**ATTRIBUTES** 76 77 78| Name | Description | Type | Mandatory | Default | 79| :------------- | :------------- | :------------- | :------------- | :------------- | 80| <a id="capture_clippy_output-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 81 82 83<a id="cargo_dep_env"></a> 84 85## cargo_dep_env 86 87<pre> 88cargo_dep_env(<a href="#cargo_dep_env-name">name</a>, <a href="#cargo_dep_env-src">src</a>, <a href="#cargo_dep_env-out_dir">out_dir</a>) 89</pre> 90 91A rule for generating variables for dependent `cargo_build_script`s without a build script. This is useful for using Bazel rules instead of a build script, while also generating configuration information for build scripts which depend on this crate. 92 93**ATTRIBUTES** 94 95 96| Name | Description | Type | Mandatory | Default | 97| :------------- | :------------- | :------------- | :------------- | :------------- | 98| <a id="cargo_dep_env-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 99| <a id="cargo_dep_env-src"></a>src | File containing additional environment variables to set for build scripts of direct dependencies.<br><br>This has the same effect as a `cargo_build_script` which prints `cargo:VAR=VALUE` lines, but without requiring a build script.<br><br>This files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`). | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 100| <a id="cargo_dep_env-out_dir"></a>out_dir | Folder containing additional inputs when building all direct dependencies.<br><br>This has the same effect as a `cargo_build_script` which prints puts files into `$OUT_DIR`, but without requiring a build script. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 101 102 103<a id="error_format"></a> 104 105## error_format 106 107<pre> 108error_format(<a href="#error_format-name">name</a>) 109</pre> 110 111Change the [--error-format](https://doc.rust-lang.org/rustc/command-line-arguments.html#option-error-format) flag from the command line with `--@rules_rust//:error_format`. See rustc documentation for valid values. 112 113**ATTRIBUTES** 114 115 116| Name | Description | Type | Mandatory | Default | 117| :------------- | :------------- | :------------- | :------------- | :------------- | 118| <a id="error_format-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 119 120 121<a id="extra_rustc_flag"></a> 122 123## extra_rustc_flag 124 125<pre> 126extra_rustc_flag(<a href="#extra_rustc_flag-name">name</a>) 127</pre> 128 129Add additional rustc_flag from the command line with `--@rules_rust//:extra_rustc_flag`. Multiple uses are accumulated and appended after the extra_rustc_flags. 130 131**ATTRIBUTES** 132 133 134| Name | Description | Type | Mandatory | Default | 135| :------------- | :------------- | :------------- | :------------- | :------------- | 136| <a id="extra_rustc_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 137 138 139<a id="extra_rustc_flags"></a> 140 141## extra_rustc_flags 142 143<pre> 144extra_rustc_flags(<a href="#extra_rustc_flags-name">name</a>) 145</pre> 146 147Add additional rustc_flags from the command line with `--@rules_rust//:extra_rustc_flags`. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use `--@rules_rust//:extra_exec_rustc_flags` to apply flags to the exec configuration. 148 149**ATTRIBUTES** 150 151 152| Name | Description | Type | Mandatory | Default | 153| :------------- | :------------- | :------------- | :------------- | :------------- | 154| <a id="extra_rustc_flags-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 155 156 157<a id="incompatible_flag"></a> 158 159## incompatible_flag 160 161<pre> 162incompatible_flag(<a href="#incompatible_flag-name">name</a>, <a href="#incompatible_flag-issue">issue</a>) 163</pre> 164 165A rule defining an incompatible flag. 166 167**ATTRIBUTES** 168 169 170| Name | Description | Type | Mandatory | Default | 171| :------------- | :------------- | :------------- | :------------- | :------------- | 172| <a id="incompatible_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 173| <a id="incompatible_flag-issue"></a>issue | The link to the github issue associated with this flag | String | required | | 174 175 176<a id="rust_analyzer_toolchain"></a> 177 178## rust_analyzer_toolchain 179 180<pre> 181rust_analyzer_toolchain(<a href="#rust_analyzer_toolchain-name">name</a>, <a href="#rust_analyzer_toolchain-proc_macro_srv">proc_macro_srv</a>, <a href="#rust_analyzer_toolchain-rustc">rustc</a>, <a href="#rust_analyzer_toolchain-rustc_srcs">rustc_srcs</a>) 182</pre> 183 184A toolchain for [rust-analyzer](https://rust-analyzer.github.io/). 185 186**ATTRIBUTES** 187 188 189| Name | Description | Type | Mandatory | Default | 190| :------------- | :------------- | :------------- | :------------- | :------------- | 191| <a id="rust_analyzer_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 192| <a id="rust_analyzer_toolchain-proc_macro_srv"></a>proc_macro_srv | The path to a `rust_analyzer_proc_macro_srv` binary. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 193| <a id="rust_analyzer_toolchain-rustc"></a>rustc | The path to a `rustc` binary. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 194| <a id="rust_analyzer_toolchain-rustc_srcs"></a>rustc_srcs | The source code of rustc. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 195 196 197<a id="rust_binary"></a> 198 199## rust_binary 200 201<pre> 202rust_binary(<a href="#rust_binary-name">name</a>, <a href="#rust_binary-deps">deps</a>, <a href="#rust_binary-srcs">srcs</a>, <a href="#rust_binary-data">data</a>, <a href="#rust_binary-aliases">aliases</a>, <a href="#rust_binary-alwayslink">alwayslink</a>, <a href="#rust_binary-compile_data">compile_data</a>, <a href="#rust_binary-crate_features">crate_features</a>, <a href="#rust_binary-crate_name">crate_name</a>, 203 <a href="#rust_binary-crate_root">crate_root</a>, <a href="#rust_binary-crate_type">crate_type</a>, <a href="#rust_binary-edition">edition</a>, <a href="#rust_binary-env">env</a>, <a href="#rust_binary-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="#rust_binary-linker_script">linker_script</a>, 204 <a href="#rust_binary-malloc">malloc</a>, <a href="#rust_binary-out_binary">out_binary</a>, <a href="#rust_binary-platform">platform</a>, <a href="#rust_binary-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_binary-rustc_env">rustc_env</a>, <a href="#rust_binary-rustc_env_files">rustc_env_files</a>, <a href="#rust_binary-rustc_flags">rustc_flags</a>, 205 <a href="#rust_binary-stamp">stamp</a>, <a href="#rust_binary-version">version</a>) 206</pre> 207 208Builds a Rust binary crate. 209 210Example: 211 212Suppose you have the following directory structure for a Rust project with a 213library crate, `hello_lib`, and a binary crate, `hello_world` that uses the 214`hello_lib` library: 215 216```output 217[workspace]/ 218 WORKSPACE 219 hello_lib/ 220 BUILD 221 src/ 222 lib.rs 223 hello_world/ 224 BUILD 225 src/ 226 main.rs 227``` 228 229`hello_lib/src/lib.rs`: 230```rust 231pub struct Greeter { 232 greeting: String, 233} 234 235impl Greeter { 236 pub fn new(greeting: &str) -> Greeter { 237 Greeter { greeting: greeting.to_string(), } 238 } 239 240 pub fn greet(&self, thing: &str) { 241 println!("{} {}", &self.greeting, thing); 242 } 243} 244``` 245 246`hello_lib/BUILD`: 247```python 248package(default_visibility = ["//visibility:public"]) 249 250load("@rules_rust//rust:defs.bzl", "rust_library") 251 252rust_library( 253 name = "hello_lib", 254 srcs = ["src/lib.rs"], 255) 256``` 257 258`hello_world/src/main.rs`: 259```rust 260extern crate hello_lib; 261 262fn main() { 263 let hello = hello_lib::Greeter::new("Hello"); 264 hello.greet("world"); 265} 266``` 267 268`hello_world/BUILD`: 269```python 270load("@rules_rust//rust:defs.bzl", "rust_binary") 271 272rust_binary( 273 name = "hello_world", 274 srcs = ["src/main.rs"], 275 deps = ["//hello_lib"], 276) 277``` 278 279Build and run `hello_world`: 280``` 281$ bazel run //hello_world 282INFO: Found 1 target... 283Target //examples/rust/hello_world:hello_world up-to-date: 284bazel-bin/examples/rust/hello_world/hello_world 285INFO: Elapsed time: 1.308s, Critical Path: 1.22s 286 287INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world 288Hello world 289``` 290 291On Windows, a PDB file containing debugging information is available under 292the key `pdb_file` in `OutputGroupInfo`. Similarly on macOS, a dSYM folder 293is available under the key `dsym_folder` in `OutputGroupInfo`. 294 295**ATTRIBUTES** 296 297 298| Name | Description | Type | Mandatory | Default | 299| :------------- | :------------- | :------------- | :------------- | :------------- | 300| <a id="rust_binary-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 301| <a id="rust_binary-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 302| <a id="rust_binary-srcs"></a>srcs | List of Rust `.rs` source files used to build the library.<br><br>If `srcs` contains more than one file, then there must be a file either named `lib.rs`. Otherwise, `crate_root` must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 303| <a id="rust_binary-data"></a>data | List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer `compile_data` over `data`, to prevent the data also being included in the runfiles. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 304| <a id="rust_binary-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target<br><br>These are other `rust_library` targets and will be presented as the new name given. | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` | 305| <a id="rust_binary-alwayslink"></a>alwayslink | If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers. | Boolean | optional | `False` | 306| <a id="rust_binary-compile_data"></a>compile_data | List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [`include_str!`](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 307| <a id="rust_binary-crate_features"></a>crate_features | List of features to enable for this crate.<br><br>Features are defined in the code using the `#[cfg(feature = "foo")]` configuration option. The features listed here will be passed to `rustc` with `--cfg feature="${feature_name}"` flags. | List of strings | optional | `[]` | 308| <a id="rust_binary-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 309| <a id="rust_binary-crate_root"></a>crate_root | The file that will be passed to `rustc` to be used for building this crate.<br><br>If `crate_root` is not set, then this rule will look for a `lib.rs` file (or `main.rs` for rust_binary) or the single file in `srcs` if `srcs` contains only one file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 310| <a id="rust_binary-crate_type"></a>crate_type | Crate type that will be passed to `rustc` to be used for building this crate.<br><br>This option is a temporary workaround and should be used only when building for WebAssembly targets (//rust/platform:wasi and //rust/platform:wasm). | String | optional | `"bin"` | 311| <a id="rust_binary-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | `""` | 312| <a id="rust_binary-env"></a>env | Specifies additional environment variables to set when the target is executed by bazel run. Values are subject to `$(rootpath)`, `$(execpath)`, location, and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution.<br><br>Execpath returns absolute path, and in order to be able to construct the absolute path we need to wrap the test binary in a launcher. Using a launcher comes with complications, such as more complicated debugger attachment. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 313| <a id="rust_binary-experimental_use_cc_common_link"></a>experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | `-1` | 314| <a id="rust_binary-linker_script"></a>linker_script | Link script to forward into linker via rustc options. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 315| <a id="rust_binary-malloc"></a>malloc | Override the default dependency on `malloc`.<br><br>By default, Rust binaries linked with cc_common.link are linked against `@bazel_tools//tools/cpp:malloc"`, which is an empty library and the resulting binary will use libc's `malloc`. This label must refer to a `cc_library` rule. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@bazel_tools//tools/cpp:malloc"` | 316| <a id="rust_binary-out_binary"></a>out_binary | Force a target, regardless of it's `crate_type`, to always mark the file as executable. This attribute is only used to support wasm targets but is expected to be removed following a resolution to https://github.com/bazelbuild/rules_rust/issues/771. | Boolean | optional | `False` | 317| <a id="rust_binary-platform"></a>platform | Optional platform to transition the binary to. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 318| <a id="rust_binary-proc_macro_deps"></a>proc_macro_deps | List of `rust_proc_macro` targets used to help build this library target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 319| <a id="rust_binary-rustc_env"></a>rustc_env | Dictionary of additional `"key": "value"` environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 320| <a id="rust_binary-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the `stamp` attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. `NAME={WORKSPACE_STATUS_VARIABLE}`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 321| <a id="rust_binary-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 322| <a id="rust_binary-stamp"></a>stamp | Whether to encode build information into the `Rustc` action. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the `Rustc` action, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- `stamp = 0`: Always replace build information by constant values. This gives good build result caching.<br><br>- `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a `rust_library` is stamped, and a `rust_binary` depends on that library, the stamped library won't be rebuilt when we change sources of the `rust_binary`. This is different from how [`cc_library.linkstamps`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp) behaves. | Integer | optional | `-1` | 323| <a id="rust_binary-version"></a>version | A version to inject in the cargo environment variable. | String | optional | `"0.0.0"` | 324 325 326<a id="rust_bindgen"></a> 327 328## rust_bindgen 329 330<pre> 331rust_bindgen(<a href="#rust_bindgen-name">name</a>, <a href="#rust_bindgen-bindgen_flags">bindgen_flags</a>, <a href="#rust_bindgen-cc_lib">cc_lib</a>, <a href="#rust_bindgen-clang_flags">clang_flags</a>, <a href="#rust_bindgen-header">header</a>, <a href="#rust_bindgen-wrap_static_fns">wrap_static_fns</a>) 332</pre> 333 334Generates a rust source file from a cc_library and a header. 335 336**ATTRIBUTES** 337 338 339| Name | Description | Type | Mandatory | Default | 340| :------------- | :------------- | :------------- | :------------- | :------------- | 341| <a id="rust_bindgen-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 342| <a id="rust_bindgen-bindgen_flags"></a>bindgen_flags | Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details. | List of strings | optional | `[]` | 343| <a id="rust_bindgen-cc_lib"></a>cc_lib | The cc_library that contains the `.h` file. This is used to find the transitive includes. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 344| <a id="rust_bindgen-clang_flags"></a>clang_flags | Flags to pass directly to the clang executable. | List of strings | optional | `[]` | 345| <a id="rust_bindgen-header"></a>header | The `.h` file to generate bindings for. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 346| <a id="rust_bindgen-wrap_static_fns"></a>wrap_static_fns | Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains). | Boolean | optional | `False` | 347 348 349<a id="rust_bindgen_toolchain"></a> 350 351## rust_bindgen_toolchain 352 353<pre> 354rust_bindgen_toolchain(<a href="#rust_bindgen_toolchain-name">name</a>, <a href="#rust_bindgen_toolchain-bindgen">bindgen</a>, <a href="#rust_bindgen_toolchain-clang">clang</a>, <a href="#rust_bindgen_toolchain-default_rustfmt">default_rustfmt</a>, <a href="#rust_bindgen_toolchain-libclang">libclang</a>, <a href="#rust_bindgen_toolchain-libstdcxx">libstdcxx</a>) 355</pre> 356 357The tools required for the `rust_bindgen` rule. 358 359This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it 360in turn depends on both a clang binary and the clang library. To obtain these dependencies, 361`rust_bindgen_dependencies` imports bindgen and its dependencies. 362 363```python 364load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_toolchain") 365 366rust_bindgen_toolchain( 367 name = "bindgen_toolchain_impl", 368 bindgen = "//my/rust:bindgen", 369 clang = "//my/clang:clang", 370 libclang = "//my/clang:libclang.so", 371 libstdcxx = "//my/cpp:libstdc++", 372) 373 374toolchain( 375 name = "bindgen_toolchain", 376 toolchain = "bindgen_toolchain_impl", 377 toolchain_type = "@rules_rust//bindgen:toolchain_type", 378) 379``` 380 381This toolchain will then need to be registered in the current `WORKSPACE`. 382For additional information, see the [Bazel toolchains documentation](https://docs.bazel.build/versions/master/toolchains.html). 383 384**ATTRIBUTES** 385 386 387| Name | Description | Type | Mandatory | Default | 388| :------------- | :------------- | :------------- | :------------- | :------------- | 389| <a id="rust_bindgen_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 390| <a id="rust_bindgen_toolchain-bindgen"></a>bindgen | The label of a `bindgen` executable. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 391| <a id="rust_bindgen_toolchain-clang"></a>clang | The label of a `clang` executable. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 392| <a id="rust_bindgen_toolchain-default_rustfmt"></a>default_rustfmt | If set, `rust_bindgen` targets will always format generated sources with `rustfmt`. | Boolean | optional | `True` | 393| <a id="rust_bindgen_toolchain-libclang"></a>libclang | A cc_library that provides bindgen's runtime dependency on libclang. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 394| <a id="rust_bindgen_toolchain-libstdcxx"></a>libstdcxx | A cc_library that satisfies libclang's libstdc++ dependency. This is used to make the execution of clang hermetic. If None, system libraries will be used instead. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 395 396 397<a id="rust_clippy"></a> 398 399## rust_clippy 400 401<pre> 402rust_clippy(<a href="#rust_clippy-name">name</a>, <a href="#rust_clippy-deps">deps</a>) 403</pre> 404 405Executes the clippy checker on a specific target. 406 407Similar to `rust_clippy_aspect`, but allows specifying a list of dependencies within the build system. 408 409For example, given the following example targets: 410 411```python 412load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 413 414rust_library( 415 name = "hello_lib", 416 srcs = ["src/lib.rs"], 417) 418 419rust_test( 420 name = "greeting_test", 421 srcs = ["tests/greeting.rs"], 422 deps = [":hello_lib"], 423) 424``` 425 426Rust clippy can be set as a build target with the following: 427 428```python 429load("@rules_rust//rust:defs.bzl", "rust_clippy") 430 431rust_clippy( 432 name = "hello_library_clippy", 433 testonly = True, 434 deps = [ 435 ":hello_lib", 436 ":greeting_test", 437 ], 438) 439``` 440 441**ATTRIBUTES** 442 443 444| Name | Description | Type | Mandatory | Default | 445| :------------- | :------------- | :------------- | :------------- | :------------- | 446| <a id="rust_clippy-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 447| <a id="rust_clippy-deps"></a>deps | Rust targets to run clippy on. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 448 449 450<a id="rust_doc"></a> 451 452## rust_doc 453 454<pre> 455rust_doc(<a href="#rust_doc-name">name</a>, <a href="#rust_doc-crate">crate</a>, <a href="#rust_doc-html_after_content">html_after_content</a>, <a href="#rust_doc-html_before_content">html_before_content</a>, <a href="#rust_doc-html_in_header">html_in_header</a>, <a href="#rust_doc-markdown_css">markdown_css</a>, 456 <a href="#rust_doc-rustc_flags">rustc_flags</a>, <a href="#rust_doc-rustdoc_flags">rustdoc_flags</a>) 457</pre> 458 459Generates code documentation. 460 461Example: 462Suppose you have the following directory structure for a Rust library crate: 463 464``` 465[workspace]/ 466 WORKSPACE 467 hello_lib/ 468 BUILD 469 src/ 470 lib.rs 471``` 472 473To build [`rustdoc`][rustdoc] documentation for the `hello_lib` crate, define a `rust_doc` rule that depends on the the `hello_lib` `rust_library` target: 474 475[rustdoc]: https://doc.rust-lang.org/book/documentation.html 476 477```python 478package(default_visibility = ["//visibility:public"]) 479 480load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc") 481 482rust_library( 483 name = "hello_lib", 484 srcs = ["src/lib.rs"], 485) 486 487rust_doc( 488 name = "hello_lib_doc", 489 crate = ":hello_lib", 490) 491``` 492 493Running `bazel build //hello_lib:hello_lib_doc` will build a zip file containing the documentation for the `hello_lib` library crate generated by `rustdoc`. 494 495**ATTRIBUTES** 496 497 498| Name | Description | Type | Mandatory | Default | 499| :------------- | :------------- | :------------- | :------------- | :------------- | 500| <a id="rust_doc-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 501| <a id="rust_doc-crate"></a>crate | The label of the target to generate code documentation for.<br><br>`rust_doc` can generate HTML code documentation for the source files of `rust_library` or `rust_binary` targets. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 502| <a id="rust_doc-html_after_content"></a>html_after_content | File to add in `<body>`, after content. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 503| <a id="rust_doc-html_before_content"></a>html_before_content | File to add in `<body>`, before content. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 504| <a id="rust_doc-html_in_header"></a>html_in_header | File to add to `<head>`. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 505| <a id="rust_doc-markdown_css"></a>markdown_css | CSS files to include via `<link>` in a rendered Markdown file. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 506| <a id="rust_doc-rustc_flags"></a>rustc_flags | **Deprecated**: use `rustdoc_flags` instead | List of strings | optional | `[]` | 507| <a id="rust_doc-rustdoc_flags"></a>rustdoc_flags | List of flags passed to `rustdoc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 508 509 510<a id="rust_doc_test"></a> 511 512## rust_doc_test 513 514<pre> 515rust_doc_test(<a href="#rust_doc_test-name">name</a>, <a href="#rust_doc_test-deps">deps</a>, <a href="#rust_doc_test-crate">crate</a>) 516</pre> 517 518Runs Rust documentation tests. 519 520Example: 521 522Suppose you have the following directory structure for a Rust library crate: 523 524```output 525[workspace]/ 526WORKSPACE 527hello_lib/ 528 BUILD 529 src/ 530 lib.rs 531``` 532 533To run [documentation tests][doc-test] for the `hello_lib` crate, define a `rust_doc_test` target that depends on the `hello_lib` `rust_library` target: 534 535[doc-test]: https://doc.rust-lang.org/book/documentation.html#documentation-as-tests 536 537```python 538package(default_visibility = ["//visibility:public"]) 539 540load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test") 541 542rust_library( 543 name = "hello_lib", 544 srcs = ["src/lib.rs"], 545) 546 547rust_doc_test( 548 name = "hello_lib_doc_test", 549 crate = ":hello_lib", 550) 551``` 552 553Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation tests for the `hello_lib` library crate. 554 555**ATTRIBUTES** 556 557 558| Name | Description | Type | Mandatory | Default | 559| :------------- | :------------- | :------------- | :------------- | :------------- | 560| <a id="rust_doc_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 561| <a id="rust_doc_test-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 562| <a id="rust_doc_test-crate"></a>crate | The label of the target to generate code documentation for. `rust_doc_test` can generate HTML code documentation for the source files of `rust_library` or `rust_binary` targets. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 563 564 565<a id="rust_grpc_library"></a> 566 567## rust_grpc_library 568 569<pre> 570rust_grpc_library(<a href="#rust_grpc_library-name">name</a>, <a href="#rust_grpc_library-deps">deps</a>, <a href="#rust_grpc_library-crate_name">crate_name</a>, <a href="#rust_grpc_library-rust_deps">rust_deps</a>, <a href="#rust_grpc_library-rustc_flags">rustc_flags</a>) 571</pre> 572 573Builds a Rust library crate from a set of `proto_library`s suitable for gRPC. 574 575Example: 576 577```python 578load("@rules_rust//proto/protobuf:defs.bzl", "rust_grpc_library") 579 580proto_library( 581 name = "my_proto", 582 srcs = ["my.proto"] 583) 584 585rust_grpc_library( 586 name = "rust", 587 deps = [":my_proto"], 588) 589 590rust_binary( 591 name = "my_service", 592 srcs = ["my_service.rs"], 593 deps = [":rust"], 594) 595``` 596 597**ATTRIBUTES** 598 599 600| Name | Description | Type | Mandatory | Default | 601| :------------- | :------------- | :------------- | :------------- | :------------- | 602| <a id="rust_grpc_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 603| <a id="rust_grpc_library-deps"></a>deps | List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding gRPC stubs. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | | 604| <a id="rust_grpc_library-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 605| <a id="rust_grpc_library-rust_deps"></a>rust_deps | The crates the generated library depends on. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 606| <a id="rust_grpc_library-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 607 608 609<a id="rust_library"></a> 610 611## rust_library 612 613<pre> 614rust_library(<a href="#rust_library-name">name</a>, <a href="#rust_library-deps">deps</a>, <a href="#rust_library-srcs">srcs</a>, <a href="#rust_library-data">data</a>, <a href="#rust_library-aliases">aliases</a>, <a href="#rust_library-alwayslink">alwayslink</a>, <a href="#rust_library-compile_data">compile_data</a>, <a href="#rust_library-crate_features">crate_features</a>, <a href="#rust_library-crate_name">crate_name</a>, 615 <a href="#rust_library-crate_root">crate_root</a>, <a href="#rust_library-disable_pipelining">disable_pipelining</a>, <a href="#rust_library-edition">edition</a>, <a href="#rust_library-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_library-rustc_env">rustc_env</a>, <a href="#rust_library-rustc_env_files">rustc_env_files</a>, 616 <a href="#rust_library-rustc_flags">rustc_flags</a>, <a href="#rust_library-stamp">stamp</a>, <a href="#rust_library-version">version</a>) 617</pre> 618 619Builds a Rust library crate. 620 621Example: 622 623Suppose you have the following directory structure for a simple Rust library crate: 624 625```output 626[workspace]/ 627 WORKSPACE 628 hello_lib/ 629 BUILD 630 src/ 631 greeter.rs 632 lib.rs 633``` 634 635`hello_lib/src/greeter.rs`: 636```rust 637pub struct Greeter { 638 greeting: String, 639} 640 641impl Greeter { 642 pub fn new(greeting: &str) -> Greeter { 643 Greeter { greeting: greeting.to_string(), } 644 } 645 646 pub fn greet(&self, thing: &str) { 647 println!("{} {}", &self.greeting, thing); 648 } 649} 650``` 651 652`hello_lib/src/lib.rs`: 653 654```rust 655pub mod greeter; 656``` 657 658`hello_lib/BUILD`: 659```python 660package(default_visibility = ["//visibility:public"]) 661 662load("@rules_rust//rust:defs.bzl", "rust_library") 663 664rust_library( 665 name = "hello_lib", 666 srcs = [ 667 "src/greeter.rs", 668 "src/lib.rs", 669 ], 670) 671``` 672 673Build the library: 674```output 675$ bazel build //hello_lib 676INFO: Found 1 target... 677Target //examples/rust/hello_lib:hello_lib up-to-date: 678bazel-bin/examples/rust/hello_lib/libhello_lib.rlib 679INFO: Elapsed time: 1.245s, Critical Path: 1.01s 680``` 681 682**ATTRIBUTES** 683 684 685| Name | Description | Type | Mandatory | Default | 686| :------------- | :------------- | :------------- | :------------- | :------------- | 687| <a id="rust_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 688| <a id="rust_library-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 689| <a id="rust_library-srcs"></a>srcs | List of Rust `.rs` source files used to build the library.<br><br>If `srcs` contains more than one file, then there must be a file either named `lib.rs`. Otherwise, `crate_root` must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 690| <a id="rust_library-data"></a>data | List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer `compile_data` over `data`, to prevent the data also being included in the runfiles. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 691| <a id="rust_library-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target<br><br>These are other `rust_library` targets and will be presented as the new name given. | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` | 692| <a id="rust_library-alwayslink"></a>alwayslink | If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers. | Boolean | optional | `False` | 693| <a id="rust_library-compile_data"></a>compile_data | List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [`include_str!`](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 694| <a id="rust_library-crate_features"></a>crate_features | List of features to enable for this crate.<br><br>Features are defined in the code using the `#[cfg(feature = "foo")]` configuration option. The features listed here will be passed to `rustc` with `--cfg feature="${feature_name}"` flags. | List of strings | optional | `[]` | 695| <a id="rust_library-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 696| <a id="rust_library-crate_root"></a>crate_root | The file that will be passed to `rustc` to be used for building this crate.<br><br>If `crate_root` is not set, then this rule will look for a `lib.rs` file (or `main.rs` for rust_binary) or the single file in `srcs` if `srcs` contains only one file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 697| <a id="rust_library-disable_pipelining"></a>disable_pipelining | Disables pipelining for this rule if it is globally enabled. This will cause this rule to not produce a `.rmeta` file and all the dependent crates will instead use the `.rlib` file. | Boolean | optional | `False` | 698| <a id="rust_library-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | `""` | 699| <a id="rust_library-proc_macro_deps"></a>proc_macro_deps | List of `rust_proc_macro` targets used to help build this library target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 700| <a id="rust_library-rustc_env"></a>rustc_env | Dictionary of additional `"key": "value"` environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 701| <a id="rust_library-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the `stamp` attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. `NAME={WORKSPACE_STATUS_VARIABLE}`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 702| <a id="rust_library-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 703| <a id="rust_library-stamp"></a>stamp | Whether to encode build information into the `Rustc` action. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the `Rustc` action, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- `stamp = 0`: Always replace build information by constant values. This gives good build result caching.<br><br>- `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a `rust_library` is stamped, and a `rust_binary` depends on that library, the stamped library won't be rebuilt when we change sources of the `rust_binary`. This is different from how [`cc_library.linkstamps`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp) behaves. | Integer | optional | `0` | 704| <a id="rust_library-version"></a>version | A version to inject in the cargo environment variable. | String | optional | `"0.0.0"` | 705 706 707<a id="rust_library_group"></a> 708 709## rust_library_group 710 711<pre> 712rust_library_group(<a href="#rust_library_group-name">name</a>, <a href="#rust_library_group-deps">deps</a>) 713</pre> 714 715Functions as an alias for a set of dependencies. 716 717Specifically, the following are equivalent: 718 719```starlark 720rust_library_group( 721 name = "crate_group", 722 deps = [ 723 ":crate1", 724 ":crate2", 725 ], 726) 727 728rust_library( 729 name = "foobar", 730 deps = [":crate_group"], 731 ... 732) 733``` 734 735and 736 737```starlark 738rust_library( 739 name = "foobar", 740 deps = [ 741 ":crate1", 742 ":crate2", 743 ], 744 ... 745) 746``` 747 748**ATTRIBUTES** 749 750 751| Name | Description | Type | Mandatory | Default | 752| :------------- | :------------- | :------------- | :------------- | :------------- | 753| <a id="rust_library_group-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 754| <a id="rust_library_group-deps"></a>deps | Other dependencies to forward through this crate group. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 755 756 757<a id="rust_proc_macro"></a> 758 759## rust_proc_macro 760 761<pre> 762rust_proc_macro(<a href="#rust_proc_macro-name">name</a>, <a href="#rust_proc_macro-deps">deps</a>, <a href="#rust_proc_macro-srcs">srcs</a>, <a href="#rust_proc_macro-data">data</a>, <a href="#rust_proc_macro-aliases">aliases</a>, <a href="#rust_proc_macro-alwayslink">alwayslink</a>, <a href="#rust_proc_macro-compile_data">compile_data</a>, <a href="#rust_proc_macro-crate_features">crate_features</a>, 763 <a href="#rust_proc_macro-crate_name">crate_name</a>, <a href="#rust_proc_macro-crate_root">crate_root</a>, <a href="#rust_proc_macro-edition">edition</a>, <a href="#rust_proc_macro-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_proc_macro-rustc_env">rustc_env</a>, <a href="#rust_proc_macro-rustc_env_files">rustc_env_files</a>, 764 <a href="#rust_proc_macro-rustc_flags">rustc_flags</a>, <a href="#rust_proc_macro-stamp">stamp</a>, <a href="#rust_proc_macro-version">version</a>) 765</pre> 766 767Builds a Rust proc-macro crate. 768 769**ATTRIBUTES** 770 771 772| Name | Description | Type | Mandatory | Default | 773| :------------- | :------------- | :------------- | :------------- | :------------- | 774| <a id="rust_proc_macro-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 775| <a id="rust_proc_macro-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 776| <a id="rust_proc_macro-srcs"></a>srcs | List of Rust `.rs` source files used to build the library.<br><br>If `srcs` contains more than one file, then there must be a file either named `lib.rs`. Otherwise, `crate_root` must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 777| <a id="rust_proc_macro-data"></a>data | List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer `compile_data` over `data`, to prevent the data also being included in the runfiles. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 778| <a id="rust_proc_macro-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target<br><br>These are other `rust_library` targets and will be presented as the new name given. | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` | 779| <a id="rust_proc_macro-alwayslink"></a>alwayslink | If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers. | Boolean | optional | `False` | 780| <a id="rust_proc_macro-compile_data"></a>compile_data | List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [`include_str!`](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 781| <a id="rust_proc_macro-crate_features"></a>crate_features | List of features to enable for this crate.<br><br>Features are defined in the code using the `#[cfg(feature = "foo")]` configuration option. The features listed here will be passed to `rustc` with `--cfg feature="${feature_name}"` flags. | List of strings | optional | `[]` | 782| <a id="rust_proc_macro-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 783| <a id="rust_proc_macro-crate_root"></a>crate_root | The file that will be passed to `rustc` to be used for building this crate.<br><br>If `crate_root` is not set, then this rule will look for a `lib.rs` file (or `main.rs` for rust_binary) or the single file in `srcs` if `srcs` contains only one file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 784| <a id="rust_proc_macro-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | `""` | 785| <a id="rust_proc_macro-proc_macro_deps"></a>proc_macro_deps | List of `rust_proc_macro` targets used to help build this library target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 786| <a id="rust_proc_macro-rustc_env"></a>rustc_env | Dictionary of additional `"key": "value"` environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 787| <a id="rust_proc_macro-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the `stamp` attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. `NAME={WORKSPACE_STATUS_VARIABLE}`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 788| <a id="rust_proc_macro-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 789| <a id="rust_proc_macro-stamp"></a>stamp | Whether to encode build information into the `Rustc` action. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the `Rustc` action, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- `stamp = 0`: Always replace build information by constant values. This gives good build result caching.<br><br>- `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a `rust_library` is stamped, and a `rust_binary` depends on that library, the stamped library won't be rebuilt when we change sources of the `rust_binary`. This is different from how [`cc_library.linkstamps`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp) behaves. | Integer | optional | `0` | 790| <a id="rust_proc_macro-version"></a>version | A version to inject in the cargo environment variable. | String | optional | `"0.0.0"` | 791 792 793<a id="rust_prost_toolchain"></a> 794 795## rust_prost_toolchain 796 797<pre> 798rust_prost_toolchain(<a href="#rust_prost_toolchain-name">name</a>, <a href="#rust_prost_toolchain-prost_opts">prost_opts</a>, <a href="#rust_prost_toolchain-prost_plugin">prost_plugin</a>, <a href="#rust_prost_toolchain-prost_plugin_flag">prost_plugin_flag</a>, <a href="#rust_prost_toolchain-prost_runtime">prost_runtime</a>, <a href="#rust_prost_toolchain-prost_types">prost_types</a>, 799 <a href="#rust_prost_toolchain-proto_compiler">proto_compiler</a>, <a href="#rust_prost_toolchain-tonic_opts">tonic_opts</a>, <a href="#rust_prost_toolchain-tonic_plugin">tonic_plugin</a>, <a href="#rust_prost_toolchain-tonic_plugin_flag">tonic_plugin_flag</a>, <a href="#rust_prost_toolchain-tonic_runtime">tonic_runtime</a>) 800</pre> 801 802Rust Prost toolchain rule. 803 804**ATTRIBUTES** 805 806 807| Name | Description | Type | Mandatory | Default | 808| :------------- | :------------- | :------------- | :------------- | :------------- | 809| <a id="rust_prost_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 810| <a id="rust_prost_toolchain-prost_opts"></a>prost_opts | Additional options to add to Prost. | List of strings | optional | `[]` | 811| <a id="rust_prost_toolchain-prost_plugin"></a>prost_plugin | Additional plugins to add to Prost. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 812| <a id="rust_prost_toolchain-prost_plugin_flag"></a>prost_plugin_flag | Prost plugin flag format. (e.g. `--plugin=protoc-gen-prost=%s`) | String | optional | `"--plugin=protoc-gen-prost=%s"` | 813| <a id="rust_prost_toolchain-prost_runtime"></a>prost_runtime | The Prost runtime crates to use. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 814| <a id="rust_prost_toolchain-prost_types"></a>prost_types | The Prost types crates to use. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 815| <a id="rust_prost_toolchain-proto_compiler"></a>proto_compiler | The protoc compiler to use. Note that this attribute is deprecated - prefer to use --incompatible_enable_proto_toolchain_resolution. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 816| <a id="rust_prost_toolchain-tonic_opts"></a>tonic_opts | Additional options to add to Tonic. | List of strings | optional | `[]` | 817| <a id="rust_prost_toolchain-tonic_plugin"></a>tonic_plugin | Additional plugins to add to Tonic. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 818| <a id="rust_prost_toolchain-tonic_plugin_flag"></a>tonic_plugin_flag | Tonic plugin flag format. (e.g. `--plugin=protoc-gen-tonic=%s`)) | String | optional | `"--plugin=protoc-gen-tonic=%s"` | 819| <a id="rust_prost_toolchain-tonic_runtime"></a>tonic_runtime | The Tonic runtime crates to use. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 820 821 822<a id="rust_proto_library"></a> 823 824## rust_proto_library 825 826<pre> 827rust_proto_library(<a href="#rust_proto_library-name">name</a>, <a href="#rust_proto_library-deps">deps</a>, <a href="#rust_proto_library-crate_name">crate_name</a>, <a href="#rust_proto_library-rust_deps">rust_deps</a>, <a href="#rust_proto_library-rustc_flags">rustc_flags</a>) 828</pre> 829 830Builds a Rust library crate from a set of `proto_library`s. 831 832Example: 833 834```python 835load("@rules_rust//proto/protobuf:defs.bzl", "rust_proto_library") 836 837proto_library( 838 name = "my_proto", 839 srcs = ["my.proto"] 840) 841 842rust_proto_library( 843 name = "rust", 844 deps = [":my_proto"], 845) 846 847rust_binary( 848 name = "my_proto_binary", 849 srcs = ["my_proto_binary.rs"], 850 deps = [":rust"], 851) 852``` 853 854**ATTRIBUTES** 855 856 857| Name | Description | Type | Mandatory | Default | 858| :------------- | :------------- | :------------- | :------------- | :------------- | 859| <a id="rust_proto_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 860| <a id="rust_proto_library-deps"></a>deps | List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding stubs. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | | 861| <a id="rust_proto_library-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 862| <a id="rust_proto_library-rust_deps"></a>rust_deps | The crates the generated library depends on. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 863| <a id="rust_proto_library-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 864 865 866<a id="rust_shared_library"></a> 867 868## rust_shared_library 869 870<pre> 871rust_shared_library(<a href="#rust_shared_library-name">name</a>, <a href="#rust_shared_library-deps">deps</a>, <a href="#rust_shared_library-srcs">srcs</a>, <a href="#rust_shared_library-data">data</a>, <a href="#rust_shared_library-aliases">aliases</a>, <a href="#rust_shared_library-alwayslink">alwayslink</a>, <a href="#rust_shared_library-compile_data">compile_data</a>, <a href="#rust_shared_library-crate_features">crate_features</a>, 872 <a href="#rust_shared_library-crate_name">crate_name</a>, <a href="#rust_shared_library-crate_root">crate_root</a>, <a href="#rust_shared_library-edition">edition</a>, <a href="#rust_shared_library-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="#rust_shared_library-malloc">malloc</a>, 873 <a href="#rust_shared_library-platform">platform</a>, <a href="#rust_shared_library-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_shared_library-rustc_env">rustc_env</a>, <a href="#rust_shared_library-rustc_env_files">rustc_env_files</a>, <a href="#rust_shared_library-rustc_flags">rustc_flags</a>, <a href="#rust_shared_library-stamp">stamp</a>, 874 <a href="#rust_shared_library-version">version</a>) 875</pre> 876 877Builds a Rust shared library. 878 879This shared library will contain all transitively reachable crates and native objects. 880It is meant to be used when producing an artifact that is then consumed by some other build system 881(for example to produce a shared library that Python program links against). 882 883This rule provides CcInfo, so it can be used everywhere Bazel expects `rules_cc`. 884 885When building the whole binary in Bazel, use `rust_library` instead. 886 887**ATTRIBUTES** 888 889 890| Name | Description | Type | Mandatory | Default | 891| :------------- | :------------- | :------------- | :------------- | :------------- | 892| <a id="rust_shared_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 893| <a id="rust_shared_library-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 894| <a id="rust_shared_library-srcs"></a>srcs | List of Rust `.rs` source files used to build the library.<br><br>If `srcs` contains more than one file, then there must be a file either named `lib.rs`. Otherwise, `crate_root` must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 895| <a id="rust_shared_library-data"></a>data | List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer `compile_data` over `data`, to prevent the data also being included in the runfiles. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 896| <a id="rust_shared_library-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target<br><br>These are other `rust_library` targets and will be presented as the new name given. | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` | 897| <a id="rust_shared_library-alwayslink"></a>alwayslink | If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers. | Boolean | optional | `False` | 898| <a id="rust_shared_library-compile_data"></a>compile_data | List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [`include_str!`](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 899| <a id="rust_shared_library-crate_features"></a>crate_features | List of features to enable for this crate.<br><br>Features are defined in the code using the `#[cfg(feature = "foo")]` configuration option. The features listed here will be passed to `rustc` with `--cfg feature="${feature_name}"` flags. | List of strings | optional | `[]` | 900| <a id="rust_shared_library-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 901| <a id="rust_shared_library-crate_root"></a>crate_root | The file that will be passed to `rustc` to be used for building this crate.<br><br>If `crate_root` is not set, then this rule will look for a `lib.rs` file (or `main.rs` for rust_binary) or the single file in `srcs` if `srcs` contains only one file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 902| <a id="rust_shared_library-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | `""` | 903| <a id="rust_shared_library-experimental_use_cc_common_link"></a>experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | `-1` | 904| <a id="rust_shared_library-malloc"></a>malloc | Override the default dependency on `malloc`.<br><br>By default, Rust binaries linked with cc_common.link are linked against `@bazel_tools//tools/cpp:malloc"`, which is an empty library and the resulting binary will use libc's `malloc`. This label must refer to a `cc_library` rule. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@bazel_tools//tools/cpp:malloc"` | 905| <a id="rust_shared_library-platform"></a>platform | Optional platform to transition the shared library to. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 906| <a id="rust_shared_library-proc_macro_deps"></a>proc_macro_deps | List of `rust_proc_macro` targets used to help build this library target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 907| <a id="rust_shared_library-rustc_env"></a>rustc_env | Dictionary of additional `"key": "value"` environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 908| <a id="rust_shared_library-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the `stamp` attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. `NAME={WORKSPACE_STATUS_VARIABLE}`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 909| <a id="rust_shared_library-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 910| <a id="rust_shared_library-stamp"></a>stamp | Whether to encode build information into the `Rustc` action. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the `Rustc` action, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- `stamp = 0`: Always replace build information by constant values. This gives good build result caching.<br><br>- `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a `rust_library` is stamped, and a `rust_binary` depends on that library, the stamped library won't be rebuilt when we change sources of the `rust_binary`. This is different from how [`cc_library.linkstamps`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp) behaves. | Integer | optional | `0` | 911| <a id="rust_shared_library-version"></a>version | A version to inject in the cargo environment variable. | String | optional | `"0.0.0"` | 912 913 914<a id="rust_static_library"></a> 915 916## rust_static_library 917 918<pre> 919rust_static_library(<a href="#rust_static_library-name">name</a>, <a href="#rust_static_library-deps">deps</a>, <a href="#rust_static_library-srcs">srcs</a>, <a href="#rust_static_library-data">data</a>, <a href="#rust_static_library-aliases">aliases</a>, <a href="#rust_static_library-alwayslink">alwayslink</a>, <a href="#rust_static_library-compile_data">compile_data</a>, <a href="#rust_static_library-crate_features">crate_features</a>, 920 <a href="#rust_static_library-crate_name">crate_name</a>, <a href="#rust_static_library-crate_root">crate_root</a>, <a href="#rust_static_library-edition">edition</a>, <a href="#rust_static_library-platform">platform</a>, <a href="#rust_static_library-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_static_library-rustc_env">rustc_env</a>, 921 <a href="#rust_static_library-rustc_env_files">rustc_env_files</a>, <a href="#rust_static_library-rustc_flags">rustc_flags</a>, <a href="#rust_static_library-stamp">stamp</a>, <a href="#rust_static_library-version">version</a>) 922</pre> 923 924Builds a Rust static library. 925 926This static library will contain all transitively reachable crates and native objects. 927It is meant to be used when producing an artifact that is then consumed by some other build system 928(for example to produce an archive that Python program links against). 929 930This rule provides CcInfo, so it can be used everywhere Bazel expects `rules_cc`. 931 932When building the whole binary in Bazel, use `rust_library` instead. 933 934**ATTRIBUTES** 935 936 937| Name | Description | Type | Mandatory | Default | 938| :------------- | :------------- | :------------- | :------------- | :------------- | 939| <a id="rust_static_library-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 940| <a id="rust_static_library-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 941| <a id="rust_static_library-srcs"></a>srcs | List of Rust `.rs` source files used to build the library.<br><br>If `srcs` contains more than one file, then there must be a file either named `lib.rs`. Otherwise, `crate_root` must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 942| <a id="rust_static_library-data"></a>data | List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer `compile_data` over `data`, to prevent the data also being included in the runfiles. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 943| <a id="rust_static_library-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target<br><br>These are other `rust_library` targets and will be presented as the new name given. | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` | 944| <a id="rust_static_library-alwayslink"></a>alwayslink | If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers. | Boolean | optional | `False` | 945| <a id="rust_static_library-compile_data"></a>compile_data | List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [`include_str!`](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 946| <a id="rust_static_library-crate_features"></a>crate_features | List of features to enable for this crate.<br><br>Features are defined in the code using the `#[cfg(feature = "foo")]` configuration option. The features listed here will be passed to `rustc` with `--cfg feature="${feature_name}"` flags. | List of strings | optional | `[]` | 947| <a id="rust_static_library-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 948| <a id="rust_static_library-crate_root"></a>crate_root | The file that will be passed to `rustc` to be used for building this crate.<br><br>If `crate_root` is not set, then this rule will look for a `lib.rs` file (or `main.rs` for rust_binary) or the single file in `srcs` if `srcs` contains only one file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 949| <a id="rust_static_library-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | `""` | 950| <a id="rust_static_library-platform"></a>platform | Optional platform to transition the static library to. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 951| <a id="rust_static_library-proc_macro_deps"></a>proc_macro_deps | List of `rust_proc_macro` targets used to help build this library target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 952| <a id="rust_static_library-rustc_env"></a>rustc_env | Dictionary of additional `"key": "value"` environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 953| <a id="rust_static_library-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the `stamp` attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. `NAME={WORKSPACE_STATUS_VARIABLE}`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 954| <a id="rust_static_library-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 955| <a id="rust_static_library-stamp"></a>stamp | Whether to encode build information into the `Rustc` action. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the `Rustc` action, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- `stamp = 0`: Always replace build information by constant values. This gives good build result caching.<br><br>- `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a `rust_library` is stamped, and a `rust_binary` depends on that library, the stamped library won't be rebuilt when we change sources of the `rust_binary`. This is different from how [`cc_library.linkstamps`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp) behaves. | Integer | optional | `0` | 956| <a id="rust_static_library-version"></a>version | A version to inject in the cargo environment variable. | String | optional | `"0.0.0"` | 957 958 959<a id="rust_stdlib_filegroup"></a> 960 961## rust_stdlib_filegroup 962 963<pre> 964rust_stdlib_filegroup(<a href="#rust_stdlib_filegroup-name">name</a>, <a href="#rust_stdlib_filegroup-srcs">srcs</a>) 965</pre> 966 967A dedicated filegroup-like rule for Rust stdlib artifacts. 968 969**ATTRIBUTES** 970 971 972| Name | Description | Type | Mandatory | Default | 973| :------------- | :------------- | :------------- | :------------- | :------------- | 974| <a id="rust_stdlib_filegroup-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 975| <a id="rust_stdlib_filegroup-srcs"></a>srcs | The list of targets/files that are components of the rust-stdlib file group | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | | 976 977 978<a id="rust_test"></a> 979 980## rust_test 981 982<pre> 983rust_test(<a href="#rust_test-name">name</a>, <a href="#rust_test-deps">deps</a>, <a href="#rust_test-srcs">srcs</a>, <a href="#rust_test-data">data</a>, <a href="#rust_test-aliases">aliases</a>, <a href="#rust_test-alwayslink">alwayslink</a>, <a href="#rust_test-compile_data">compile_data</a>, <a href="#rust_test-crate">crate</a>, <a href="#rust_test-crate_features">crate_features</a>, 984 <a href="#rust_test-crate_name">crate_name</a>, <a href="#rust_test-crate_root">crate_root</a>, <a href="#rust_test-edition">edition</a>, <a href="#rust_test-env">env</a>, <a href="#rust_test-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="#rust_test-malloc">malloc</a>, <a href="#rust_test-platform">platform</a>, 985 <a href="#rust_test-proc_macro_deps">proc_macro_deps</a>, <a href="#rust_test-rustc_env">rustc_env</a>, <a href="#rust_test-rustc_env_files">rustc_env_files</a>, <a href="#rust_test-rustc_flags">rustc_flags</a>, <a href="#rust_test-stamp">stamp</a>, <a href="#rust_test-use_libtest_harness">use_libtest_harness</a>, 986 <a href="#rust_test-version">version</a>) 987</pre> 988 989Builds a Rust test crate. 990 991Examples: 992 993Suppose you have the following directory structure for a Rust library crate with unit test code in the library sources: 994 995```output 996[workspace]/ 997 WORKSPACE 998 hello_lib/ 999 BUILD 1000 src/ 1001 lib.rs 1002``` 1003 1004`hello_lib/src/lib.rs`: 1005```rust 1006pub struct Greeter { 1007 greeting: String, 1008} 1009 1010impl Greeter { 1011 pub fn new(greeting: &str) -> Greeter { 1012 Greeter { greeting: greeting.to_string(), } 1013 } 1014 1015 pub fn greet(&self, thing: &str) -> String { 1016 format!("{} {}", &self.greeting, thing) 1017 } 1018} 1019 1020#[cfg(test)] 1021mod test { 1022 use super::Greeter; 1023 1024 #[test] 1025 fn test_greeting() { 1026 let hello = Greeter::new("Hi"); 1027 assert_eq!("Hi Rust", hello.greet("Rust")); 1028 } 1029} 1030``` 1031 1032To build and run the tests, simply add a `rust_test` rule with no `srcs` 1033and only depends on the `hello_lib` `rust_library` target via the 1034`crate` attribute: 1035 1036`hello_lib/BUILD`: 1037```python 1038load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 1039 1040rust_library( 1041 name = "hello_lib", 1042 srcs = ["src/lib.rs"], 1043) 1044 1045rust_test( 1046 name = "hello_lib_test", 1047 crate = ":hello_lib", 1048 # You may add other deps that are specific to the test configuration 1049 deps = ["//some/dev/dep"], 1050) 1051``` 1052 1053Run the test with `bazel test //hello_lib:hello_lib_test`. The crate 1054will be built using the same crate name as the underlying ":hello_lib" 1055crate. 1056 1057### Example: `test` directory 1058 1059Integration tests that live in the [`tests` directory][int-tests], they are essentially built as separate crates. Suppose you have the following directory structure where `greeting.rs` is an integration test for the `hello_lib` library crate: 1060 1061[int-tests]: http://doc.rust-lang.org/book/testing.html#the-tests-directory 1062 1063```output 1064[workspace]/ 1065 WORKSPACE 1066 hello_lib/ 1067 BUILD 1068 src/ 1069 lib.rs 1070 tests/ 1071 greeting.rs 1072``` 1073 1074`hello_lib/tests/greeting.rs`: 1075```rust 1076extern crate hello_lib; 1077 1078use hello_lib; 1079 1080#[test] 1081fn test_greeting() { 1082 let hello = greeter::Greeter::new("Hello"); 1083 assert_eq!("Hello world", hello.greeting("world")); 1084} 1085``` 1086 1087To build the `greeting.rs` integration test, simply add a `rust_test` target 1088with `greeting.rs` in `srcs` and a dependency on the `hello_lib` target: 1089 1090`hello_lib/BUILD`: 1091```python 1092load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 1093 1094rust_library( 1095 name = "hello_lib", 1096 srcs = ["src/lib.rs"], 1097) 1098 1099rust_test( 1100 name = "greeting_test", 1101 srcs = ["tests/greeting.rs"], 1102 deps = [":hello_lib"], 1103) 1104``` 1105 1106Run the test with `bazel test //hello_lib:greeting_test`. 1107 1108**ATTRIBUTES** 1109 1110 1111| Name | Description | Type | Mandatory | Default | 1112| :------------- | :------------- | :------------- | :------------- | :------------- | 1113| <a id="rust_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 1114| <a id="rust_test-deps"></a>deps | List of other libraries to be linked to this library target.<br><br>These can be either other `rust_library` targets or `cc_library` targets if linking a native library. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1115| <a id="rust_test-srcs"></a>srcs | List of Rust `.rs` source files used to build the library.<br><br>If `srcs` contains more than one file, then there must be a file either named `lib.rs`. Otherwise, `crate_root` must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1116| <a id="rust_test-data"></a>data | List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer `compile_data` over `data`, to prevent the data also being included in the runfiles. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1117| <a id="rust_test-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target<br><br>These are other `rust_library` targets and will be presented as the new name given. | <a href="https://bazel.build/rules/lib/dict">Dictionary: Label -> String</a> | optional | `{}` | 1118| <a id="rust_test-alwayslink"></a>alwayslink | If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers. | Boolean | optional | `False` | 1119| <a id="rust_test-compile_data"></a>compile_data | List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the [`include_str!`](https://doc.rust-lang.org/std/macro.include_str!.html) macro. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1120| <a id="rust_test-crate"></a>crate | Target inline tests declared in the given crate<br><br>These tests are typically those that would be held out under `#[cfg(test)]` declarations. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1121| <a id="rust_test-crate_features"></a>crate_features | List of features to enable for this crate.<br><br>Features are defined in the code using the `#[cfg(feature = "foo")]` configuration option. The features listed here will be passed to `rustc` with `--cfg feature="${feature_name}"` flags. | List of strings | optional | `[]` | 1122| <a id="rust_test-crate_name"></a>crate_name | Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores. | String | optional | `""` | 1123| <a id="rust_test-crate_root"></a>crate_root | The file that will be passed to `rustc` to be used for building this crate.<br><br>If `crate_root` is not set, then this rule will look for a `lib.rs` file (or `main.rs` for rust_binary) or the single file in `srcs` if `srcs` contains only one file. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1124| <a id="rust_test-edition"></a>edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | `""` | 1125| <a id="rust_test-env"></a>env | Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to `$(rootpath)`, `$(execpath)`, location, and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 1126| <a id="rust_test-experimental_use_cc_common_link"></a>experimental_use_cc_common_link | Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link. | Integer | optional | `-1` | 1127| <a id="rust_test-malloc"></a>malloc | Override the default dependency on `malloc`.<br><br>By default, Rust binaries linked with cc_common.link are linked against `@bazel_tools//tools/cpp:malloc"`, which is an empty library and the resulting binary will use libc's `malloc`. This label must refer to a `cc_library` rule. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@bazel_tools//tools/cpp:malloc"` | 1128| <a id="rust_test-platform"></a>platform | Optional platform to transition the test to. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1129| <a id="rust_test-proc_macro_deps"></a>proc_macro_deps | List of `rust_proc_macro` targets used to help build this library target. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1130| <a id="rust_test-rustc_env"></a>rustc_env | Dictionary of additional `"key": "value"` environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 1131| <a id="rust_test-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format `NAME=value`, and newlines may be included in a value by ending a line with a trailing back-slash (`\\`).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to [workspace status](https://docs.bazel.build/versions/main/user-manual.html#workspace_status) stamping should the `stamp` attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. `NAME={WORKSPACE_STATUS_VARIABLE}`. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1132| <a id="rust_test-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like `$location`, `$execpath`, and `$rootpath`. This expansion is useful if you wish to pass a generated file of arguments to rustc: `@$(location //package:target)`. | List of strings | optional | `[]` | 1133| <a id="rust_test-stamp"></a>stamp | Whether to encode build information into the `Rustc` action. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the `Rustc` action, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- `stamp = 0`: Always replace build information by constant values. This gives good build result caching.<br><br>- `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a `rust_library` is stamped, and a `rust_binary` depends on that library, the stamped library won't be rebuilt when we change sources of the `rust_binary`. This is different from how [`cc_library.linkstamps`](https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp) behaves. | Integer | optional | `0` | 1134| <a id="rust_test-use_libtest_harness"></a>use_libtest_harness | Whether to use `libtest`. For targets using this flag, individual tests can be run by using the [--test_arg](https://docs.bazel.build/versions/4.0.0/command-line-reference.html#flag--test_arg) flag. E.g. `bazel test //src:rust_test --test_arg=foo::test::test_fn`. | Boolean | optional | `True` | 1135| <a id="rust_test-version"></a>version | A version to inject in the cargo environment variable. | String | optional | `"0.0.0"` | 1136 1137 1138<a id="rust_toolchain"></a> 1139 1140## rust_toolchain 1141 1142<pre> 1143rust_toolchain(<a href="#rust_toolchain-name">name</a>, <a href="#rust_toolchain-allocator_library">allocator_library</a>, <a href="#rust_toolchain-binary_ext">binary_ext</a>, <a href="#rust_toolchain-cargo">cargo</a>, <a href="#rust_toolchain-cargo_clippy">cargo_clippy</a>, <a href="#rust_toolchain-clippy_driver">clippy_driver</a>, <a href="#rust_toolchain-debug_info">debug_info</a>, 1144 <a href="#rust_toolchain-default_edition">default_edition</a>, <a href="#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="#rust_toolchain-env">env</a>, <a href="#rust_toolchain-exec_triple">exec_triple</a>, <a href="#rust_toolchain-experimental_link_std_dylib">experimental_link_std_dylib</a>, 1145 <a href="#rust_toolchain-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="#rust_toolchain-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain-extra_rustc_flags">extra_rustc_flags</a>, 1146 <a href="#rust_toolchain-extra_rustc_flags_for_crate_types">extra_rustc_flags_for_crate_types</a>, <a href="#rust_toolchain-global_allocator_library">global_allocator_library</a>, <a href="#rust_toolchain-llvm_cov">llvm_cov</a>, <a href="#rust_toolchain-llvm_profdata">llvm_profdata</a>, 1147 <a href="#rust_toolchain-llvm_tools">llvm_tools</a>, <a href="#rust_toolchain-opt_level">opt_level</a>, <a href="#rust_toolchain-per_crate_rustc_flags">per_crate_rustc_flags</a>, <a href="#rust_toolchain-rust_doc">rust_doc</a>, <a href="#rust_toolchain-rust_std">rust_std</a>, <a href="#rust_toolchain-rustc">rustc</a>, <a href="#rust_toolchain-rustc_lib">rustc_lib</a>, 1148 <a href="#rust_toolchain-rustfmt">rustfmt</a>, <a href="#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="#rust_toolchain-strip_level">strip_level</a>, <a href="#rust_toolchain-target_json">target_json</a>, <a href="#rust_toolchain-target_triple">target_triple</a>) 1149</pre> 1150 1151Declares a Rust toolchain for use. 1152 1153This is for declaring a custom toolchain, eg. for configuring a particular version of rust or supporting a new platform. 1154 1155Example: 1156 1157Suppose the core rust team has ported the compiler to a new target CPU, called `cpuX`. This support can be used in Bazel by defining a new toolchain definition and declaration: 1158 1159```python 1160load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain') 1161 1162rust_toolchain( 1163 name = "rust_cpuX_impl", 1164 binary_ext = "", 1165 dylib_ext = ".so", 1166 exec_triple = "cpuX-unknown-linux-gnu", 1167 rust_doc = "@rust_cpuX//:rustdoc", 1168 rust_std = "@rust_cpuX//:rust_std", 1169 rustc = "@rust_cpuX//:rustc", 1170 rustc_lib = "@rust_cpuX//:rustc_lib", 1171 staticlib_ext = ".a", 1172 stdlib_linkflags = ["-lpthread", "-ldl"], 1173 target_triple = "cpuX-unknown-linux-gnu", 1174) 1175 1176toolchain( 1177 name = "rust_cpuX", 1178 exec_compatible_with = [ 1179 "@platforms//cpu:cpuX", 1180 "@platforms//os:linux", 1181 ], 1182 target_compatible_with = [ 1183 "@platforms//cpu:cpuX", 1184 "@platforms//os:linux", 1185 ], 1186 toolchain = ":rust_cpuX_impl", 1187) 1188``` 1189 1190Then, either add the label of the toolchain rule to `register_toolchains` in the WORKSPACE, or pass it to the `"--extra_toolchains"` flag for Bazel, and it will be used. 1191 1192See `@rules_rust//rust:repositories.bzl` for examples of defining the `@rust_cpuX` repository with the actual binaries and libraries. 1193 1194**ATTRIBUTES** 1195 1196 1197| Name | Description | Type | Mandatory | Default | 1198| :------------- | :------------- | :------------- | :------------- | :------------- | 1199| <a id="rust_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 1200| <a id="rust_toolchain-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@rules_rust//ffi/cc/allocator_library"` | 1201| <a id="rust_toolchain-binary_ext"></a>binary_ext | The extension for binaries created from rustc. | String | required | | 1202| <a id="rust_toolchain-cargo"></a>cargo | The location of the `cargo` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1203| <a id="rust_toolchain-cargo_clippy"></a>cargo_clippy | The location of the `cargo_clippy` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1204| <a id="rust_toolchain-clippy_driver"></a>clippy_driver | The location of the `clippy-driver` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1205| <a id="rust_toolchain-debug_info"></a>debug_info | Rustc debug info levels per opt level | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{"dbg": "2", "fastbuild": "0", "opt": "0"}` | 1206| <a id="rust_toolchain-default_edition"></a>default_edition | The edition to use for rust_* rules that don't specify an edition. If absent, every rule is required to specify its `edition` attribute. | String | optional | `""` | 1207| <a id="rust_toolchain-dylib_ext"></a>dylib_ext | The extension for dynamic libraries created from rustc. | String | required | | 1208| <a id="rust_toolchain-env"></a>env | Environment variables to set in actions. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 1209| <a id="rust_toolchain-exec_triple"></a>exec_triple | The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | required | | 1210| <a id="rust_toolchain-experimental_link_std_dylib"></a>experimental_link_std_dylib | Label to a boolean build setting that controls whether whether to link libstd dynamically. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@rules_rust//rust/settings:experimental_link_std_dylib"` | 1211| <a id="rust_toolchain-experimental_use_cc_common_link"></a>experimental_use_cc_common_link | Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@rules_rust//rust/settings:experimental_use_cc_common_link"` | 1212| <a id="rust_toolchain-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | `[]` | 1213| <a id="rust_toolchain-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration. Subject to location expansion with respect to the srcs of the `rust_std` attribute. | List of strings | optional | `[]` | 1214| <a id="rust_toolchain-extra_rustc_flags_for_crate_types"></a>extra_rustc_flags_for_crate_types | Extra flags to pass to rustc based on crate type | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a> | optional | `{}` | 1215| <a id="rust_toolchain-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions for when a global allocator is present. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `"@rules_rust//ffi/cc/global_allocator_library"` | 1216| <a id="rust_toolchain-llvm_cov"></a>llvm_cov | The location of the `llvm-cov` binary. Can be a direct source or a filegroup containing one item. If None, rust code is not instrumented for coverage. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1217| <a id="rust_toolchain-llvm_profdata"></a>llvm_profdata | The location of the `llvm-profdata` binary. Can be a direct source or a filegroup containing one item. If `llvm_cov` is None, this can be None as well and rust code is not instrumented for coverage. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1218| <a id="rust_toolchain-llvm_tools"></a>llvm_tools | LLVM tools that are shipped with the Rust toolchain. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1219| <a id="rust_toolchain-opt_level"></a>opt_level | Rustc optimization levels. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{"dbg": "0", "fastbuild": "0", "opt": "3"}` | 1220| <a id="rust_toolchain-per_crate_rustc_flags"></a>per_crate_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | `[]` | 1221| <a id="rust_toolchain-rust_doc"></a>rust_doc | The location of the `rustdoc` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 1222| <a id="rust_toolchain-rust_std"></a>rust_std | The Rust standard library. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 1223| <a id="rust_toolchain-rustc"></a>rustc | The location of the `rustc` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 1224| <a id="rust_toolchain-rustc_lib"></a>rustc_lib | The libraries used by rustc during compilation. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1225| <a id="rust_toolchain-rustfmt"></a>rustfmt | **Deprecated**: Instead see [rustfmt_toolchain](#rustfmt_toolchain) | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1226| <a id="rust_toolchain-staticlib_ext"></a>staticlib_ext | The extension for static libraries created from rustc. | String | required | | 1227| <a id="rust_toolchain-stdlib_linkflags"></a>stdlib_linkflags | Additional linker flags to use when Rust standard library is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the `rust_std` attribute. | List of strings | required | | 1228| <a id="rust_toolchain-strip_level"></a>strip_level | Rustc strip levels. For all potential options, see https://doc.rust-lang.org/rustc/codegen-options/index.html#strip | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{"dbg": "none", "fastbuild": "none", "opt": "debuginfo"}` | 1229| <a id="rust_toolchain-target_json"></a>target_json | Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html | String | optional | `""` | 1230| <a id="rust_toolchain-target_triple"></a>target_triple | The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations | String | optional | `""` | 1231 1232 1233<a id="rust_wasm_bindgen"></a> 1234 1235## rust_wasm_bindgen 1236 1237<pre> 1238rust_wasm_bindgen(<a href="#rust_wasm_bindgen-name">name</a>, <a href="#rust_wasm_bindgen-bindgen_flags">bindgen_flags</a>, <a href="#rust_wasm_bindgen-target">target</a>, <a href="#rust_wasm_bindgen-wasm_file">wasm_file</a>) 1239</pre> 1240 1241Generates javascript and typescript bindings for a webassembly module using [wasm-bindgen][ws]. 1242 1243[ws]: https://rustwasm.github.io/docs/wasm-bindgen/ 1244 1245An example of this rule in use can be seen at [@rules_rust//examples/wasm](../examples/wasm) 1246 1247**ATTRIBUTES** 1248 1249 1250| Name | Description | Type | Mandatory | Default | 1251| :------------- | :------------- | :------------- | :------------- | :------------- | 1252| <a id="rust_wasm_bindgen-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 1253| <a id="rust_wasm_bindgen-bindgen_flags"></a>bindgen_flags | Flags to pass directly to the bindgen executable. See https://github.com/rustwasm/wasm-bindgen/ for details. | List of strings | optional | `[]` | 1254| <a id="rust_wasm_bindgen-target"></a>target | The type of output to generate. See https://rustwasm.github.io/wasm-bindgen/reference/deployment.html for details. | String | optional | `"bundler"` | 1255| <a id="rust_wasm_bindgen-wasm_file"></a>wasm_file | The `.wasm` file or crate to generate bindings for. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 1256 1257 1258<a id="rust_wasm_bindgen_toolchain"></a> 1259 1260## rust_wasm_bindgen_toolchain 1261 1262<pre> 1263rust_wasm_bindgen_toolchain(<a href="#rust_wasm_bindgen_toolchain-name">name</a>, <a href="#rust_wasm_bindgen_toolchain-bindgen">bindgen</a>) 1264</pre> 1265 1266The tools required for the `rust_wasm_bindgen` rule. 1267 1268In cases where users want to control or change the version of `wasm-bindgen` used by [rust_wasm_bindgen](#rust_wasm_bindgen), 1269a unique toolchain can be created as in the example below: 1270 1271```python 1272load("@rules_rust//bindgen:bindgen.bzl", "rust_bindgen_toolchain") 1273 1274rust_bindgen_toolchain( 1275 bindgen = "//3rdparty/crates:wasm_bindgen_cli__bin", 1276) 1277 1278toolchain( 1279 name = "wasm_bindgen_toolchain", 1280 toolchain = "wasm_bindgen_toolchain_impl", 1281 toolchain_type = "@rules_rust//wasm_bindgen:toolchain_type", 1282) 1283``` 1284 1285Now that you have your own toolchain, you need to register it by 1286inserting the following statement in your `WORKSPACE` file: 1287 1288```python 1289register_toolchains("//my/toolchains:wasm_bindgen_toolchain") 1290``` 1291 1292For additional information, see the [Bazel toolchains documentation][toolchains]. 1293 1294[toolchains]: https://docs.bazel.build/versions/master/toolchains.html 1295 1296**ATTRIBUTES** 1297 1298 1299| Name | Description | Type | Mandatory | Default | 1300| :------------- | :------------- | :------------- | :------------- | :------------- | 1301| <a id="rust_wasm_bindgen_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 1302| <a id="rust_wasm_bindgen_toolchain-bindgen"></a>bindgen | The label of a `wasm-bindgen-cli` executable. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1303 1304 1305<a id="rustfmt_test"></a> 1306 1307## rustfmt_test 1308 1309<pre> 1310rustfmt_test(<a href="#rustfmt_test-name">name</a>, <a href="#rustfmt_test-targets">targets</a>) 1311</pre> 1312 1313A test rule for performing `rustfmt --check` on a set of targets 1314 1315**ATTRIBUTES** 1316 1317 1318| Name | Description | Type | Mandatory | Default | 1319| :------------- | :------------- | :------------- | :------------- | :------------- | 1320| <a id="rustfmt_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 1321| <a id="rustfmt_test-targets"></a>targets | Rust targets to run `rustfmt --check` on. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 1322 1323 1324<a id="rustfmt_toolchain"></a> 1325 1326## rustfmt_toolchain 1327 1328<pre> 1329rustfmt_toolchain(<a href="#rustfmt_toolchain-name">name</a>, <a href="#rustfmt_toolchain-rustc">rustc</a>, <a href="#rustfmt_toolchain-rustc_lib">rustc_lib</a>, <a href="#rustfmt_toolchain-rustfmt">rustfmt</a>) 1330</pre> 1331 1332A toolchain for [rustfmt](https://rust-lang.github.io/rustfmt/) 1333 1334**ATTRIBUTES** 1335 1336 1337| Name | Description | Type | Mandatory | Default | 1338| :------------- | :------------- | :------------- | :------------- | :------------- | 1339| <a id="rustfmt_toolchain-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 1340| <a id="rustfmt_toolchain-rustc"></a>rustc | The location of the `rustc` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1341| <a id="rustfmt_toolchain-rustc_lib"></a>rustc_lib | The libraries used by rustc during compilation. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` | 1342| <a id="rustfmt_toolchain-rustfmt"></a>rustfmt | The location of the `rustfmt` binary. Can be a direct source or a filegroup containing one item. | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 1343 1344 1345<a id="CrateInfo"></a> 1346 1347## CrateInfo 1348 1349<pre> 1350CrateInfo(<a href="#CrateInfo-aliases">aliases</a>, <a href="#CrateInfo-compile_data">compile_data</a>, <a href="#CrateInfo-compile_data_targets">compile_data_targets</a>, <a href="#CrateInfo-data">data</a>, <a href="#CrateInfo-deps">deps</a>, <a href="#CrateInfo-edition">edition</a>, <a href="#CrateInfo-is_test">is_test</a>, <a href="#CrateInfo-metadata">metadata</a>, <a href="#CrateInfo-name">name</a>, 1351 <a href="#CrateInfo-output">output</a>, <a href="#CrateInfo-owner">owner</a>, <a href="#CrateInfo-proc_macro_deps">proc_macro_deps</a>, <a href="#CrateInfo-root">root</a>, <a href="#CrateInfo-rustc_env">rustc_env</a>, <a href="#CrateInfo-rustc_env_files">rustc_env_files</a>, <a href="#CrateInfo-rustc_output">rustc_output</a>, 1352 <a href="#CrateInfo-rustc_rmeta_output">rustc_rmeta_output</a>, <a href="#CrateInfo-srcs">srcs</a>, <a href="#CrateInfo-std_dylib">std_dylib</a>, <a href="#CrateInfo-type">type</a>, <a href="#CrateInfo-wrapped_crate_type">wrapped_crate_type</a>) 1353</pre> 1354 1355A provider containing general Crate information. 1356 1357**FIELDS** 1358 1359 1360| Name | Description | 1361| :------------- | :------------- | 1362| <a id="CrateInfo-aliases"></a>aliases | Dict[Label, String]: Renamed and aliased crates | 1363| <a id="CrateInfo-compile_data"></a>compile_data | depset[File]: Compile data required by this crate. | 1364| <a id="CrateInfo-compile_data_targets"></a>compile_data_targets | depset[Label]: Compile data targets required by this crate. | 1365| <a id="CrateInfo-data"></a>data | depset[File]: Compile data required by crates that use the current crate as a proc-macro. | 1366| <a id="CrateInfo-deps"></a>deps | depset[DepVariantInfo]: This crate's (rust or cc) dependencies' providers. | 1367| <a id="CrateInfo-edition"></a>edition | str: The edition of this crate. | 1368| <a id="CrateInfo-is_test"></a>is_test | bool: If the crate is being compiled in a test context | 1369| <a id="CrateInfo-metadata"></a>metadata | File: The output from rustc from producing the output file. It is optional. | 1370| <a id="CrateInfo-name"></a>name | str: The name of this crate. | 1371| <a id="CrateInfo-output"></a>output | File: The output File that will be produced, depends on crate type. | 1372| <a id="CrateInfo-owner"></a>owner | Label: The label of the target that produced this CrateInfo | 1373| <a id="CrateInfo-proc_macro_deps"></a>proc_macro_deps | depset[DepVariantInfo]: This crate's rust proc_macro dependencies' providers. | 1374| <a id="CrateInfo-root"></a>root | File: The source File entrypoint to this crate, eg. lib.rs | 1375| <a id="CrateInfo-rustc_env"></a>rustc_env | Dict[String, String]: Additional `"key": "value"` environment variables to set for rustc. | 1376| <a id="CrateInfo-rustc_env_files"></a>rustc_env_files | [File]: Files containing additional environment variables to set for rustc. | 1377| <a id="CrateInfo-rustc_output"></a>rustc_output | File: The output from rustc from producing the output file. It is optional. | 1378| <a id="CrateInfo-rustc_rmeta_output"></a>rustc_rmeta_output | File: The rmeta file produced for this crate. It is optional. | 1379| <a id="CrateInfo-srcs"></a>srcs | depset[File]: All source Files that are part of the crate. | 1380| <a id="CrateInfo-std_dylib"></a>std_dylib | File: libstd.so file | 1381| <a id="CrateInfo-type"></a>type | str: The type of this crate (see [rustc --crate-type](https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit)). | 1382| <a id="CrateInfo-wrapped_crate_type"></a>wrapped_crate_type | str, optional: The original crate type for targets generated using a previously defined crate (typically tests using the `rust_test::crate` attribute) | 1383 1384 1385<a id="DepInfo"></a> 1386 1387## DepInfo 1388 1389<pre> 1390DepInfo(<a href="#DepInfo-dep_env">dep_env</a>, <a href="#DepInfo-direct_crates">direct_crates</a>, <a href="#DepInfo-link_search_path_files">link_search_path_files</a>, <a href="#DepInfo-transitive_build_infos">transitive_build_infos</a>, 1391 <a href="#DepInfo-transitive_crate_outputs">transitive_crate_outputs</a>, <a href="#DepInfo-transitive_crates">transitive_crates</a>, <a href="#DepInfo-transitive_data">transitive_data</a>, <a href="#DepInfo-transitive_metadata_outputs">transitive_metadata_outputs</a>, 1392 <a href="#DepInfo-transitive_noncrates">transitive_noncrates</a>, <a href="#DepInfo-transitive_proc_macro_data">transitive_proc_macro_data</a>) 1393</pre> 1394 1395A provider containing information about a Crate's dependencies. 1396 1397**FIELDS** 1398 1399 1400| Name | Description | 1401| :------------- | :------------- | 1402| <a id="DepInfo-dep_env"></a>dep_env | File: File with environment variables direct dependencies build scripts rely upon. | 1403| <a id="DepInfo-direct_crates"></a>direct_crates | depset[AliasableDepInfo] | 1404| <a id="DepInfo-link_search_path_files"></a>link_search_path_files | depset[File]: All transitive files containing search paths to pass to the linker | 1405| <a id="DepInfo-transitive_build_infos"></a>transitive_build_infos | depset[BuildInfo] | 1406| <a id="DepInfo-transitive_crate_outputs"></a>transitive_crate_outputs | depset[File]: All transitive crate outputs. | 1407| <a id="DepInfo-transitive_crates"></a>transitive_crates | depset[CrateInfo] | 1408| <a id="DepInfo-transitive_data"></a>transitive_data | depset[File]: Data of all transitive non-macro dependencies. | 1409| <a id="DepInfo-transitive_metadata_outputs"></a>transitive_metadata_outputs | depset[File]: All transitive metadata dependencies (.rmeta, for crates that provide them) and all transitive object dependencies (.rlib) for crates that don't provide metadata. | 1410| <a id="DepInfo-transitive_noncrates"></a>transitive_noncrates | depset[LinkerInput]: All transitive dependencies that aren't crates. | 1411| <a id="DepInfo-transitive_proc_macro_data"></a>transitive_proc_macro_data | depset[File]: Data of all transitive proc-macro dependencies, and non-macro dependencies of those macros. | 1412 1413 1414<a id="RustWasmBindgenInfo"></a> 1415 1416## RustWasmBindgenInfo 1417 1418<pre> 1419RustWasmBindgenInfo(<a href="#RustWasmBindgenInfo-js">js</a>, <a href="#RustWasmBindgenInfo-ts">ts</a>, <a href="#RustWasmBindgenInfo-wasm">wasm</a>) 1420</pre> 1421 1422Info about wasm-bindgen outputs. 1423 1424**FIELDS** 1425 1426 1427| Name | Description | 1428| :------------- | :------------- | 1429| <a id="RustWasmBindgenInfo-js"></a>js | Depset[File]: The Javascript files produced by `wasm-bindgen`. | 1430| <a id="RustWasmBindgenInfo-ts"></a>ts | Depset[File]: The Typescript files produced by `wasm-bindgen`. | 1431| <a id="RustWasmBindgenInfo-wasm"></a>wasm | File: The `.wasm` file generated by `wasm-bindgen`. | 1432 1433 1434<a id="StdLibInfo"></a> 1435 1436## StdLibInfo 1437 1438<pre> 1439StdLibInfo(<a href="#StdLibInfo-alloc_files">alloc_files</a>, <a href="#StdLibInfo-between_alloc_and_core_files">between_alloc_and_core_files</a>, <a href="#StdLibInfo-between_core_and_std_files">between_core_and_std_files</a>, <a href="#StdLibInfo-core_files">core_files</a>, 1440 <a href="#StdLibInfo-dot_a_files">dot_a_files</a>, <a href="#StdLibInfo-memchr_files">memchr_files</a>, <a href="#StdLibInfo-panic_files">panic_files</a>, <a href="#StdLibInfo-self_contained_files">self_contained_files</a>, <a href="#StdLibInfo-srcs">srcs</a>, <a href="#StdLibInfo-std_dylib">std_dylib</a>, <a href="#StdLibInfo-std_files">std_files</a>, 1441 <a href="#StdLibInfo-std_rlibs">std_rlibs</a>, <a href="#StdLibInfo-test_files">test_files</a>) 1442</pre> 1443 1444A collection of files either found within the `rust-stdlib` artifact or generated based on existing files. 1445 1446**FIELDS** 1447 1448 1449| Name | Description | 1450| :------------- | :------------- | 1451| <a id="StdLibInfo-alloc_files"></a>alloc_files | List[File]: `.a` files related to the `alloc` module. | 1452| <a id="StdLibInfo-between_alloc_and_core_files"></a>between_alloc_and_core_files | List[File]: `.a` files related to the `compiler_builtins` module. | 1453| <a id="StdLibInfo-between_core_and_std_files"></a>between_core_and_std_files | List[File]: `.a` files related to all modules except `adler`, `alloc`, `compiler_builtins`, `core`, and `std`. | 1454| <a id="StdLibInfo-core_files"></a>core_files | List[File]: `.a` files related to the `core` and `adler` modules | 1455| <a id="StdLibInfo-dot_a_files"></a>dot_a_files | Depset[File]: Generated `.a` files | 1456| <a id="StdLibInfo-memchr_files"></a>memchr_files | Depset[File]: `.a` files associated with the `memchr` module. | 1457| <a id="StdLibInfo-panic_files"></a>panic_files | Depset[File]: `.a` files associated with `panic_unwind` and `panic_abort`. | 1458| <a id="StdLibInfo-self_contained_files"></a>self_contained_files | List[File]: All `.o` files from the `self-contained` directory. | 1459| <a id="StdLibInfo-srcs"></a>srcs | List[Target]: All targets from the original `srcs` attribute. | 1460| <a id="StdLibInfo-std_dylib"></a>std_dylib | File: libstd.so file | 1461| <a id="StdLibInfo-std_files"></a>std_files | Depset[File]: `.a` files associated with the `std` module. | 1462| <a id="StdLibInfo-std_rlibs"></a>std_rlibs | List[File]: All `.rlib` files | 1463| <a id="StdLibInfo-test_files"></a>test_files | Depset[File]: `.a` files associated with the `test` module. | 1464 1465 1466<a id="cargo_build_script"></a> 1467 1468## cargo_build_script 1469 1470<pre> 1471cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-edition">edition</a>, <a href="#cargo_build_script-crate_name">crate_name</a>, <a href="#cargo_build_script-crate_root">crate_root</a>, <a href="#cargo_build_script-srcs">srcs</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>, 1472 <a href="#cargo_build_script-link_deps">link_deps</a>, <a href="#cargo_build_script-proc_macro_deps">proc_macro_deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-compile_data">compile_data</a>, <a href="#cargo_build_script-tools">tools</a>, <a href="#cargo_build_script-links">links</a>, 1473 <a href="#cargo_build_script-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_env_files">rustc_env_files</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</a>, 1474 <a href="#cargo_build_script-pkg_name">pkg_name</a>, <a href="#cargo_build_script-kwargs">kwargs</a>) 1475</pre> 1476 1477Compile and execute a rust build script to generate build attributes 1478 1479This rules take the same arguments as rust_binary. 1480 1481Example: 1482 1483Suppose you have a crate with a cargo build script `build.rs`: 1484 1485```output 1486[workspace]/ 1487 hello_lib/ 1488 BUILD 1489 build.rs 1490 src/ 1491 lib.rs 1492``` 1493 1494Then you want to use the build script in the following: 1495 1496`hello_lib/BUILD`: 1497```python 1498package(default_visibility = ["//visibility:public"]) 1499 1500load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") 1501load("@rules_rust//cargo:defs.bzl", "cargo_build_script") 1502 1503# This will run the build script from the root of the workspace, and 1504# collect the outputs. 1505cargo_build_script( 1506 name = "build_script", 1507 srcs = ["build.rs"], 1508 # Optional environment variables passed during build.rs compilation 1509 rustc_env = { 1510 "CARGO_PKG_VERSION": "0.1.2", 1511 }, 1512 # Optional environment variables passed during build.rs execution. 1513 # Note that as the build script's working directory is not execroot, 1514 # execpath/location will return an absolute path, instead of a relative 1515 # one. 1516 build_script_env = { 1517 "SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)" 1518 }, 1519 # Optional data/tool dependencies 1520 data = ["@tool//:binary"], 1521) 1522 1523rust_library( 1524 name = "hello_lib", 1525 srcs = [ 1526 "src/lib.rs", 1527 ], 1528 deps = [":build_script"], 1529) 1530``` 1531 1532The `hello_lib` target will be build with the flags and the environment variables declared by the build script in addition to the file generated by it. 1533 1534 1535**PARAMETERS** 1536 1537 1538| Name | Description | Default Value | 1539| :------------- | :------------- | :------------- | 1540| <a id="cargo_build_script-name"></a>name | The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of `_bs`. Otherwise, you can set the package name via `pkg_name`. | none | 1541| <a id="cargo_build_script-edition"></a>edition | The rust edition to use for the internal binary crate. | `None` | 1542| <a id="cargo_build_script-crate_name"></a>crate_name | Crate name to use for build script. | `None` | 1543| <a id="cargo_build_script-crate_root"></a>crate_root | The file that will be passed to rustc to be used for building this crate. | `None` | 1544| <a id="cargo_build_script-srcs"></a>srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made. | `[]` | 1545| <a id="cargo_build_script-crate_features"></a>crate_features | A list of features to enable for the build script. | `[]` | 1546| <a id="cargo_build_script-version"></a>version | The semantic version (semver) of the crate. | `None` | 1547| <a id="cargo_build_script-deps"></a>deps | The build-dependencies of the crate. | `[]` | 1548| <a id="cargo_build_script-link_deps"></a>link_deps | The subset of the (normal) dependencies of the crate that have the links attribute and therefore provide environment variables to this build script. | `[]` | 1549| <a id="cargo_build_script-proc_macro_deps"></a>proc_macro_deps | List of rust_proc_macro targets used to build the script. | `[]` | 1550| <a id="cargo_build_script-build_script_env"></a>build_script_env | Environment variables for build scripts. | `{}` | 1551| <a id="cargo_build_script-data"></a>data | Files needed by the build script. | `[]` | 1552| <a id="cargo_build_script-compile_data"></a>compile_data | Files needed for the compilation of the build script. | `[]` | 1553| <a id="cargo_build_script-tools"></a>tools | Tools (executables) needed by the build script. | `[]` | 1554| <a id="cargo_build_script-links"></a>links | Name of the native library this crate links against. | `None` | 1555| <a id="cargo_build_script-rundir"></a>rundir | A directory to `cd` to before the cargo_build_script is run. This should be a path relative to the exec root.<br><br>The default behaviour (and the behaviour if rundir is set to the empty string) is to change to the relative path corresponding to the cargo manifest directory, which replicates the normal behaviour of cargo so it is easy to write compatible build scripts.<br><br>If set to `.`, the cargo build script will run in the exec root. | `None` | 1556| <a id="cargo_build_script-rustc_env"></a>rustc_env | Environment variables to set in rustc when compiling the build script. | `{}` | 1557| <a id="cargo_build_script-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc when building the build script. | `[]` | 1558| <a id="cargo_build_script-rustc_flags"></a>rustc_flags | List of compiler flags passed to `rustc`. | `[]` | 1559| <a id="cargo_build_script-visibility"></a>visibility | Visibility to apply to the generated build script output. | `None` | 1560| <a id="cargo_build_script-tags"></a>tags | (list of str, optional): Tags to apply to the generated build script output. | `None` | 1561| <a id="cargo_build_script-aliases"></a>aliases | Remap crates to a new name or moniker for linkage to this target. These are other `rust_library` targets and will be presented as the new name given. | `None` | 1562| <a id="cargo_build_script-pkg_name"></a>pkg_name | Override the package name used for the build script. This is useful if the build target name gets too long otherwise. | `None` | 1563| <a id="cargo_build_script-kwargs"></a>kwargs | Forwards to the underlying `rust_binary` rule. An exception is the `compatible_with` attribute, which shouldn't be forwarded to the `rust_binary`, as the `rust_binary` is only built and used in `exec` mode. We propagate the `compatible_with` attribute to the `_build_scirpt_run` target. | none | 1564 1565 1566<a id="cargo_env"></a> 1567 1568## cargo_env 1569 1570<pre> 1571cargo_env(<a href="#cargo_env-env">env</a>) 1572</pre> 1573 1574A helper for generating platform specific environment variables 1575 1576```python 1577load("@rules_rust//rust:defs.bzl", "rust_common") 1578load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository", "cargo_env") 1579 1580cargo_bootstrap_repository( 1581 name = "bootstrapped_bin", 1582 cargo_lockfile = "//:Cargo.lock", 1583 cargo_toml = "//:Cargo.toml", 1584 srcs = ["//:resolver_srcs"], 1585 version = rust_common.default_version, 1586 binary = "my-crate-binary", 1587 env = { 1588 "x86_64-unknown-linux-gnu": cargo_env({ 1589 "FOO": "BAR", 1590 }), 1591 }, 1592 env_label = { 1593 "aarch64-unknown-linux-musl": cargo_env({ 1594 "DOC": "//:README.md", 1595 }), 1596 } 1597) 1598``` 1599 1600 1601**PARAMETERS** 1602 1603 1604| Name | Description | Default Value | 1605| :------------- | :------------- | :------------- | 1606| <a id="cargo_env-env"></a>env | A map of environment variables | none | 1607 1608**RETURNS** 1609 1610str: A json encoded string of the environment variables 1611 1612 1613<a id="rules_rust_dependencies"></a> 1614 1615## rules_rust_dependencies 1616 1617<pre> 1618rules_rust_dependencies() 1619</pre> 1620 1621Dependencies used in the implementation of `rules_rust`. 1622 1623 1624 1625<a id="rust_analyzer_toolchain_repository"></a> 1626 1627## rust_analyzer_toolchain_repository 1628 1629<pre> 1630rust_analyzer_toolchain_repository(<a href="#rust_analyzer_toolchain_repository-name">name</a>, <a href="#rust_analyzer_toolchain_repository-version">version</a>, <a href="#rust_analyzer_toolchain_repository-exec_compatible_with">exec_compatible_with</a>, <a href="#rust_analyzer_toolchain_repository-target_compatible_with">target_compatible_with</a>, 1631 <a href="#rust_analyzer_toolchain_repository-iso_date">iso_date</a>, <a href="#rust_analyzer_toolchain_repository-sha256s">sha256s</a>, <a href="#rust_analyzer_toolchain_repository-urls">urls</a>, <a href="#rust_analyzer_toolchain_repository-auth">auth</a>, <a href="#rust_analyzer_toolchain_repository-netrc">netrc</a>, <a href="#rust_analyzer_toolchain_repository-auth_patterns">auth_patterns</a>) 1632</pre> 1633 1634Assemble a remote rust_analyzer_toolchain target based on the given params. 1635 1636**PARAMETERS** 1637 1638 1639| Name | Description | Default Value | 1640| :------------- | :------------- | :------------- | 1641| <a id="rust_analyzer_toolchain_repository-name"></a>name | The name of the toolchain proxy repository contianing the registerable toolchain. | none | 1642| <a id="rust_analyzer_toolchain_repository-version"></a>version | The version of the tool among "nightly", "beta', or an exact version. | none | 1643| <a id="rust_analyzer_toolchain_repository-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `[]` | 1644| <a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | `[]` | 1645| <a id="rust_analyzer_toolchain_repository-iso_date"></a>iso_date | The date of the tool. | `None` | 1646| <a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` | 1647| <a id="rust_analyzer_toolchain_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz'] | `None` | 1648| <a id="rust_analyzer_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` | 1649| <a id="rust_analyzer_toolchain_repository-netrc"></a>netrc | .netrc file to use for authentication; mirrors the eponymous attribute from http_archive | `None` | 1650| <a id="rust_analyzer_toolchain_repository-auth_patterns"></a>auth_patterns | Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive | `None` | 1651 1652**RETURNS** 1653 1654str: The name of a registerable rust_analyzer_toolchain. 1655 1656 1657<a id="rust_bindgen_dependencies"></a> 1658 1659## rust_bindgen_dependencies 1660 1661<pre> 1662rust_bindgen_dependencies() 1663</pre> 1664 1665Declare dependencies needed for bindgen. 1666 1667 1668**RETURNS** 1669 1670list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 1671 defined by this macro. 1672 1673 1674<a id="rust_bindgen_library"></a> 1675 1676## rust_bindgen_library 1677 1678<pre> 1679rust_bindgen_library(<a href="#rust_bindgen_library-name">name</a>, <a href="#rust_bindgen_library-header">header</a>, <a href="#rust_bindgen_library-cc_lib">cc_lib</a>, <a href="#rust_bindgen_library-bindgen_flags">bindgen_flags</a>, <a href="#rust_bindgen_library-bindgen_features">bindgen_features</a>, <a href="#rust_bindgen_library-clang_flags">clang_flags</a>, 1680 <a href="#rust_bindgen_library-wrap_static_fns">wrap_static_fns</a>, <a href="#rust_bindgen_library-kwargs">kwargs</a>) 1681</pre> 1682 1683Generates a rust source file for `header`, and builds a rust_library. 1684 1685Arguments are the same as `rust_bindgen`, and `kwargs` are passed directly to rust_library. 1686 1687 1688**PARAMETERS** 1689 1690 1691| Name | Description | Default Value | 1692| :------------- | :------------- | :------------- | 1693| <a id="rust_bindgen_library-name"></a>name | A unique name for this target. | none | 1694| <a id="rust_bindgen_library-header"></a>header | The label of the .h file to generate bindings for. | none | 1695| <a id="rust_bindgen_library-cc_lib"></a>cc_lib | The label of the cc_library that contains the .h file. This is used to find the transitive includes. | none | 1696| <a id="rust_bindgen_library-bindgen_flags"></a>bindgen_flags | Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details. | `None` | 1697| <a id="rust_bindgen_library-bindgen_features"></a>bindgen_features | The `features` attribute for the `rust_bindgen` target. | `None` | 1698| <a id="rust_bindgen_library-clang_flags"></a>clang_flags | Flags to pass directly to the clang executable. | `None` | 1699| <a id="rust_bindgen_library-wrap_static_fns"></a>wrap_static_fns | Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains", | `False` | 1700| <a id="rust_bindgen_library-kwargs"></a>kwargs | Arguments to forward to the underlying `rust_library` rule. | none | 1701 1702 1703<a id="rust_bindgen_register_toolchains"></a> 1704 1705## rust_bindgen_register_toolchains 1706 1707<pre> 1708rust_bindgen_register_toolchains(<a href="#rust_bindgen_register_toolchains-register_toolchains">register_toolchains</a>) 1709</pre> 1710 1711Registers the default toolchains for the `rules_rust` [bindgen][bg] rules. 1712 1713[bg]: https://rust-lang.github.io/rust-bindgen/ 1714 1715 1716**PARAMETERS** 1717 1718 1719| Name | Description | Default Value | 1720| :------------- | :------------- | :------------- | 1721| <a id="rust_bindgen_register_toolchains-register_toolchains"></a>register_toolchains | Whether or not to register toolchains. | `True` | 1722 1723 1724<a id="rust_prost_dependencies"></a> 1725 1726## rust_prost_dependencies 1727 1728<pre> 1729rust_prost_dependencies(<a href="#rust_prost_dependencies-bzlmod">bzlmod</a>) 1730</pre> 1731 1732Declares repositories needed for prost. 1733 1734**PARAMETERS** 1735 1736 1737| Name | Description | Default Value | 1738| :------------- | :------------- | :------------- | 1739| <a id="rust_prost_dependencies-bzlmod"></a>bzlmod | Whether bzlmod is enabled. | `False` | 1740 1741**RETURNS** 1742 1743list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 1744 defined by this macro. 1745 1746 1747<a id="rust_prost_library"></a> 1748 1749## rust_prost_library 1750 1751<pre> 1752rust_prost_library(<a href="#rust_prost_library-name">name</a>, <a href="#rust_prost_library-kwargs">kwargs</a>) 1753</pre> 1754 1755A rule for generating a Rust library using Prost. 1756 1757**PARAMETERS** 1758 1759 1760| Name | Description | Default Value | 1761| :------------- | :------------- | :------------- | 1762| <a id="rust_prost_library-name"></a>name | The name of the target. | none | 1763| <a id="rust_prost_library-kwargs"></a>kwargs | Additional keyword arguments for the underlying `rust_prost_library` rule. | none | 1764 1765 1766<a id="rust_prost_transitive_repositories"></a> 1767 1768## rust_prost_transitive_repositories 1769 1770<pre> 1771rust_prost_transitive_repositories() 1772</pre> 1773 1774Load transitive dependencies of the `@rules_rust//proto/protobuf` rules. 1775 1776This macro should be called immediately after the `rust_protobuf_dependencies` macro. 1777 1778 1779 1780<a id="rust_proto_protobuf_dependencies"></a> 1781 1782## rust_proto_protobuf_dependencies 1783 1784<pre> 1785rust_proto_protobuf_dependencies(<a href="#rust_proto_protobuf_dependencies-bzlmod">bzlmod</a>) 1786</pre> 1787 1788Sets up dependencies for rules_rust's proto support. 1789 1790**PARAMETERS** 1791 1792 1793| Name | Description | Default Value | 1794| :------------- | :------------- | :------------- | 1795| <a id="rust_proto_protobuf_dependencies-bzlmod"></a>bzlmod | Whether this function is being called from a bzlmod context rather than a workspace context. | `False` | 1796 1797**RETURNS** 1798 1799A list of structs containing information about root module deps to report to bzlmod's extension_metadata. 1800 1801 1802<a id="rust_proto_protobuf_register_toolchains"></a> 1803 1804## rust_proto_protobuf_register_toolchains 1805 1806<pre> 1807rust_proto_protobuf_register_toolchains(<a href="#rust_proto_protobuf_register_toolchains-register_toolchains">register_toolchains</a>) 1808</pre> 1809 1810Register toolchains for proto compilation. 1811 1812**PARAMETERS** 1813 1814 1815| Name | Description | Default Value | 1816| :------------- | :------------- | :------------- | 1817| <a id="rust_proto_protobuf_register_toolchains-register_toolchains"></a>register_toolchains | <p align="center"> - </p> | `True` | 1818 1819 1820<a id="rust_proto_protobuf_transitive_repositories"></a> 1821 1822## rust_proto_protobuf_transitive_repositories 1823 1824<pre> 1825rust_proto_protobuf_transitive_repositories() 1826</pre> 1827 1828Load transitive dependencies of the `@rules_rust//proto/protobuf` rules. 1829 1830This macro should be called immediately after the `rust_protobuf_dependencies` macro. 1831 1832 1833 1834<a id="rust_register_toolchains"></a> 1835 1836## rust_register_toolchains 1837 1838<pre> 1839rust_register_toolchains(<a href="#rust_register_toolchains-dev_components">dev_components</a>, <a href="#rust_register_toolchains-edition">edition</a>, <a href="#rust_register_toolchains-allocator_library">allocator_library</a>, <a href="#rust_register_toolchains-global_allocator_library">global_allocator_library</a>, 1840 <a href="#rust_register_toolchains-iso_date">iso_date</a>, <a href="#rust_register_toolchains-register_toolchains">register_toolchains</a>, <a href="#rust_register_toolchains-rustfmt_version">rustfmt_version</a>, <a href="#rust_register_toolchains-rust_analyzer_version">rust_analyzer_version</a>, 1841 <a href="#rust_register_toolchains-sha256s">sha256s</a>, <a href="#rust_register_toolchains-extra_target_triples">extra_target_triples</a>, <a href="#rust_register_toolchains-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_register_toolchains-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, 1842 <a href="#rust_register_toolchains-urls">urls</a>, <a href="#rust_register_toolchains-version">version</a>, <a href="#rust_register_toolchains-versions">versions</a>) 1843</pre> 1844 1845Emits a default set of toolchains for Linux, MacOS, and Freebsd 1846 1847Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for other hosts or for additional target triples. 1848 1849The `sha256s` attribute represents a dict associating tool subdirectories to sha256 hashes. As an example: 1850```python 1851{ 1852 "rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5", 1853 "rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0", 1854 "rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc", 1855} 1856``` 1857This would match for `exec_triple = "x86_64-unknown-linux-gnu"`. If not specified, rules_rust pulls from a non-exhaustive list of known checksums.. 1858 1859See `load_arbitrary_tool` in `@rules_rust//rust:repositories.bzl` for more details. 1860 1861 1862**PARAMETERS** 1863 1864 1865| Name | Description | Default Value | 1866| :------------- | :------------- | :------------- | 1867| <a id="rust_register_toolchains-dev_components"></a>dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | `False` | 1868| <a id="rust_register_toolchains-edition"></a>edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every target is required to specify its `edition` attribute. | `None` | 1869| <a id="rust_register_toolchains-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | `None` | 1870| <a id="rust_register_toolchains-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when global allocator is used with cc_common.link. | `None` | 1871| <a id="rust_register_toolchains-iso_date"></a>iso_date | **Deprecated**: Use `versions` instead. | `None` | 1872| <a id="rust_register_toolchains-register_toolchains"></a>register_toolchains | If true, repositories will be generated to produce and register `rust_toolchain` targets. | `True` | 1873| <a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version | The version of rustfmt. If none is supplied and only a single version in `versions` is given, then this defaults to that version, otherwise will default to the default nightly version. | `None` | 1874| <a id="rust_register_toolchains-rust_analyzer_version"></a>rust_analyzer_version | The version of Rustc to pair with rust-analyzer. | `None` | 1875| <a id="rust_register_toolchains-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. | `None` | 1876| <a id="rust_register_toolchains-extra_target_triples"></a>extra_target_triples | Additional rust-style targets that rust toolchains should support. | `["wasm32-unknown-unknown", "wasm32-wasi"]` | 1877| <a id="rust_register_toolchains-extra_rustc_flags"></a>extra_rustc_flags | Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration. | `None` | 1878| <a id="rust_register_toolchains-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` | 1879| <a id="rust_register_toolchains-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | `["https://static.rust-lang.org/dist/{}.tar.xz"]` | 1880| <a id="rust_register_toolchains-version"></a>version | **Deprecated**: Use `versions` instead. | `None` | 1881| <a id="rust_register_toolchains-versions"></a>versions | A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`. | `[]` | 1882 1883 1884<a id="rust_repositories"></a> 1885 1886## rust_repositories 1887 1888<pre> 1889rust_repositories(<a href="#rust_repositories-kwargs">kwargs</a>) 1890</pre> 1891 1892**Deprecated**: Use [rules_rust_dependencies](#rules_rust_dependencies) and [rust_register_toolchains](#rust_register_toolchains) directly. 1893 1894**PARAMETERS** 1895 1896 1897| Name | Description | Default Value | 1898| :------------- | :------------- | :------------- | 1899| <a id="rust_repositories-kwargs"></a>kwargs | Keyword arguments for the `rust_register_toolchains` macro. | none | 1900 1901 1902<a id="rust_repository_set"></a> 1903 1904## rust_repository_set 1905 1906<pre> 1907rust_repository_set(<a href="#rust_repository_set-name">name</a>, <a href="#rust_repository_set-exec_triple">exec_triple</a>, <a href="#rust_repository_set-target_settings">target_settings</a>, <a href="#rust_repository_set-version">version</a>, <a href="#rust_repository_set-versions">versions</a>, <a href="#rust_repository_set-allocator_library">allocator_library</a>, 1908 <a href="#rust_repository_set-global_allocator_library">global_allocator_library</a>, <a href="#rust_repository_set-extra_target_triples">extra_target_triples</a>, <a href="#rust_repository_set-iso_date">iso_date</a>, <a href="#rust_repository_set-rustfmt_version">rustfmt_version</a>, 1909 <a href="#rust_repository_set-edition">edition</a>, <a href="#rust_repository_set-dev_components">dev_components</a>, <a href="#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_repository_set-opt_level">opt_level</a>, 1910 <a href="#rust_repository_set-sha256s">sha256s</a>, <a href="#rust_repository_set-urls">urls</a>, <a href="#rust_repository_set-auth">auth</a>, <a href="#rust_repository_set-netrc">netrc</a>, <a href="#rust_repository_set-auth_patterns">auth_patterns</a>, <a href="#rust_repository_set-register_toolchain">register_toolchain</a>, 1911 <a href="#rust_repository_set-exec_compatible_with">exec_compatible_with</a>, <a href="#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>) 1912</pre> 1913 1914Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. 1915 1916**PARAMETERS** 1917 1918 1919| Name | Description | Default Value | 1920| :------------- | :------------- | :------------- | 1921| <a id="rust_repository_set-name"></a>name | The name of the generated repository | none | 1922| <a id="rust_repository_set-exec_triple"></a>exec_triple | The Rust-style target that this compiler runs on | none | 1923| <a id="rust_repository_set-target_settings"></a>target_settings | A list of config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution. | `[]` | 1924| <a id="rust_repository_set-version"></a>version | The version of the tool among "nightly", "beta', or an exact version. | `None` | 1925| <a id="rust_repository_set-versions"></a>versions | A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`. | `[]` | 1926| <a id="rust_repository_set-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | `None` | 1927| <a id="rust_repository_set-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions a global allocator is used with cc_common.link. | `None` | 1928| <a id="rust_repository_set-extra_target_triples"></a>extra_target_triples | Additional rust-style targets that this set of toolchains should support. If a map, values should be (optional) target_compatible_with lists for that particular target triple. | `{}` | 1929| <a id="rust_repository_set-iso_date"></a>iso_date | The date of the tool. | `None` | 1930| <a id="rust_repository_set-rustfmt_version"></a>rustfmt_version | The version of rustfmt to be associated with the toolchain. | `None` | 1931| <a id="rust_repository_set-edition"></a>edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its `edition` attribute. | `None` | 1932| <a id="rust_repository_set-dev_components"></a>dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". | `False` | 1933| <a id="rust_repository_set-extra_rustc_flags"></a>extra_rustc_flags | Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration. | `None` | 1934| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` | 1935| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` | 1936| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` | 1937| <a id="rust_repository_set-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | `["https://static.rust-lang.org/dist/{}.tar.xz"]` | 1938| <a id="rust_repository_set-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` | 1939| <a id="rust_repository_set-netrc"></a>netrc | .netrc file to use for authentication; mirrors the eponymous attribute from http_archive | `None` | 1940| <a id="rust_repository_set-auth_patterns"></a>auth_patterns | Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive | `None` | 1941| <a id="rust_repository_set-register_toolchain"></a>register_toolchain | If True, the generated `rust_toolchain` target will become a registered toolchain. | `True` | 1942| <a id="rust_repository_set-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` | 1943| <a id="rust_repository_set-default_target_compatible_with"></a>default_target_compatible_with | A list of constraints for the target platform for this toolchain when the exec platform is the same as the target platform. | `None` | 1944 1945 1946<a id="rust_test_suite"></a> 1947 1948## rust_test_suite 1949 1950<pre> 1951rust_test_suite(<a href="#rust_test_suite-name">name</a>, <a href="#rust_test_suite-srcs">srcs</a>, <a href="#rust_test_suite-shared_srcs">shared_srcs</a>, <a href="#rust_test_suite-kwargs">kwargs</a>) 1952</pre> 1953 1954A rule for creating a test suite for a set of `rust_test` targets. 1955 1956This rule can be used for setting up typical rust [integration tests][it]. Given the following 1957directory structure: 1958 1959```text 1960[crate]/ 1961 BUILD.bazel 1962 src/ 1963 lib.rs 1964 main.rs 1965 tests/ 1966 integrated_test_a.rs 1967 integrated_test_b.rs 1968 integrated_test_c.rs 1969 patterns/ 1970 fibonacci_test.rs 1971 helpers/ 1972 mod.rs 1973``` 1974 1975The rule can be used to generate [rust_test](#rust_test) targets for each source file under `tests` 1976and a [test_suite][ts] which encapsulates all tests. 1977 1978```python 1979load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test_suite") 1980 1981rust_library( 1982 name = "math_lib", 1983 srcs = ["src/lib.rs"], 1984) 1985 1986rust_binary( 1987 name = "math_bin", 1988 srcs = ["src/main.rs"], 1989) 1990 1991rust_test_suite( 1992 name = "integrated_tests_suite", 1993 srcs = glob(["tests/**"]), 1994 shared_srcs=glob(["tests/helpers/**"]), 1995 deps = [":math_lib"], 1996) 1997``` 1998 1999[it]: https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html 2000[ts]: https://docs.bazel.build/versions/master/be/general.html#test_suite 2001 2002 2003**PARAMETERS** 2004 2005 2006| Name | Description | Default Value | 2007| :------------- | :------------- | :------------- | 2008| <a id="rust_test_suite-name"></a>name | The name of the `test_suite`. | none | 2009| <a id="rust_test_suite-srcs"></a>srcs | All test sources, typically `glob(["tests/**/*.rs"])`. | none | 2010| <a id="rust_test_suite-shared_srcs"></a>shared_srcs | Optional argument for sources shared among tests, typically helper functions. | `[]` | 2011| <a id="rust_test_suite-kwargs"></a>kwargs | Additional keyword arguments for the underyling [rust_test](#rust_test) targets. The `tags` argument is also passed to the generated `test_suite` target. | none | 2012 2013 2014<a id="rust_toolchain_repository"></a> 2015 2016## rust_toolchain_repository 2017 2018<pre> 2019rust_toolchain_repository(<a href="#rust_toolchain_repository-name">name</a>, <a href="#rust_toolchain_repository-version">version</a>, <a href="#rust_toolchain_repository-exec_triple">exec_triple</a>, <a href="#rust_toolchain_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_repository-exec_compatible_with">exec_compatible_with</a>, 2020 <a href="#rust_toolchain_repository-target_compatible_with">target_compatible_with</a>, <a href="#rust_toolchain_repository-target_settings">target_settings</a>, <a href="#rust_toolchain_repository-channel">channel</a>, <a href="#rust_toolchain_repository-allocator_library">allocator_library</a>, 2021 <a href="#rust_toolchain_repository-global_allocator_library">global_allocator_library</a>, <a href="#rust_toolchain_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_repository-edition">edition</a>, 2022 <a href="#rust_toolchain_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_repository-opt_level">opt_level</a>, 2023 <a href="#rust_toolchain_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_repository-urls">urls</a>, <a href="#rust_toolchain_repository-auth">auth</a>, <a href="#rust_toolchain_repository-netrc">netrc</a>, <a href="#rust_toolchain_repository-auth_patterns">auth_patterns</a>) 2024</pre> 2025 2026Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains. 2027 2028**PARAMETERS** 2029 2030 2031| Name | Description | Default Value | 2032| :------------- | :------------- | :------------- | 2033| <a id="rust_toolchain_repository-name"></a>name | The name of the generated repository | none | 2034| <a id="rust_toolchain_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | none | 2035| <a id="rust_toolchain_repository-exec_triple"></a>exec_triple | The Rust-style target that this compiler runs on. | none | 2036| <a id="rust_toolchain_repository-target_triple"></a>target_triple | The Rust-style target to build for. | none | 2037| <a id="rust_toolchain_repository-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | `None` | 2038| <a id="rust_toolchain_repository-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | `None` | 2039| <a id="rust_toolchain_repository-target_settings"></a>target_settings | A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution. | `[]` | 2040| <a id="rust_toolchain_repository-channel"></a>channel | The channel of the Rust toolchain. | `None` | 2041| <a id="rust_toolchain_repository-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | `None` | 2042| <a id="rust_toolchain_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | `None` | 2043| <a id="rust_toolchain_repository-iso_date"></a>iso_date | The date of the tool. | `None` | 2044| <a id="rust_toolchain_repository-rustfmt_version"></a>rustfmt_version | The version of rustfmt to be associated with the toolchain. | `None` | 2045| <a id="rust_toolchain_repository-edition"></a>edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its `edition` attribute. | `None` | 2046| <a id="rust_toolchain_repository-dev_components"></a>dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False. | `False` | 2047| <a id="rust_toolchain_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration. | `None` | 2048| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` | 2049| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` | 2050| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | `None` | 2051| <a id="rust_toolchain_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz'] | `["https://static.rust-lang.org/dist/{}.tar.xz"]` | 2052| <a id="rust_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` | 2053| <a id="rust_toolchain_repository-netrc"></a>netrc | .netrc file to use for authentication; mirrors the eponymous attribute from http_archive | `None` | 2054| <a id="rust_toolchain_repository-auth_patterns"></a>auth_patterns | A list of patterns to match against urls for which the auth object should be used. | `None` | 2055 2056**RETURNS** 2057 2058str: The name of the registerable toolchain created by this rule. 2059 2060 2061<a id="rust_wasm_bindgen_dependencies"></a> 2062 2063## rust_wasm_bindgen_dependencies 2064 2065<pre> 2066rust_wasm_bindgen_dependencies() 2067</pre> 2068 2069Declare dependencies needed for the `rules_rust` [wasm-bindgen][wb] rules. 2070 2071[wb]: https://github.com/rustwasm/wasm-bindgen 2072 2073 2074 2075**RETURNS** 2076 2077list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 2078 defined by this macro. 2079 2080 2081<a id="rust_wasm_bindgen_register_toolchains"></a> 2082 2083## rust_wasm_bindgen_register_toolchains 2084 2085<pre> 2086rust_wasm_bindgen_register_toolchains(<a href="#rust_wasm_bindgen_register_toolchains-register_toolchains">register_toolchains</a>) 2087</pre> 2088 2089Registers the default toolchains for the `rules_rust` [wasm-bindgen][wb] rules. 2090 2091[wb]: https://github.com/rustwasm/wasm-bindgen 2092 2093 2094**PARAMETERS** 2095 2096 2097| Name | Description | Default Value | 2098| :------------- | :------------- | :------------- | 2099| <a id="rust_wasm_bindgen_register_toolchains-register_toolchains"></a>register_toolchains | Whether or not to register toolchains. | `True` | 2100 2101 2102<a id="rust_analyzer_aspect"></a> 2103 2104## rust_analyzer_aspect 2105 2106<pre> 2107rust_analyzer_aspect(<a href="#rust_analyzer_aspect-name">name</a>) 2108</pre> 2109 2110Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json 2111 2112**ASPECT ATTRIBUTES** 2113 2114 2115| Name | Type | 2116| :------------- | :------------- | 2117| deps| String | 2118| proc_macro_deps| String | 2119| crate| String | 2120| actual| String | 2121| proto| String | 2122 2123 2124**ATTRIBUTES** 2125 2126 2127| Name | Description | Type | Mandatory | Default | 2128| :------------- | :------------- | :------------- | :------------- | :------------- | 2129| <a id="rust_analyzer_aspect-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 2130 2131 2132<a id="rust_clippy_aspect"></a> 2133 2134## rust_clippy_aspect 2135 2136<pre> 2137rust_clippy_aspect(<a href="#rust_clippy_aspect-name">name</a>) 2138</pre> 2139 2140Executes the clippy checker on specified targets. 2141 2142This aspect applies to existing rust_library, rust_test, and rust_binary rules. 2143 2144As an example, if the following is defined in `examples/hello_lib/BUILD.bazel`: 2145 2146```python 2147load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 2148 2149rust_library( 2150 name = "hello_lib", 2151 srcs = ["src/lib.rs"], 2152) 2153 2154rust_test( 2155 name = "greeting_test", 2156 srcs = ["tests/greeting.rs"], 2157 deps = [":hello_lib"], 2158) 2159``` 2160 2161Then the targets can be analyzed with clippy using the following command: 2162 2163```output 2164$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all 2165``` 2166 2167**ASPECT ATTRIBUTES** 2168 2169 2170 2171**ATTRIBUTES** 2172 2173 2174| Name | Description | Type | Mandatory | Default | 2175| :------------- | :------------- | :------------- | :------------- | :------------- | 2176| <a id="rust_clippy_aspect-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 2177 2178 2179<a id="rustfmt_aspect"></a> 2180 2181## rustfmt_aspect 2182 2183<pre> 2184rustfmt_aspect(<a href="#rustfmt_aspect-name">name</a>) 2185</pre> 2186 2187This aspect is used to gather information about a crate for use in rustfmt and perform rustfmt checks 2188 2189Output Groups: 2190 2191- `rustfmt_checks`: Executes `rustfmt --check` on the specified target. 2192 2193The build setting `@rules_rust//:rustfmt.toml` is used to control the Rustfmt [configuration settings][cs] 2194used at runtime. 2195 2196[cs]: https://rust-lang.github.io/rustfmt/ 2197 2198This aspect is executed on any target which provides the `CrateInfo` provider. However 2199users may tag a target with `no-rustfmt` or `no-format` to have it skipped. Additionally, 2200generated source files are also ignored by this aspect. 2201 2202**ASPECT ATTRIBUTES** 2203 2204 2205 2206**ATTRIBUTES** 2207 2208 2209| Name | Description | Type | Mandatory | Default | 2210| :------------- | :------------- | :------------- | :------------- | :------------- | 2211| <a id="rustfmt_aspect-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 2212 2213 2214<a id="cargo_bootstrap_repository"></a> 2215 2216## cargo_bootstrap_repository 2217 2218<pre> 2219cargo_bootstrap_repository(<a href="#cargo_bootstrap_repository-name">name</a>, <a href="#cargo_bootstrap_repository-srcs">srcs</a>, <a href="#cargo_bootstrap_repository-binary">binary</a>, <a href="#cargo_bootstrap_repository-build_mode">build_mode</a>, <a href="#cargo_bootstrap_repository-cargo_lockfile">cargo_lockfile</a>, <a href="#cargo_bootstrap_repository-cargo_toml">cargo_toml</a>, <a href="#cargo_bootstrap_repository-env">env</a>, 2220 <a href="#cargo_bootstrap_repository-env_label">env_label</a>, <a href="#cargo_bootstrap_repository-repo_mapping">repo_mapping</a>, <a href="#cargo_bootstrap_repository-rust_toolchain_cargo_template">rust_toolchain_cargo_template</a>, 2221 <a href="#cargo_bootstrap_repository-rust_toolchain_rustc_template">rust_toolchain_rustc_template</a>, <a href="#cargo_bootstrap_repository-timeout">timeout</a>, <a href="#cargo_bootstrap_repository-version">version</a>) 2222</pre> 2223 2224A rule for bootstrapping a Rust binary using [Cargo](https://doc.rust-lang.org/cargo/) 2225 2226**ATTRIBUTES** 2227 2228 2229| Name | Description | Type | Mandatory | Default | 2230| :------------- | :------------- | :------------- | :------------- | :------------- | 2231| <a id="cargo_bootstrap_repository-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 2232| <a id="cargo_bootstrap_repository-srcs"></a>srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` | 2233| <a id="cargo_bootstrap_repository-binary"></a>binary | The binary to build (the `--bin` parameter for Cargo). If left empty, the repository name will be used. | String | optional | `""` | 2234| <a id="cargo_bootstrap_repository-build_mode"></a>build_mode | The build mode the binary should be built with | String | optional | `"release"` | 2235| <a id="cargo_bootstrap_repository-cargo_lockfile"></a>cargo_lockfile | The lockfile of the crate_universe resolver | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 2236| <a id="cargo_bootstrap_repository-cargo_toml"></a>cargo_toml | The path of the crate_universe resolver manifest (`Cargo.toml` file) | <a href="https://bazel.build/concepts/labels">Label</a> | required | | 2237| <a id="cargo_bootstrap_repository-env"></a>env | A mapping of platform triple to a set of environment variables. See [cargo_env](#cargo_env) for usage details. Additionally, the platform triple `*` applies to all platforms. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 2238| <a id="cargo_bootstrap_repository-env_label"></a>env_label | A mapping of platform triple to a set of environment variables. This attribute differs from `env` in that all variables passed here must be fully qualified labels of files. See [cargo_env](#cargo_env) for usage details. Additionally, the platform triple `*` applies to all platforms. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 2239| <a id="cargo_bootstrap_repository-repo_mapping"></a>repo_mapping | In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).<br><br>This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | | 2240| <a id="cargo_bootstrap_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template | The template to use for finding the host `cargo` binary. `{version}` (eg. '1.53.0'), `{triple}` (eg. 'x86_64-unknown-linux-gnu'), `{arch}` (eg. 'aarch64'), `{vendor}` (eg. 'unknown'), `{system}` (eg. 'darwin'), `{channel}` (eg. 'stable'), and `{tool}` (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | `"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"` | 2241| <a id="cargo_bootstrap_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template | The template to use for finding the host `rustc` binary. `{version}` (eg. '1.53.0'), `{triple}` (eg. 'x86_64-unknown-linux-gnu'), `{arch}` (eg. 'aarch64'), `{vendor}` (eg. 'unknown'), `{system}` (eg. 'darwin'), `{channel}` (eg. 'stable'), and `{tool}` (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | `"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"` | 2242| <a id="cargo_bootstrap_repository-timeout"></a>timeout | Maximum duration of the Cargo build command in seconds | Integer | optional | `600` | 2243| <a id="cargo_bootstrap_repository-version"></a>version | The version of Rust the currently registered toolchain is using. Eg. `1.56.0`, or `nightly/2021-09-08` | String | optional | `"1.80.0"` | 2244 2245 2246<a id="rust_toolchain_repository_proxy"></a> 2247 2248## rust_toolchain_repository_proxy 2249 2250<pre> 2251rust_toolchain_repository_proxy(<a href="#rust_toolchain_repository_proxy-name">name</a>, <a href="#rust_toolchain_repository_proxy-exec_compatible_with">exec_compatible_with</a>, <a href="#rust_toolchain_repository_proxy-repo_mapping">repo_mapping</a>, <a href="#rust_toolchain_repository_proxy-target_compatible_with">target_compatible_with</a>, 2252 <a href="#rust_toolchain_repository_proxy-target_settings">target_settings</a>, <a href="#rust_toolchain_repository_proxy-toolchain">toolchain</a>, <a href="#rust_toolchain_repository_proxy-toolchain_type">toolchain_type</a>) 2253</pre> 2254 2255Generates a toolchain-bearing repository that declares the toolchains from some other rust_toolchain_repository. 2256 2257**ATTRIBUTES** 2258 2259 2260| Name | Description | Type | Mandatory | Default | 2261| :------------- | :------------- | :------------- | :------------- | :------------- | 2262| <a id="rust_toolchain_repository_proxy-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 2263| <a id="rust_toolchain_repository_proxy-exec_compatible_with"></a>exec_compatible_with | A list of constraints for the execution platform for this toolchain. | List of strings | optional | `[]` | 2264| <a id="rust_toolchain_repository_proxy-repo_mapping"></a>repo_mapping | In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).<br><br>This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | | 2265| <a id="rust_toolchain_repository_proxy-target_compatible_with"></a>target_compatible_with | A list of constraints for the target platform for this toolchain. | List of strings | optional | `[]` | 2266| <a id="rust_toolchain_repository_proxy-target_settings"></a>target_settings | A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution. | List of strings | optional | `[]` | 2267| <a id="rust_toolchain_repository_proxy-toolchain"></a>toolchain | The name of the toolchain implementation target. | String | required | | 2268| <a id="rust_toolchain_repository_proxy-toolchain_type"></a>toolchain_type | The toolchain type of the toolchain to declare | String | required | | 2269 2270 2271<a id="rust_toolchain_tools_repository"></a> 2272 2273## rust_toolchain_tools_repository 2274 2275<pre> 2276rust_toolchain_tools_repository(<a href="#rust_toolchain_tools_repository-name">name</a>, <a href="#rust_toolchain_tools_repository-allocator_library">allocator_library</a>, <a href="#rust_toolchain_tools_repository-auth">auth</a>, <a href="#rust_toolchain_tools_repository-auth_patterns">auth_patterns</a>, <a href="#rust_toolchain_tools_repository-dev_components">dev_components</a>, 2277 <a href="#rust_toolchain_tools_repository-edition">edition</a>, <a href="#rust_toolchain_tools_repository-exec_triple">exec_triple</a>, <a href="#rust_toolchain_tools_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_tools_repository-extra_rustc_flags">extra_rustc_flags</a>, 2278 <a href="#rust_toolchain_tools_repository-global_allocator_library">global_allocator_library</a>, <a href="#rust_toolchain_tools_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_tools_repository-netrc">netrc</a>, <a href="#rust_toolchain_tools_repository-opt_level">opt_level</a>, <a href="#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>, 2279 <a href="#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_tools_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_tools_repository-urls">urls</a>, <a href="#rust_toolchain_tools_repository-version">version</a>) 2280</pre> 2281 2282Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms. 2283 2284A given instance of this rule should be accompanied by a toolchain_repository_proxy invocation to declare its toolchains to Bazel; the indirection allows separating toolchain selection from toolchain fetching. 2285 2286**ATTRIBUTES** 2287 2288 2289| Name | Description | Type | Mandatory | Default | 2290| :------------- | :------------- | :------------- | :------------- | :------------- | 2291| <a id="rust_toolchain_tools_repository-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | 2292| <a id="rust_toolchain_tools_repository-allocator_library"></a>allocator_library | Target that provides allocator functions when rust_library targets are embedded in a cc_binary. | String | optional | `"@rules_rust//ffi/cc/allocator_library"` | 2293| <a id="rust_toolchain_tools_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 2294| <a id="rust_toolchain_tools_repository-auth_patterns"></a>auth_patterns | A list of patterns to match against urls for which the auth object should be used. | List of strings | optional | `[]` | 2295| <a id="rust_toolchain_tools_repository-dev_components"></a>dev_components | Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly". | Boolean | optional | `False` | 2296| <a id="rust_toolchain_tools_repository-edition"></a>edition | The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its `edition` attribute. | String | optional | `""` | 2297| <a id="rust_toolchain_tools_repository-exec_triple"></a>exec_triple | The Rust-style target that this compiler runs on | String | required | | 2298| <a id="rust_toolchain_tools_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration | List of strings | optional | `[]` | 2299| <a id="rust_toolchain_tools_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | `[]` | 2300| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | `"@rules_rust//ffi/cc/global_allocator_library"` | 2301| <a id="rust_toolchain_tools_repository-iso_date"></a>iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | `""` | 2302| <a id="rust_toolchain_tools_repository-netrc"></a>netrc | .netrc file to use for authentication; mirrors the eponymous attribute from http_archive | String | optional | `""` | 2303| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. For more details see the documentation for `rust_toolchain.opt_level`. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 2304| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | In `WORKSPACE` context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`).<br><br>This attribute is _not_ supported in `MODULE.bazel` context (when invoking a repository rule inside a module extension's implementation function). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | | 2305| <a id="rust_toolchain_tools_repository-rustfmt_version"></a>rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | `""` | 2306| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_register_toolchains](#rust_register_toolchains) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` | 2307| <a id="rust_toolchain_tools_repository-target_triple"></a>target_triple | The Rust-style target that this compiler builds for. | String | required | | 2308| <a id="rust_toolchain_tools_repository-urls"></a>urls | A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). | List of strings | optional | `["https://static.rust-lang.org/dist/{}.tar.xz"]` | 2309| <a id="rust_toolchain_tools_repository-version"></a>version | The version of the tool among "nightly", "beta", or an exact version. | String | required | | 2310 2311 2312