@@ -18,17 +18,17 @@ Using Protocol Buffers with Bazel has always been difficult.
1818## Support matrix
1919
2020Minimum versions:
21+
2122- Bazel: 7.0.0
2223- rules_proto: 6.0.0
2324
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 ) |
2728| 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 ) |
3030
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
3232
3333## Installation
3434
@@ -56,43 +56,33 @@ using whatever Bazel rule you chose for interacting with package managers
5656- JavaScript: https://www.npmjs.com/package/protobufjs
5757- Go: https://pkg.go.dev/google.golang.org/protobuf/runtime
5858
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
6161with appropriate values for the language and the label of the runtime you installed).
6262
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 ` .
6464
6565``` starlark
6666load(" @rules_proto//proto:defs.bzl" , " proto_lang_toolchain" )
67+
6768proto_lang_toolchain(
6869 name = " protoc_LANG_toolchain" ,
6970 command_line = " --flag_to_protoc=%s " ,
7071 progress_message = " Generating LANG proto_library %{label} " ,
7172 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:
8274 toolchain_type = " @rules_LANG//path/to/proto:toolchain_type" ,
8375)
8476```
8577
86- ...and then register it , either in ` MODULE.bazel ` or ` WORKSPACE ` :
78+ Then register the toolchains , either in ` MODULE.bazel ` or ` WORKSPACE ` :
8779
8880``` starlark
89- register_toolchains(" //tools/protoc :all" )
81+ register_toolchains(" //tools/toolchains :all" )
9082```
9183
9284See ` examples ` for several language rules like ` py_proto_library ` and ` java_proto_library ` .
9385
94- Note that there is NO dependency on ` @com_google_protobuf ` anywhere.
95-
9686### Troubleshooting
9787
9888What 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
1101001 . That distribution includes the "well known types" such as ` timestamp.proto `
1111011 . The protobuf runtimes for each language are distributed to the appropriate package manager such as npm or PyPI.
1121021 . 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.
114104
115105Thanks to that flag, this repo simply contains a toolchain that resolves those pre-built binaries.
116106In the user's repository, there's a small BUILD file where the toolchain is configured.
0 commit comments