Skip to content

Commit 06c0e69

Browse files
committed
Update proto compiler toolchainization in README
Incorporates additional insights and configuration requirements for using `rules_scala`'s protocol compiler toolchainization.
1 parent 2cc37a8 commit 06c0e69

File tree

1 file changed

+72
-12
lines changed

1 file changed

+72
-12
lines changed

README.md

+72-12
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,16 @@ load(
193193
with the `MODULE.bazel` or `WORKSPACE` configurations below, `rules_scala` will
194194
use a precompiled protocol compiler binary by default.
195195

196-
To set the flag in your `.bazelrc` file:
197-
198196
[`--incompatible_enable_proto_toolchain_resolution`]: https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
199197

198+
__Windows builds now require the precompiled protocol compiler toolchain.__ See
199+
the [Windows MSVC builds of protobuf broken by default](#protoc-msvc) section
200+
below for details.
201+
202+
#### Common setup
203+
204+
To set the flag in your `.bazelrc` file:
205+
200206
```txt
201207
common --incompatible_enable_proto_toolchain_resolution
202208
```
@@ -210,8 +216,61 @@ other toolchain registrations. It's safe to include even when not using
210216
register_toolchains("@rules_scala//protoc:all")
211217
```
212218

213-
`WORKSPACE` must include the `host_platform_repo` snippet from [Getting
214-
started](#getting-started):
219+
#### Temporary required `protobuf` patch
220+
221+
As of `protobuf` v29.3, enabling protocol compiler toolchainization requires
222+
applying [protoc/0001-protobuf-19679-rm-protoc-dep.patch][]. It is the `git
223+
diff` output from the branch used to create protocolbuffers/protobuf#19679.
224+
Without it, there remains a transitive dependency on
225+
`@com_google_protobuf//:protoc`, causing it to recompile even with the
226+
precompiled toolchain registered first.
227+
228+
[protoc/0001-protobuf-19679-rm-protoc-dep.patch]: ./protoc/0001-protobuf-19679-rm-protoc-dep.patch
229+
230+
If and when `protobuf` merges that pull request, or applies an equivalent fix,
231+
this patch will no longer be necessary.
232+
233+
#### Bzlmod setup
234+
235+
Applying the `protobuf` patch requires using [`single_version_override`][],
236+
which also requires that the patch be a regular file in your own repo. In other
237+
words, neither `@rules_scala//protoc:0001-protobuf-19679-rm-protoc-dep.patch`
238+
nor an [`alias`][] to it will work.
239+
240+
[`single_version_override`]: https://bazel.build/rules/lib/globals/module#single_version_override
241+
[`alias`]: https://bazel.build/reference/be/general#alias
242+
243+
Assuming you've copied the patch to a file called `protobuf.patch` in the root
244+
package of your repository, add the following to your `MODULE.bazel`:
245+
246+
```py
247+
# MODULE.bazel
248+
249+
# Required for protocol compiler toolchainization until resolution of
250+
# protocolbuffers/protobuf#19679.
251+
bazel_dep(
252+
name = "protobuf",
253+
version = "29.3",
254+
repo_name = "com_google_protobuf",
255+
)
256+
257+
single_version_override(
258+
module_name = "protobuf",
259+
version = "29.3",
260+
patches = ["//:protobuf.patch"],
261+
patch_strip = 1,
262+
)
263+
```
264+
265+
#### `WORKSPACE` setup
266+
267+
[`scala/deps.bzl`](./scala/deps.bzl) already applies the `protobuf` patch by
268+
default. If you need to apply it yourself, you can also copy it to your repo as
269+
described in the Bzlmod setup above. Then follow the example in `scala/deps.bzl`
270+
to apply it in your own `http_archive` call.
271+
272+
However, `WORKSPACE` must include the `host_platform_repo` snippet from
273+
[Getting started](#getting-started) to work around bazelbuild/bazel#22558:
215274

216275
```py
217276
# WORKSPACE
@@ -222,11 +281,7 @@ load("@platforms//host:extension.bzl", "host_platform_repo")
222281
host_platform_repo(name = "host_platform")
223282
```
224283

225-
__Windows builds now require the precompiled protocol compiler toolchain.__ See
226-
the [Windows MSVC builds of protobuf broken by default](#protoc-msvc) section
227-
below for details.
228-
229-
More background on proto toolchainization:
284+
#### More background on proto toolchainization
230285

231286
- [Proto Toolchainisation Design Doc](
232287
https://docs.google.com/document/d/1CE6wJHNfKbUPBr7-mmk_0Yo3a4TaqcTPE0OWNuQkhPs/edit)
@@ -819,9 +874,14 @@ with Bazel 6.5.0 won't work at all because [Bazel 6.5.0 doesn't support
819874
https://github.com/bazelbuild/rules_scala/issues/1482#issuecomment-2515496234).
820875

821876
At the moment, `WORKSPACE` builds mostly continue to work with Bazel 6.5.0, but
822-
not out of the box, and may break at any time. Per bazelbuild/rules_scala#1647,
823-
such builds require adding the following flags to `.bazelrc`, required by the
824-
newer `abseil-cpp` version used by `protobuf`:
877+
not out of the box, and may break at any time. You will have to choose one of
878+
the following approaches to resolve `protobuf` compatibility issues.
879+
880+
First, you may choose to use protocol compiler toolchainization. See the [Using
881+
a precompiled protocol compiler](#protoc) section for details.
882+
883+
Otherwise, per bazelbuild/rules_scala#1647, you must add the following flags to
884+
`.bazelrc`, required by the newer `abseil-cpp` version used by `protobuf`:
825885

826886
```txt
827887
common --enable_platform_specific_config

0 commit comments

Comments
 (0)