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