diff --git a/docs/flatten.md b/docs/flatten.md index 28edf8beaa..f997431833 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -598,7 +598,7 @@ Running `bazel test //hello_lib:hello_lib_doc_test` will run all documentation t ## rust_grpc_library
-rust_grpc_library(name, deps, rust_deps, rustc_flags)
+rust_grpc_library(name, crate_name, deps, rust_deps, rustc_flags)
 
Builds a Rust library crate from a set of `proto_library`s suitable for gRPC. @@ -632,6 +632,7 @@ rust_binary( | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | +| crate_name | Crate name to use for this target.

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 | "" | | 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 | [] | | rustc_flags | List of compiler flags passed to rustc.

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 | [] | @@ -856,7 +857,7 @@ Rust Prost toolchain rule. ## rust_proto_library
-rust_proto_library(name, deps, rust_deps, rustc_flags)
+rust_proto_library(name, crate_name, deps, rust_deps, rustc_flags)
 
Builds a Rust library crate from a set of `proto_library`s. @@ -890,6 +891,7 @@ rust_binary( | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | +| crate_name | Crate name to use for this target.

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 | "" | | 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 | [] | | rustc_flags | List of compiler flags passed to rustc.

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 | [] | diff --git a/docs/rust_proto.md b/docs/rust_proto.md index 4511fee532..0cfe312b7e 100644 --- a/docs/rust_proto.md +++ b/docs/rust_proto.md @@ -258,7 +258,7 @@ configuration. ## rust_grpc_library
-rust_grpc_library(name, deps, rust_deps, rustc_flags)
+rust_grpc_library(name, crate_name, deps, rust_deps, rustc_flags)
 
Builds a Rust library crate from a set of `proto_library`s suitable for gRPC. @@ -292,6 +292,7 @@ rust_binary( | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | +| crate_name | Crate name to use for this target.

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 | "" | | 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 | [] | | rustc_flags | List of compiler flags passed to rustc.

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 | [] | @@ -331,7 +332,7 @@ Rust Prost toolchain rule. ## rust_proto_library
-rust_proto_library(name, deps, rust_deps, rustc_flags)
+rust_proto_library(name, crate_name, deps, rust_deps, rustc_flags)
 
Builds a Rust library crate from a set of `proto_library`s. @@ -365,6 +366,7 @@ rust_binary( | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | +| crate_name | Crate name to use for this target.

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 | "" | | 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 | [] | | rustc_flags | List of compiler flags passed to rustc.

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 | [] | diff --git a/examples/proto/basic/BUILD.bazel b/examples/proto/basic/BUILD.bazel index 1f012b272f..db0cf2cd9e 100644 --- a/examples/proto/basic/BUILD.bazel +++ b/examples/proto/basic/BUILD.bazel @@ -4,7 +4,8 @@ load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") package(default_visibility = ["//proto:__subpackages__"]) rust_proto_library( - name = "common_proto_rust", + name = "libcommon_proto_rust", + crate_name = "common_proto_rust", tags = ["manual"], deps = ["//proto:common"], ) @@ -13,7 +14,7 @@ rust_library( name = "common_lib", srcs = ["lib.rs"], tags = ["manual"], - deps = [":common_proto_rust"], + deps = [":libcommon_proto_rust"], ) rust_binary( @@ -22,6 +23,6 @@ rust_binary( tags = ["manual"], deps = [ ":common_lib", - ":common_proto_rust", + ":libcommon_proto_rust", ], ) diff --git a/examples/proto/helloworld/BUILD.bazel b/examples/proto/helloworld/BUILD.bazel index c42bfce8fb..d665aae731 100644 --- a/examples/proto/helloworld/BUILD.bazel +++ b/examples/proto/helloworld/BUILD.bazel @@ -10,7 +10,8 @@ proto_library( ) rust_grpc_library( - name = "helloworld_proto", + name = "libhelloworld_proto", + crate_name = "helloworld_proto", tags = ["manual"], visibility = ["//proto/helloworld:__subpackages__"], deps = [":helloworld"], diff --git a/examples/proto/helloworld/greeter_client/BUILD.bazel b/examples/proto/helloworld/greeter_client/BUILD.bazel index 828aeb91b6..f4d0c03803 100644 --- a/examples/proto/helloworld/greeter_client/BUILD.bazel +++ b/examples/proto/helloworld/greeter_client/BUILD.bazel @@ -7,6 +7,6 @@ rust_binary( tags = ["manual"], visibility = ["//proto/helloworld:__subpackages__"], deps = [ - "//proto/helloworld:helloworld_proto", + "//proto/helloworld:libhelloworld_proto", ] + GRPC_COMPILE_DEPS, ) diff --git a/proto/protobuf/proto.bzl b/proto/protobuf/proto.bzl index 36c49a1b00..ca2df8a21f 100644 --- a/proto/protobuf/proto.bzl +++ b/proto/protobuf/proto.bzl @@ -253,7 +253,7 @@ def _rust_protogrpc_library_impl(ctx, is_grpc): ] toolchain = find_toolchain(ctx) - crate_name = compute_crate_name(ctx.workspace_name, ctx.label, toolchain) + crate_name = compute_crate_name(ctx.workspace_name, ctx.label, toolchain, ctx.attr.crate_name) return _rust_proto_compile( protos = depset(transitive = transitive_sources), @@ -280,6 +280,14 @@ def _rust_proto_library_impl(ctx): rust_proto_library = rule( implementation = _rust_proto_library_impl, attrs = { + "crate_name": attr.string( + doc = """\ + Crate name to use for this target. + + 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. + """, + ), "deps": attr.label_list( doc = ( "List of proto_library dependencies that will be built. " + @@ -368,6 +376,14 @@ def _rust_grpc_library_impl(ctx): rust_grpc_library = rule( implementation = _rust_grpc_library_impl, attrs = { + "crate_name": attr.string( + doc = """\ + Crate name to use for this target. + + 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. + """, + ), "deps": attr.label_list( doc = ( "List of proto_library dependencies that will be built. " +