Skip to content

Commit 3dd2b44

Browse files
committed
- Implements Basic support for python.
- Implements general 'protoc_compile' rule, clearing out redundant rule implementations. - Load import sorting. - Significant code cleanup. - Eliminate old genrule cruft. - Improved documentation.
1 parent 3cdf80e commit 3dd2b44

File tree

26 files changed

+749
-767
lines changed

26 files changed

+749
-767
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Require these rules your `WORKSPACE`:
6363
git_repository(
6464
name = "org_pubref_rules_protobuf",
6565
remote = "https://github.com/pubref/rules_protobuf",
66-
tag = "v0.4.0",
66+
tag = "v0.5.0",
6767
)
6868
```
6969

@@ -91,8 +91,9 @@ load("@org_pubref_rules_protobuf//bzl:java/rules.bzl", "java_proto_library")
9191

9292
java_proto_library(
9393
name = "protolib",
94-
srcs = ["my.proto"],
94+
protos = ["my.proto"],
9595
with_grpc = True,
96+
verbose = 1, # 0=no output, 1=show protoc command, 2+ more...
9697
)
9798
```
9899

@@ -144,8 +145,15 @@ protobuf_repositories(
144145
)
145146
```
146147

148+
# Proto B --> Proto A dependencies
147149

148-
# Imports
150+
Use the `proto_deps` attribute to name proto rule dependencies. The
151+
implementation of the dependent rule `B` should match that of the
152+
dependee `A`. This relationship is shown in the examples folder of
153+
this repo. Use of `proto_deps` implies you're using imports, so read
154+
on...
155+
156+
## Imports
149157

150158
In all cases, these rules will include a `--proto_path=.` argument.
151159
This is functionally equivalent to `--proto_path=$(bazel info
@@ -194,7 +202,7 @@ answer are:
194202
```python
195203
java_proto_library(
196204
name = 'fooprotos',
197-
srcs = 'foo.proto`,
205+
protos = 'foo.proto`,
198206
imports = [
199207
"external/com_github_google_protobuf/src/",
200208
],
@@ -206,16 +214,17 @@ that the file
206214
`@com_github_google_protobuf/src/google/protobuf/descriptor.proto` is
207215
in the package `google.protobuf`.
208216

209-
2. *Can the `cc_proto_library` rule "see" the generated protobuf files*
210-
(in this case `descriptor.pb.{h,cc}`. Just because the file was
211-
imported does not imply that protoc will generate outputs for it,
212-
so somewhere in the `cc_library` rule dependency chain these files
213-
must be present. This could be via another `cc_proto_library` rule
214-
defined elswhere, or a some other filegroup or label list. If the
215-
source is another `cc_proto_library` rule, specify that in the
216-
`deps` attribute to the calling `cc_proto_library` rule.
217-
Otherwise, pass it to the `cc_srcs` or perhaps `cc_deps` attribute
218-
to the calling `cc_proto_library` rule. Hopefully that made sense.
217+
2. *Can the `cc_proto_library` rule "see" the generated protobuf
218+
files* (in this case `descriptor.pb.{h,cc}`. Just because the file
219+
was imported does not imply that protoc will generate outputs for
220+
it, so somewhere in the `cc_library` rule dependency chain these
221+
files must be present. This could be via another
222+
`cc_proto_library` rule defined elswhere, or a some other filegroup
223+
or label list. If the source is another `cc_proto_library` rule,
224+
specify that in the `proto_deps` attribute to the calling
225+
`cc_proto_library` rule. Otherwise, pass a label that includes the
226+
(pregenerated) protobuf files to the `deps` attribute, just as you
227+
would any typical `cc_library` rule.Hopefully that made sense.
219228
It's tricky.
220229

221230
# Contributing

bzl/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
The `bzl/` directory contains bazel skylark code that implements
2+
protocol buffer generation for the supported languages. This file
3+
lists attributes and behavior that is shared across all languages.
4+
5+
# `*_proto_compile` attributes
6+
7+
| Name | Type | Description | Default |
8+
9+
| `name` | `string` | The name of the rule (required) | `""` |
10+
11+
| `protos` | `label_list` of file type `.proto` | The set of protobuf source files to compile. Must not be empty. | `[]` |
12+
13+
| `proto_deps` | `label_list` having provider `proto` | A list of `*_proto_library` that the calling rule is dependent upon. | `[]` |
14+
15+
| `protoc` | executable `label` | Used to override the default protoc binary tool. | `//external:protoc` |
16+
17+
| `gen_{LANG}` | `boolean` | Enable/disable protobuf output on a language-specific basis. | Usually `True` |
18+
19+
| `gen_{LANG}_grpc` | `boolean` | Enable/disable gRPC output on a language-specific basis. | `False` |
20+
21+
| `gen_{LANG}_protobuf_binary` | executable `label` | Use to override the plugin executable on a language-specific basis. This attribute will not exist if this the language does not require a plugin for it. | *Implementation-specific* |
22+
23+
| `gen_{LANG}_protobuf_options` | `string_list` | Additional options to be bundled into to the `--{LANG}_out` argument. | `[]` |
24+
25+
| `gen_{LANG}_grpc_binary` | executable `label` | Use to override the grpc plugin executable on a language-specific basis. This attribute will not exist if this the language does support or require a plugin for this. | *Implementation-specific* |
26+
27+
| `gen_{LANG}_grpc_options` | `string_list` | Additional options to be bundled into to the `--grpc-{LANG}_out` argument. | `[]` |
28+
29+
| `outs` | `output_list` | Permits language implementation to specify additional implicit output targets. Currently only used by the java implementations which expose `%{name}.srcjar` as an implicit handle to the generated sourcefiles.` | `{}` |
30+
31+
| `output_to_workspace` | `boolean` | Under normal operation, generated code is placed in the bazel sandbox and does not need to be checked in into version control. However, your requirements may be such that is necessary to check these generated files in. Setting this flag to `True` will emit generated `*.pb.*` files into in your workspace alongside the `*.proto` source files. Please make sure you're sure you want to do this as it has the potential for unwanted overwrite of source files. | `False` |
32+
33+
34+
# `*_proto_library` attributes
35+
36+
The attributes `protoc`, `protos`, `proto_deps`, `imports`,
37+
`output_to_workspace`, `verbose`, `with_grpc` are included in all
38+
`*_proto_library` rules, as described above.
39+
40+
| Name | Type | Description | Default |
41+
42+
| `name` | `string` | The name of the library rule (required). The implicit output target `%{name}.pb` refers to the corresponding proto_compile rule. | `""` |
43+
| `proto_args` | `dict` | A dictionary of arguments to be passed to the `*_proto_compile` implementation. | `{}` |
44+
| `srcs` | `label_list` of file type specific to library rule | Additional source files passed to the implementing library rule (for example, `cc_library` | `[]` |
45+
| `deps` | `label_list` having provider specific to library rule | Additional dependencies passed to the implementing library rule (for example, `cc_library` | `[]` |
46+
| `**kwargs` | `dict` | Additional extra arguments will be passed directly to the library rule implementation (for example, `cc_library` | `{}` |

0 commit comments

Comments
 (0)