1*d4726bddSHONG Yifan<!-- Generated with Stardoc: http://skydoc.bazel.build --> 2*d4726bddSHONG Yifan# Rust Proto 3*d4726bddSHONG Yifan 4*d4726bddSHONG Yifan* [rust_prost_library](#rust_prost_library) 5*d4726bddSHONG Yifan* [rust_prost_toolchain](#rust_prost_toolchain) 6*d4726bddSHONG Yifan* [rust_prost_dependencies](#rust_prost_dependencies) 7*d4726bddSHONG Yifan* [rust_prost_transitive_repositories](#rust_prost_transitive_repositories) 8*d4726bddSHONG Yifan* [rust_proto_library](#rust_proto_library) 9*d4726bddSHONG Yifan* [rust_grpc_library](#rust_grpc_library) 10*d4726bddSHONG Yifan* [rust_proto_protobuf_toolchain](#rust_proto_protobuf_toolchain) 11*d4726bddSHONG Yifan* [rust_proto_protobuf_dependencies](#rust_proto_protobuf_dependencies) 12*d4726bddSHONG Yifan* [rust_proto_protobuf_register_toolchains](#rust_proto_protobuf_register_toolchains) 13*d4726bddSHONG Yifan* [rust_proto_protobuf_transitive_repositories](#rust_proto_protobuf_transitive_repositories) 14*d4726bddSHONG Yifan 15*d4726bddSHONG Yifan 16*d4726bddSHONG Yifan## Overview 17*d4726bddSHONG YifanThese build rules are used for building [protobufs][protobuf]/[gRPC][grpc] in [Rust][rust] with Bazel. 18*d4726bddSHONG Yifan 19*d4726bddSHONG YifanThere are two rule sets. The first ruleset defines the `rust_prost_library` which generates Rust code 20*d4726bddSHONG Yifanusing the [`prost`] and [`tonic`] dependencies. The second ruleset defines the `rust_proto_library` and 21*d4726bddSHONG Yifan`rust_grpc_library` rules which generate Rust code using the [`rust-protobuf`] dependencies. 22*d4726bddSHONG Yifan 23*d4726bddSHONG Yifan[rust]: http://www.rust-lang.org/ 24*d4726bddSHONG Yifan[protobuf]: https://developers.google.com/protocol-buffers/ 25*d4726bddSHONG Yifan[grpc]: https://grpc.io 26*d4726bddSHONG Yifan[`rust-protobuf`]: https://github.com/stepancheg/rust-protobuf/ 27*d4726bddSHONG Yifan 28*d4726bddSHONG YifanSee the [protobuf example](../examples/proto) for a more complete example of use. 29*d4726bddSHONG Yifan 30*d4726bddSHONG Yifan### Prost Setup 31*d4726bddSHONG Yifan 32*d4726bddSHONG Yifan```python 33*d4726bddSHONG Yifanload("@rules_rust//proto/prost:repositories.bzl", "rust_prost_dependencies") 34*d4726bddSHONG Yifan 35*d4726bddSHONG Yifanrust_prost_dependencies() 36*d4726bddSHONG Yifan 37*d4726bddSHONG Yifanload("@rules_rust//proto/prost:transitive_repositories.bzl", "rust_prost_transitive_repositories") 38*d4726bddSHONG Yifan 39*d4726bddSHONG Yifanrust_prost_transitive_repositories() 40*d4726bddSHONG Yifan``` 41*d4726bddSHONG Yifan 42*d4726bddSHONG YifanThe `prost` and `tonic` rules do not specify a default toolchain in order to avoid mismatched 43*d4726bddSHONG Yifandependency issues. To setup the `prost` and `tonic` toolchain, please see the section 44*d4726bddSHONG Yifan[Customizing `prost` and `tonic` Dependencies](#custom-prost-deps). 45*d4726bddSHONG Yifan 46*d4726bddSHONG YifanFor additional information about Bazel toolchains, see [here](https://docs.bazel.build/versions/master/toolchains.html). 47*d4726bddSHONG Yifan 48*d4726bddSHONG Yifan#### <a name="custom-prost-deps">Customizing `prost` and `tonic` Dependencies 49*d4726bddSHONG Yifan 50*d4726bddSHONG YifanThese rules depend on the [`prost`] and [`tonic`] dependencies. To setup the necessary toolchain 51*d4726bddSHONG Yifanfor these rules, you must define a toolchain with the [`prost`], [`prost-types`], [`tonic`], [`protoc-gen-prost`], and [`protoc-gen-tonic`] crates as well as the [`protoc`] binary. 52*d4726bddSHONG Yifan 53*d4726bddSHONG Yifan[`prost`]: https://crates.io/crates/prost 54*d4726bddSHONG Yifan[`prost-types`]: https://crates.io/crates/prost-types 55*d4726bddSHONG Yifan[`protoc-gen-prost`]: https://crates.io/crates/protoc-gen-prost 56*d4726bddSHONG Yifan[`protoc-gen-tonic`]: https://crates.io/crates/protoc-gen-tonic 57*d4726bddSHONG Yifan[`tonic`]: https://crates.io/crates/tonic 58*d4726bddSHONG Yifan[`protoc`]: https://github.com/protocolbuffers/protobuf 59*d4726bddSHONG Yifan 60*d4726bddSHONG YifanTo get access to these crates, you can use the [crate_universe](./crate_universe.md) repository 61*d4726bddSHONG Yifanrules. For example: 62*d4726bddSHONG Yifan 63*d4726bddSHONG Yifan```python 64*d4726bddSHONG Yifanload("//crate_universe:defs.bzl", "crate", "crates_repository") 65*d4726bddSHONG Yifan 66*d4726bddSHONG Yifancrates_repository( 67*d4726bddSHONG Yifan name = "crates_io", 68*d4726bddSHONG Yifan annotations = { 69*d4726bddSHONG Yifan "protoc-gen-prost": [crate.annotation( 70*d4726bddSHONG Yifan gen_binaries = ["protoc-gen-prost"], 71*d4726bddSHONG Yifan patch_args = [ 72*d4726bddSHONG Yifan "-p1", 73*d4726bddSHONG Yifan ], 74*d4726bddSHONG Yifan patches = [ 75*d4726bddSHONG Yifan # Note: You will need to use this patch until a version greater than `0.2.2` of 76*d4726bddSHONG Yifan # `protoc-gen-prost` is released. 77*d4726bddSHONG Yifan "@rules_rust//proto/prost/private/3rdparty/patches:protoc-gen-prost.patch", 78*d4726bddSHONG Yifan ], 79*d4726bddSHONG Yifan )], 80*d4726bddSHONG Yifan "protoc-gen-tonic": [crate.annotation( 81*d4726bddSHONG Yifan gen_binaries = ["protoc-gen-tonic"], 82*d4726bddSHONG Yifan )], 83*d4726bddSHONG Yifan }, 84*d4726bddSHONG Yifan cargo_lockfile = "Cargo.Bazel.lock", 85*d4726bddSHONG Yifan mode = "remote", 86*d4726bddSHONG Yifan packages = { 87*d4726bddSHONG Yifan "prost": crate.spec( 88*d4726bddSHONG Yifan version = "0", 89*d4726bddSHONG Yifan ), 90*d4726bddSHONG Yifan "prost-types": crate.spec( 91*d4726bddSHONG Yifan version = "0", 92*d4726bddSHONG Yifan ), 93*d4726bddSHONG Yifan "protoc-gen-prost": crate.spec( 94*d4726bddSHONG Yifan version = "0", 95*d4726bddSHONG Yifan ), 96*d4726bddSHONG Yifan "protoc-gen-tonic": crate.spec( 97*d4726bddSHONG Yifan version = "0", 98*d4726bddSHONG Yifan ), 99*d4726bddSHONG Yifan "tonic": crate.spec( 100*d4726bddSHONG Yifan version = "0", 101*d4726bddSHONG Yifan ), 102*d4726bddSHONG Yifan }, 103*d4726bddSHONG Yifan repository_name = "rules_rust_prost", 104*d4726bddSHONG Yifan tags = ["manual"], 105*d4726bddSHONG Yifan) 106*d4726bddSHONG Yifan``` 107*d4726bddSHONG Yifan 108*d4726bddSHONG YifanYou can then define a toolchain with the `rust_prost_toolchain` rule which uses the crates 109*d4726bddSHONG Yifandefined above. For example: 110*d4726bddSHONG Yifan 111*d4726bddSHONG Yifan```python 112*d4726bddSHONG Yifanload("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain") 113*d4726bddSHONG Yifanload("@rules_rust//rust:defs.bzl", "rust_library_group") 114*d4726bddSHONG Yifan 115*d4726bddSHONG Yifanrust_library_group( 116*d4726bddSHONG Yifan name = "prost_runtime", 117*d4726bddSHONG Yifan deps = [ 118*d4726bddSHONG Yifan "@crates_io//:prost", 119*d4726bddSHONG Yifan ], 120*d4726bddSHONG Yifan) 121*d4726bddSHONG Yifan 122*d4726bddSHONG Yifanrust_library_group( 123*d4726bddSHONG Yifan name = "tonic_runtime", 124*d4726bddSHONG Yifan deps = [ 125*d4726bddSHONG Yifan ":prost_runtime", 126*d4726bddSHONG Yifan "@crates_io//:tonic", 127*d4726bddSHONG Yifan ], 128*d4726bddSHONG Yifan) 129*d4726bddSHONG Yifan 130*d4726bddSHONG Yifanrust_prost_toolchain( 131*d4726bddSHONG Yifan name = "prost_toolchain_impl", 132*d4726bddSHONG Yifan prost_plugin = "@crates_io//:protoc-gen-prost__protoc-gen-prost", 133*d4726bddSHONG Yifan prost_runtime = ":prost_runtime", 134*d4726bddSHONG Yifan prost_types = "@crates_io//:prost-types", 135*d4726bddSHONG Yifan proto_compiler = "@com_google_protobuf//:protoc", 136*d4726bddSHONG Yifan tonic_plugin = "@crates_io//:protoc-gen-tonic__protoc-gen-tonic", 137*d4726bddSHONG Yifan tonic_runtime = ":tonic_runtime", 138*d4726bddSHONG Yifan) 139*d4726bddSHONG Yifan 140*d4726bddSHONG Yifantoolchain( 141*d4726bddSHONG Yifan name = "prost_toolchain", 142*d4726bddSHONG Yifan toolchain = "prost_toolchain_impl", 143*d4726bddSHONG Yifan toolchain_type = "@rules_rust//proto/prost:toolchain_type", 144*d4726bddSHONG Yifan) 145*d4726bddSHONG Yifan``` 146*d4726bddSHONG Yifan 147*d4726bddSHONG YifanLastly, you must register the toolchain in your `WORKSPACE` file. For example: 148*d4726bddSHONG Yifan 149*d4726bddSHONG Yifan```python 150*d4726bddSHONG Yifanregister_toolchains("//toolchains:prost_toolchain") 151*d4726bddSHONG Yifan``` 152*d4726bddSHONG Yifan 153*d4726bddSHONG Yifan## Rust-Protobuf Setup 154*d4726bddSHONG Yifan 155*d4726bddSHONG YifanTo use the Rust proto rules, add the following to your `WORKSPACE` file to add the 156*d4726bddSHONG Yifanexternal repositories for the Rust proto toolchain (in addition to the [rust rules setup](..)): 157*d4726bddSHONG Yifan 158*d4726bddSHONG Yifan```python 159*d4726bddSHONG Yifanload("@rules_rust//proto/protobuf:repositories.bzl", "rust_proto_protobuf_dependencies", "rust_proto_protobuf_register_toolchains") 160*d4726bddSHONG Yifan 161*d4726bddSHONG Yifanrust_proto_protobuf_dependencies() 162*d4726bddSHONG Yifan 163*d4726bddSHONG Yifanrust_proto_protobuf_register_toolchains() 164*d4726bddSHONG Yifan 165*d4726bddSHONG Yifanload("@rules_rust//proto/protobuf:transitive_repositories.bzl", "rust_proto_protobuf_transitive_repositories") 166*d4726bddSHONG Yifan 167*d4726bddSHONG Yifanrust_proto_protobuf_transitive_repositories() 168*d4726bddSHONG Yifan``` 169*d4726bddSHONG Yifan 170*d4726bddSHONG YifanThis will load the required dependencies for the [`rust-protobuf`] rules. It will also 171*d4726bddSHONG Yifanregister a default toolchain for the `rust_proto_library` and `rust_grpc_library` rules. 172*d4726bddSHONG Yifan 173*d4726bddSHONG YifanTo customize the `rust_proto_library` and `rust_grpc_library` toolchain, please see the section 174*d4726bddSHONG Yifan[Customizing `rust-protobuf` Dependencies](#custom-proto-deps). 175*d4726bddSHONG Yifan 176*d4726bddSHONG YifanFor additional information about Bazel toolchains, see [here](https://docs.bazel.build/versions/master/toolchains.html). 177*d4726bddSHONG Yifan 178*d4726bddSHONG Yifan#### <a name="custom-proto-deps">Customizing `rust-protobuf` Dependencies 179*d4726bddSHONG Yifan 180*d4726bddSHONG YifanThese rules depend on the [`protobuf`](https://crates.io/crates/protobuf) and 181*d4726bddSHONG Yifanthe [`grpc`](https://crates.io/crates/grpc) crates in addition to the [protobuf 182*d4726bddSHONG Yifancompiler](https://github.com/google/protobuf). To obtain these crates, 183*d4726bddSHONG Yifan`rust_proto_repositories` imports the given crates using BUILD files generated with 184*d4726bddSHONG Yifan[crate_universe](./crate_universe.md). 185*d4726bddSHONG Yifan 186*d4726bddSHONG YifanIf you want to either change the protobuf and gRPC rust compilers, or to 187*d4726bddSHONG Yifansimply use [crate_universe](./crate_universe.md) in a more 188*d4726bddSHONG Yifancomplex scenario (with more dependencies), you must redefine those 189*d4726bddSHONG Yifandependencies. 190*d4726bddSHONG Yifan 191*d4726bddSHONG YifanTo do this, once you've imported the needed dependencies (see our 192*d4726bddSHONG Yifan[@rules_rust//proto/3rdparty/BUILD.bazel](https://github.com/bazelbuild/rules_rust/blob/main/proto/3rdparty/BUILD.bazel) 193*d4726bddSHONG Yifanfile to see the default dependencies), you need to create your own toolchain. 194*d4726bddSHONG YifanTo do so you can create a BUILD file with your toolchain definition, for example: 195*d4726bddSHONG Yifan 196*d4726bddSHONG Yifan```python 197*d4726bddSHONG Yifanload("@rules_rust//proto:toolchain.bzl", "rust_proto_toolchain") 198*d4726bddSHONG Yifan 199*d4726bddSHONG Yifanrust_proto_toolchain( 200*d4726bddSHONG Yifan name = "proto-toolchain-impl", 201*d4726bddSHONG Yifan # Path to the protobuf compiler. 202*d4726bddSHONG Yifan protoc = "@com_google_protobuf//:protoc", 203*d4726bddSHONG Yifan # Protobuf compiler plugin to generate rust gRPC stubs. 204*d4726bddSHONG Yifan grpc_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust_grpc", 205*d4726bddSHONG Yifan # Protobuf compiler plugin to generate rust protobuf stubs. 206*d4726bddSHONG Yifan proto_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust", 207*d4726bddSHONG Yifan) 208*d4726bddSHONG Yifan 209*d4726bddSHONG Yifantoolchain( 210*d4726bddSHONG Yifan name = "proto-toolchain", 211*d4726bddSHONG Yifan toolchain = ":proto-toolchain-impl", 212*d4726bddSHONG Yifan toolchain_type = "@rules_rust//proto/protobuf:toolchain_type", 213*d4726bddSHONG Yifan) 214*d4726bddSHONG Yifan``` 215*d4726bddSHONG Yifan 216*d4726bddSHONG YifanNow that you have your own toolchain, you need to register it by 217*d4726bddSHONG Yifaninserting the following statement in your `WORKSPACE` file: 218*d4726bddSHONG Yifan 219*d4726bddSHONG Yifan```python 220*d4726bddSHONG Yifanregister_toolchains("//my/toolchains:proto-toolchain") 221*d4726bddSHONG Yifan``` 222*d4726bddSHONG Yifan 223*d4726bddSHONG YifanFinally, you might want to set the `rust_deps` attribute in 224*d4726bddSHONG Yifan`rust_proto_library` and `rust_grpc_library` to change the compile-time 225*d4726bddSHONG Yifandependencies: 226*d4726bddSHONG Yifan 227*d4726bddSHONG Yifan```python 228*d4726bddSHONG Yifanrust_proto_library( 229*d4726bddSHONG Yifan ... 230*d4726bddSHONG Yifan rust_deps = ["//3rdparty/crates:protobuf"], 231*d4726bddSHONG Yifan ... 232*d4726bddSHONG Yifan) 233*d4726bddSHONG Yifan 234*d4726bddSHONG Yifanrust_grpc_library( 235*d4726bddSHONG Yifan ... 236*d4726bddSHONG Yifan rust_deps = [ 237*d4726bddSHONG Yifan "//3rdparty/crates:protobuf", 238*d4726bddSHONG Yifan "//3rdparty/crates:grpc", 239*d4726bddSHONG Yifan "//3rdparty/crates:tls_api", 240*d4726bddSHONG Yifan "//3rdparty/crates:tls_api_stub", 241*d4726bddSHONG Yifan ], 242*d4726bddSHONG Yifan ... 243*d4726bddSHONG Yifan) 244*d4726bddSHONG Yifan``` 245*d4726bddSHONG Yifan 246*d4726bddSHONG Yifan__Note__: Ideally, we would inject those dependencies from the toolchain, 247*d4726bddSHONG Yifanbut due to [bazelbuild/bazel#6889](https://github.com/bazelbuild/bazel/issues/6889) 248*d4726bddSHONG Yifanall dependencies added via the toolchain ends-up being in the wrong 249*d4726bddSHONG Yifanconfiguration. 250*d4726bddSHONG Yifan 251*d4726bddSHONG Yifan--- 252*d4726bddSHONG Yifan--- 253*d4726bddSHONG Yifan 254*d4726bddSHONG Yifan 255*d4726bddSHONG Yifan 256*d4726bddSHONG Yifan<a id="rust_grpc_library"></a> 257*d4726bddSHONG Yifan 258*d4726bddSHONG Yifan## rust_grpc_library 259*d4726bddSHONG Yifan 260*d4726bddSHONG Yifan<pre> 261*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>) 262*d4726bddSHONG Yifan</pre> 263*d4726bddSHONG Yifan 264*d4726bddSHONG YifanBuilds a Rust library crate from a set of `proto_library`s suitable for gRPC. 265*d4726bddSHONG Yifan 266*d4726bddSHONG YifanExample: 267*d4726bddSHONG Yifan 268*d4726bddSHONG Yifan```python 269*d4726bddSHONG Yifanload("@rules_rust//proto/protobuf:defs.bzl", "rust_grpc_library") 270*d4726bddSHONG Yifan 271*d4726bddSHONG Yifanproto_library( 272*d4726bddSHONG Yifan name = "my_proto", 273*d4726bddSHONG Yifan srcs = ["my.proto"] 274*d4726bddSHONG Yifan) 275*d4726bddSHONG Yifan 276*d4726bddSHONG Yifanrust_grpc_library( 277*d4726bddSHONG Yifan name = "rust", 278*d4726bddSHONG Yifan deps = [":my_proto"], 279*d4726bddSHONG Yifan) 280*d4726bddSHONG Yifan 281*d4726bddSHONG Yifanrust_binary( 282*d4726bddSHONG Yifan name = "my_service", 283*d4726bddSHONG Yifan srcs = ["my_service.rs"], 284*d4726bddSHONG Yifan deps = [":rust"], 285*d4726bddSHONG Yifan) 286*d4726bddSHONG Yifan``` 287*d4726bddSHONG Yifan 288*d4726bddSHONG Yifan**ATTRIBUTES** 289*d4726bddSHONG Yifan 290*d4726bddSHONG Yifan 291*d4726bddSHONG Yifan| Name | Description | Type | Mandatory | Default | 292*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | :------------- | :------------- | 293*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 | | 294*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 | | 295*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 | `""` | 296*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 | `[]` | 297*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 | `[]` | 298*d4726bddSHONG Yifan 299*d4726bddSHONG Yifan 300*d4726bddSHONG Yifan<a id="rust_prost_toolchain"></a> 301*d4726bddSHONG Yifan 302*d4726bddSHONG Yifan## rust_prost_toolchain 303*d4726bddSHONG Yifan 304*d4726bddSHONG Yifan<pre> 305*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>, 306*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>) 307*d4726bddSHONG Yifan</pre> 308*d4726bddSHONG Yifan 309*d4726bddSHONG YifanRust Prost toolchain rule. 310*d4726bddSHONG Yifan 311*d4726bddSHONG Yifan**ATTRIBUTES** 312*d4726bddSHONG Yifan 313*d4726bddSHONG Yifan 314*d4726bddSHONG Yifan| Name | Description | Type | Mandatory | Default | 315*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | :------------- | :------------- | 316*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 | | 317*d4726bddSHONG Yifan| <a id="rust_prost_toolchain-prost_opts"></a>prost_opts | Additional options to add to Prost. | List of strings | optional | `[]` | 318*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 | | 319*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"` | 320*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 | | 321*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 | | 322*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` | 323*d4726bddSHONG Yifan| <a id="rust_prost_toolchain-tonic_opts"></a>tonic_opts | Additional options to add to Tonic. | List of strings | optional | `[]` | 324*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` | 325*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"` | 326*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` | 327*d4726bddSHONG Yifan 328*d4726bddSHONG Yifan 329*d4726bddSHONG Yifan<a id="rust_proto_library"></a> 330*d4726bddSHONG Yifan 331*d4726bddSHONG Yifan## rust_proto_library 332*d4726bddSHONG Yifan 333*d4726bddSHONG Yifan<pre> 334*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>) 335*d4726bddSHONG Yifan</pre> 336*d4726bddSHONG Yifan 337*d4726bddSHONG YifanBuilds a Rust library crate from a set of `proto_library`s. 338*d4726bddSHONG Yifan 339*d4726bddSHONG YifanExample: 340*d4726bddSHONG Yifan 341*d4726bddSHONG Yifan```python 342*d4726bddSHONG Yifanload("@rules_rust//proto/protobuf:defs.bzl", "rust_proto_library") 343*d4726bddSHONG Yifan 344*d4726bddSHONG Yifanproto_library( 345*d4726bddSHONG Yifan name = "my_proto", 346*d4726bddSHONG Yifan srcs = ["my.proto"] 347*d4726bddSHONG Yifan) 348*d4726bddSHONG Yifan 349*d4726bddSHONG Yifanrust_proto_library( 350*d4726bddSHONG Yifan name = "rust", 351*d4726bddSHONG Yifan deps = [":my_proto"], 352*d4726bddSHONG Yifan) 353*d4726bddSHONG Yifan 354*d4726bddSHONG Yifanrust_binary( 355*d4726bddSHONG Yifan name = "my_proto_binary", 356*d4726bddSHONG Yifan srcs = ["my_proto_binary.rs"], 357*d4726bddSHONG Yifan deps = [":rust"], 358*d4726bddSHONG Yifan) 359*d4726bddSHONG Yifan``` 360*d4726bddSHONG Yifan 361*d4726bddSHONG Yifan**ATTRIBUTES** 362*d4726bddSHONG Yifan 363*d4726bddSHONG Yifan 364*d4726bddSHONG Yifan| Name | Description | Type | Mandatory | Default | 365*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | :------------- | :------------- | 366*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 | | 367*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 | | 368*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 | `""` | 369*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 | `[]` | 370*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 | `[]` | 371*d4726bddSHONG Yifan 372*d4726bddSHONG Yifan 373*d4726bddSHONG Yifan<a id="rust_prost_dependencies"></a> 374*d4726bddSHONG Yifan 375*d4726bddSHONG Yifan## rust_prost_dependencies 376*d4726bddSHONG Yifan 377*d4726bddSHONG Yifan<pre> 378*d4726bddSHONG Yifanrust_prost_dependencies(<a href="#rust_prost_dependencies-bzlmod">bzlmod</a>) 379*d4726bddSHONG Yifan</pre> 380*d4726bddSHONG Yifan 381*d4726bddSHONG YifanDeclares repositories needed for prost. 382*d4726bddSHONG Yifan 383*d4726bddSHONG Yifan**PARAMETERS** 384*d4726bddSHONG Yifan 385*d4726bddSHONG Yifan 386*d4726bddSHONG Yifan| Name | Description | Default Value | 387*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | 388*d4726bddSHONG Yifan| <a id="rust_prost_dependencies-bzlmod"></a>bzlmod | Whether bzlmod is enabled. | `False` | 389*d4726bddSHONG Yifan 390*d4726bddSHONG Yifan**RETURNS** 391*d4726bddSHONG Yifan 392*d4726bddSHONG Yifanlist[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 393*d4726bddSHONG Yifan defined by this macro. 394*d4726bddSHONG Yifan 395*d4726bddSHONG Yifan 396*d4726bddSHONG Yifan<a id="rust_prost_library"></a> 397*d4726bddSHONG Yifan 398*d4726bddSHONG Yifan## rust_prost_library 399*d4726bddSHONG Yifan 400*d4726bddSHONG Yifan<pre> 401*d4726bddSHONG Yifanrust_prost_library(<a href="#rust_prost_library-name">name</a>, <a href="#rust_prost_library-kwargs">kwargs</a>) 402*d4726bddSHONG Yifan</pre> 403*d4726bddSHONG Yifan 404*d4726bddSHONG YifanA rule for generating a Rust library using Prost. 405*d4726bddSHONG Yifan 406*d4726bddSHONG Yifan**PARAMETERS** 407*d4726bddSHONG Yifan 408*d4726bddSHONG Yifan 409*d4726bddSHONG Yifan| Name | Description | Default Value | 410*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | 411*d4726bddSHONG Yifan| <a id="rust_prost_library-name"></a>name | The name of the target. | none | 412*d4726bddSHONG Yifan| <a id="rust_prost_library-kwargs"></a>kwargs | Additional keyword arguments for the underlying `rust_prost_library` rule. | none | 413*d4726bddSHONG Yifan 414*d4726bddSHONG Yifan 415*d4726bddSHONG Yifan<a id="rust_prost_transitive_repositories"></a> 416*d4726bddSHONG Yifan 417*d4726bddSHONG Yifan## rust_prost_transitive_repositories 418*d4726bddSHONG Yifan 419*d4726bddSHONG Yifan<pre> 420*d4726bddSHONG Yifanrust_prost_transitive_repositories() 421*d4726bddSHONG Yifan</pre> 422*d4726bddSHONG Yifan 423*d4726bddSHONG YifanLoad transitive dependencies of the `@rules_rust//proto/protobuf` rules. 424*d4726bddSHONG Yifan 425*d4726bddSHONG YifanThis macro should be called immediately after the `rust_protobuf_dependencies` macro. 426*d4726bddSHONG Yifan 427*d4726bddSHONG Yifan 428*d4726bddSHONG Yifan 429*d4726bddSHONG Yifan<a id="rust_proto_protobuf_dependencies"></a> 430*d4726bddSHONG Yifan 431*d4726bddSHONG Yifan## rust_proto_protobuf_dependencies 432*d4726bddSHONG Yifan 433*d4726bddSHONG Yifan<pre> 434*d4726bddSHONG Yifanrust_proto_protobuf_dependencies(<a href="#rust_proto_protobuf_dependencies-bzlmod">bzlmod</a>) 435*d4726bddSHONG Yifan</pre> 436*d4726bddSHONG Yifan 437*d4726bddSHONG YifanSets up dependencies for rules_rust's proto support. 438*d4726bddSHONG Yifan 439*d4726bddSHONG Yifan**PARAMETERS** 440*d4726bddSHONG Yifan 441*d4726bddSHONG Yifan 442*d4726bddSHONG Yifan| Name | Description | Default Value | 443*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | 444*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` | 445*d4726bddSHONG Yifan 446*d4726bddSHONG Yifan**RETURNS** 447*d4726bddSHONG Yifan 448*d4726bddSHONG YifanA list of structs containing information about root module deps to report to bzlmod's extension_metadata. 449*d4726bddSHONG Yifan 450*d4726bddSHONG Yifan 451*d4726bddSHONG Yifan<a id="rust_proto_protobuf_register_toolchains"></a> 452*d4726bddSHONG Yifan 453*d4726bddSHONG Yifan## rust_proto_protobuf_register_toolchains 454*d4726bddSHONG Yifan 455*d4726bddSHONG Yifan<pre> 456*d4726bddSHONG Yifanrust_proto_protobuf_register_toolchains(<a href="#rust_proto_protobuf_register_toolchains-register_toolchains">register_toolchains</a>) 457*d4726bddSHONG Yifan</pre> 458*d4726bddSHONG Yifan 459*d4726bddSHONG YifanRegister toolchains for proto compilation. 460*d4726bddSHONG Yifan 461*d4726bddSHONG Yifan**PARAMETERS** 462*d4726bddSHONG Yifan 463*d4726bddSHONG Yifan 464*d4726bddSHONG Yifan| Name | Description | Default Value | 465*d4726bddSHONG Yifan| :------------- | :------------- | :------------- | 466*d4726bddSHONG Yifan| <a id="rust_proto_protobuf_register_toolchains-register_toolchains"></a>register_toolchains | <p align="center"> - </p> | `True` | 467*d4726bddSHONG Yifan 468*d4726bddSHONG Yifan 469*d4726bddSHONG Yifan<a id="rust_proto_protobuf_transitive_repositories"></a> 470*d4726bddSHONG Yifan 471*d4726bddSHONG Yifan## rust_proto_protobuf_transitive_repositories 472*d4726bddSHONG Yifan 473*d4726bddSHONG Yifan<pre> 474*d4726bddSHONG Yifanrust_proto_protobuf_transitive_repositories() 475*d4726bddSHONG Yifan</pre> 476*d4726bddSHONG Yifan 477*d4726bddSHONG YifanLoad transitive dependencies of the `@rules_rust//proto/protobuf` rules. 478*d4726bddSHONG Yifan 479*d4726bddSHONG YifanThis macro should be called immediately after the `rust_protobuf_dependencies` macro. 480*d4726bddSHONG Yifan 481*d4726bddSHONG Yifan 482*d4726bddSHONG Yifan 483