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