Skip to content

Commit 67bff65

Browse files
freeformstuSilcet
authored andcommitted
Consolidate rust_prost_library and fix extension-only proto generation. (bazelbuild#2047)
This PR consolidates rust_prost_library and rust_tonic_library into one rule; `rust_prost_library`. `rust_prost_library` will generate tonic services if you provide a `tonic_plugin` in the toolchain definition. If you do not provide that plugin and you try to build a proto with services, it will print a warning that you should add a `tonic_plugin`. This PR also handles extension-only proto files. Prost does not generate a file if there are no messages, enums, or services and it appears that Prost doesn't even support proto2 extensions. So to work around this issue, protoc_wrapper will generate an empty `.rs` file in the case that there are only extensions defined in a file. Closes: bazelbuild#2046
1 parent 2c6d3d9 commit 67bff65

File tree

19 files changed

+365
-255
lines changed

19 files changed

+365
-255
lines changed

WORKSPACE.bazel

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ load("//test:deps.bzl", "rules_rust_test_deps")
5252

5353
rules_rust_test_deps()
5454

55+
load("//test:deps_transitive.bzl", "rules_rust_test_deps_transitive")
56+
57+
rules_rust_test_deps_transitive()
58+
5559
# --- end stardoc
5660

5761
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

docs/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ PAGES = dict([
122122
"rust_proto_transitive_repositories",
123123
"rust_proto_toolchain",
124124
"rust_prost_library",
125-
"rust_tonic_library",
126125
],
127126
),
128127
page(

docs/flatten.md

-20
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
* [rust_stdlib_filegroup](#rust_stdlib_filegroup)
4545
* [rust_test](#rust_test)
4646
* [rust_test_suite](#rust_test_suite)
47-
* [rust_tonic_library](#rust_tonic_library)
4847
* [rust_toolchain](#rust_toolchain)
4948
* [rust_toolchain_repository](#rust_toolchain_repository)
5049
* [rust_toolchain_repository_proxy](#rust_toolchain_repository_proxy)
@@ -2019,25 +2018,6 @@ rust_test_suite(
20192018
| <a id="rust_test_suite-kwargs"></a>kwargs | Additional keyword arguments for the underyling [rust_test](#rust_test) targets. The <code>tags</code> argument is also passed to the generated <code>test_suite</code> target. | none |
20202019

20212020

2022-
<a id="rust_tonic_library"></a>
2023-
2024-
## rust_tonic_library
2025-
2026-
<pre>
2027-
rust_tonic_library(<a href="#rust_tonic_library-name">name</a>, <a href="#rust_tonic_library-kwargs">kwargs</a>)
2028-
</pre>
2029-
2030-
A rule for generating a Rust library using Prost and Tonic.
2031-
2032-
**PARAMETERS**
2033-
2034-
2035-
| Name | Description | Default Value |
2036-
| :------------- | :------------- | :------------- |
2037-
| <a id="rust_tonic_library-name"></a>name | The name of the target. | none |
2038-
| <a id="rust_tonic_library-kwargs"></a>kwargs | Additional keyword arguments for the underlying <code>rust_tonic_library</code> rule. | none |
2039-
2040-
20412021
<a id="rust_toolchain_repository"></a>
20422022

20432023
## rust_toolchain_repository

docs/rust_proto.md

+1-22
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
* [rust_proto_transitive_repositories](#rust_proto_transitive_repositories)
88
* [rust_proto_toolchain](#rust_proto_toolchain)
99
* [rust_prost_library](#rust_prost_library)
10-
* [rust_tonic_library](#rust_tonic_library)
1110

1211

1312
## Overview
1413
These build rules are used for building [protobufs][protobuf]/[gRPC][grpc] in [Rust][rust] with Bazel.
1514

1615
There are two rule sets. The first ruleset defines the `rust_proto_library` and `rust_grpc_library`
1716
rules which generate Rust code using the [`rust-protobuf`] dependencies. The second ruleset defines
18-
the `rust_prost_library` and `rust_tonic_library` rules which generate Rust code using the [`prost`]
19-
and [`tonic`] dependencies respectively.
17+
the `rust_prost_library` which generates Rust code using the [`prost`] and [`tonic`] dependencies.
2018

2119
[rust]: http://www.rust-lang.org/
2220
[protobuf]: https://developers.google.com/protocol-buffers/
@@ -427,22 +425,3 @@ This macro should be called immediately after the `rust_proto_repositories` macr
427425

428426

429427

430-
<a id="rust_tonic_library"></a>
431-
432-
## rust_tonic_library
433-
434-
<pre>
435-
rust_tonic_library(<a href="#rust_tonic_library-name">name</a>, <a href="#rust_tonic_library-kwargs">kwargs</a>)
436-
</pre>
437-
438-
A rule for generating a Rust library using Prost and Tonic.
439-
440-
**PARAMETERS**
441-
442-
443-
| Name | Description | Default Value |
444-
| :------------- | :------------- | :------------- |
445-
| <a id="rust_tonic_library-name"></a>name | The name of the target. | none |
446-
| <a id="rust_tonic_library-kwargs"></a>kwargs | Additional keyword arguments for the underlying <code>rust_tonic_library</code> rule. | none |
447-
448-

docs/rust_proto.vm

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ These build rules are used for building [protobufs][protobuf]/[gRPC][grpc] in [R
44

55
There are two rule sets. The first ruleset defines the `rust_proto_library` and `rust_grpc_library`
66
rules which generate Rust code using the [`rust-protobuf`] dependencies. The second ruleset defines
7-
the `rust_prost_library` and `rust_tonic_library` rules which generate Rust code using the [`prost`]
8-
and [`tonic`] dependencies respectively.
7+
the `rust_prost_library` which generates Rust code using the [`prost`] and [`tonic`] dependencies.
98

109
[rust]: http://www.rust-lang.org/
1110
[protobuf]: https://developers.google.com/protocol-buffers/

docs/symbols.bzl

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ load(
3232
_rust_grpc_library = "rust_grpc_library",
3333
_rust_prost_library = "rust_prost_library",
3434
_rust_proto_library = "rust_proto_library",
35-
_rust_tonic_library = "rust_tonic_library",
3635
)
3736
load(
3837
"@rules_rust//proto:repositories.bzl",
@@ -127,7 +126,6 @@ rust_doc_test = _rust_doc_test
127126
rust_proto_library = _rust_proto_library
128127
rust_grpc_library = _rust_grpc_library
129128
rust_prost_library = _rust_prost_library
130-
rust_tonic_library = _rust_tonic_library
131129

132130
rust_bindgen = _rust_bindgen
133131
rust_bindgen_dependencies = _rust_bindgen_dependencies

proto/defs.bzl

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
load(
44
"//proto/prost:defs.bzl",
55
_rust_prost_library = "rust_prost_library",
6-
_rust_tonic_library = "rust_tonic_library",
76
)
87
load(
98
":proto.bzl",
@@ -15,4 +14,3 @@ rust_proto_library = _rust_proto_library
1514
rust_grpc_library = _rust_grpc_library
1615

1716
rust_prost_library = _rust_prost_library
18-
rust_tonic_library = _rust_tonic_library

proto/prost/defs.bzl

-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ load(
44
"//proto/prost/private:prost.bzl",
55
_rust_prost_library = "rust_prost_library",
66
_rust_prost_toolchain = "rust_prost_toolchain",
7-
_rust_tonic_library = "rust_tonic_library",
87
)
98

109
def rust_prost_library(name, **kwargs):
@@ -30,27 +29,4 @@ def rust_prost_library(name, **kwargs):
3029
**kwargs
3130
)
3231

33-
def rust_tonic_library(name, **kwargs):
34-
"""A rule for generating a Rust library using Prost and Tonic.
35-
36-
Args:
37-
name (str): The name of the target.
38-
**kwargs (dict): Additional keyword arguments for the underlying
39-
`rust_tonic_library` rule.
40-
"""
41-
42-
# Clippy and Rustfmt will attempt to run on these targets.
43-
# This is not correct and likely a bug in target detection.
44-
tags = kwargs.pop("tags", [])
45-
if "no-clippy" not in tags:
46-
tags.append("no-clippy")
47-
if "no-rustfmt" not in tags:
48-
tags.append("no-rustfmt")
49-
50-
_rust_tonic_library(
51-
name = name,
52-
tags = tags,
53-
**kwargs
54-
)
55-
5632
rust_prost_toolchain = _rust_prost_toolchain

0 commit comments

Comments
 (0)