@@ -193,10 +193,16 @@ load(
193
193
with the ` MODULE.bazel ` or ` WORKSPACE ` configurations below, ` rules_scala ` will
194
194
use a precompiled protocol compiler binary by default.
195
195
196
- To set the flag in your ` .bazelrc ` file:
197
-
198
196
[ `--incompatible_enable_proto_toolchain_resolution` ] : https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
199
197
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
+
200
206
``` txt
201
207
common --incompatible_enable_proto_toolchain_resolution
202
208
```
@@ -210,8 +216,61 @@ other toolchain registrations. It's safe to include even when not using
210
216
register_toolchains(" @rules_scala//protoc:all" )
211
217
```
212
218
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 :
215
274
216
275
``` py
217
276
# WORKSPACE
@@ -222,11 +281,7 @@ load("@platforms//host:extension.bzl", "host_platform_repo")
222
281
host_platform_repo(name = " host_platform" )
223
282
```
224
283
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
230
285
231
286
- [ Proto Toolchainisation Design Doc] (
232
287
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
819
874
https://github.com/bazelbuild/rules_scala/issues/1482#issuecomment-2515496234 ).
820
875
821
876
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 ` :
825
885
826
886
``` txt
827
887
common --enable_platform_specific_config
0 commit comments