Builds a Rust library crate from a set of proto_library
s suitable for gRPC.
Example:
load("//proto:proto.bzl", "rust_grpc_library") proto_library( name = "my_proto", srcs = ["my.proto"] ) rust_grpc_library( name = "rust", deps = [":my_proto"], ) rust_binary( name = "my_service", srcs = ["my_service.rs"], deps = [":rust"], )
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
deps | List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding gRPC stubs. | List of labels | required | |
rust_deps | The crates the generated library depends on. | List of labels | optional | [] |
Builds a Rust library crate from a set of proto_library
s.
Example:
load("@rules_rust//proto:proto.bzl", "rust_proto_library") proto_library( name = "my_proto", srcs = ["my.proto"] ) proto_rust_library( name = "rust", deps = [":my_proto"], ) rust_binary( name = "my_proto_binary", srcs = ["my_proto_binary.rs"], deps = [":rust"], )
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
deps | List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding stubs. | List of labels | required | |
rust_deps | The crates the generated library depends on. | List of labels | optional | [] |
Declares a Rust Proto toolchain for use.
This is used to configure proto compilation and can be used to set different protobuf compiler plugin.
Example:
Suppose a new nicer gRPC plugin has came out. The new plugin can be used in Bazel by defining a new toolchain definition and declaration:
load('@rules_rust//proto:toolchain.bzl', 'rust_proto_toolchain') rust_proto_toolchain( name="rust_proto_impl", grpc_plugin="@rust_grpc//:grpc_plugin", grpc_compile_deps=["@rust_grpc//:grpc_deps"], ) toolchain( name="rust_proto", exec_compatible_with = [ "@platforms//cpu:cpuX", ], target_compatible_with = [ "@platforms//cpu:cpuX", ], toolchain = ":rust_proto_impl", )
Then, 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.
See @rules_rust//proto:BUILD for examples of defining the toolchain.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
edition | The edition used by the generated rust source. | String | optional | “2015” |
grpc_compile_deps | The crates the generated grpc libraries depends on. | List of labels | optional | [Label(“//proto/raze:protobuf”), Label(“//proto/raze:grpc”), Label(“//proto/raze:tls_api”), Label(“//proto/raze:tls_api_stub”)] |
grpc_plugin | The location of the Rust protobuf compiler plugin to generate rust gRPC stubs. | Label | optional | //proto:protoc_gen_rust_grpc |
proto_compile_deps | The crates the generated protobuf libraries depends on. | List of labels | optional | [Label(“//proto/raze:protobuf”)] |
proto_plugin | The location of the Rust protobuf compiler plugin used to generate rust sources. | Label | optional | //proto:protoc_gen_rust |
protoc | The location of the protoc binary. It should be an executable target. | Label | optional | @com_google_protobuf//:protoc |
Declare dependencies needed for proto compilation.
PARAMETERS
Name | Description | Default Value |
---|---|---|
register_default_toolchain | If True, the default rust_proto_toolchain (@rules_rust//proto:default-proto-toolchain) is registered. This toolchain requires a set of dependencies that were generated using cargo raze. These will also be loaded. | True |