@@ -18,17 +18,17 @@ Using Protocol Buffers with Bazel has always been difficult.
18
18
## Support matrix
19
19
20
20
Minimum versions:
21
+
21
22
- Bazel: 7.0.0
22
23
- rules_proto: 6.0.0
23
24
24
- | Language | Support | Example or Issue |
25
- | ---------- | ---------| ------------------|
26
- | Java | Yes | [ example] ( ./examples/java ) |
25
+ | Language | Support | Example or Issue |
26
+ | -------- | ------- | ---------------------------- |
27
+ | Java | Yes | [ example] ( ./examples/java ) |
27
28
| Python | Yes | [ example] ( ./examples/python ) |
28
- | Rust | | https://github.com/bazelbuild/rules_rust/issues/2627 |
29
- | Go | | https://github.com/bazelbuild/rules_go/issues/3895 |
29
+ | Go | Yes | [ example] ( ./examples/go ) |
30
30
31
- Your language missing? Please file the upstream issue and send a PR to update this table!
31
+ For all other languages, see https://github.com/bazelbuild/rules_proto/discussions/213
32
32
33
33
## Installation
34
34
@@ -56,43 +56,33 @@ using whatever Bazel rule you chose for interacting with package managers
56
56
- JavaScript: https://www.npmjs.com/package/protobufjs
57
57
- Go: https://pkg.go.dev/google.golang.org/protobuf/runtime
58
58
59
- Second, declare the toolchain in a ` BUILD ` file. It looks like the following
60
- (where ` LANG ` , ` --flag_to_protoc ` , and ` runtime ` are replaced
59
+ For rulesets that need a "lang toolchain", declare one in a ` BUILD ` file.
60
+ It looks like the following (where ` LANG ` , ` --flag_to_protoc ` , and ` runtime ` are replaced
61
61
with appropriate values for the language and the label of the runtime you installed).
62
62
63
- You can choose a Bazel package where this goes; we recommend ` /tools/protoc /BUILD.bazel ` .
63
+ You can choose a Bazel package where this goes; we recommend ` /tools/toolchains /BUILD.bazel ` .
64
64
65
65
``` starlark
66
66
load(" @rules_proto//proto:defs.bzl" , " proto_lang_toolchain" )
67
+
67
68
proto_lang_toolchain(
68
69
name = " protoc_LANG_toolchain" ,
69
70
command_line = " --flag_to_protoc=%s " ,
70
71
progress_message = " Generating LANG proto_library %{label} " ,
71
72
runtime = " @some-external//lib" ,
72
- )
73
- ```
74
-
75
- Finally, in the same ` BUILD ` file, declare the registration target...
76
-
77
- ``` starlark
78
- toolchain(
79
- name = " protoc_LANG_toolchain.registration" ,
80
- toolchain = " :protoc_LANG_toolchain" ,
81
- # This type should be declared by the language rules:
73
+ # This target should be declared by the language rules:
82
74
toolchain_type = " @rules_LANG//path/to/proto:toolchain_type" ,
83
75
)
84
76
```
85
77
86
- ...and then register it , either in ` MODULE.bazel ` or ` WORKSPACE ` :
78
+ Then register the toolchains , either in ` MODULE.bazel ` or ` WORKSPACE ` :
87
79
88
80
``` starlark
89
- register_toolchains(" //tools/protoc :all" )
81
+ register_toolchains(" //tools/toolchains :all" )
90
82
```
91
83
92
84
See ` examples ` for several language rules like ` py_proto_library ` and ` java_proto_library ` .
93
85
94
- Note that there is NO dependency on ` @com_google_protobuf ` anywhere.
95
-
96
86
### Troubleshooting
97
87
98
88
What if you still see that protoc is compiling? This means that there is still a transitive dependency on the
@@ -110,7 +100,7 @@ What if you still see that protoc is compiling? This means that there is still a
110
100
1 . That distribution includes the "well known types" such as ` timestamp.proto `
111
101
1 . The protobuf runtimes for each language are distributed to the appropriate package manager such as npm or PyPI.
112
102
1 . Bazel 7 introduced ` --incompatible_enable_proto_toolchain_resolution ` to allow us fetch ` protoc ` rather than re-build it!
113
- That flag ALSO decouples how each built-in language rule (Java, Python, C++, etc.) locates the runtime.
103
+ That flag ALSO decouples how each built-in language rule (Java, Python, C++, etc.) locates the runtime.
114
104
115
105
Thanks to that flag, this repo simply contains a toolchain that resolves those pre-built binaries.
116
106
In the user's repository, there's a small BUILD file where the toolchain is configured.
0 commit comments