@@ -76,7 +76,7 @@ host_platform_repo(name = "host_platform")
76
76
77
77
# This is optional, but still safe to include even when not using
78
78
# `--incompatible_enable_proto_toolchain_resolution`. Requires calling
79
- # `scala_toolchains ()`.
79
+ # `scala_protoc_toolchains ()` as seen below .
80
80
register_toolchains(" @rules_scala//protoc:all" )
81
81
82
82
load(" @rules_java//java:rules_java_deps.bzl" , " rules_java_dependencies" )
@@ -125,6 +125,13 @@ load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
125
125
126
126
rules_proto_toolchains()
127
127
128
+ # Include this after loading `platforms` and `com_google_protobuf` to enable the
129
+ # `//protoc` precompiled protocol compiler toolchains. See the "Using a
130
+ # precompiled protocol compiler" section below.
131
+ load(" @rules_scala//protoc:toolchains.bzl" , " scala_protoc_toolchains" )
132
+
133
+ scala_protoc_toolchains()
134
+
128
135
load(" @rules_scala//:scala_config.bzl" , " scala_config" )
129
136
130
137
# Stores the selected Scala version and other configuration parameters.
@@ -226,13 +233,37 @@ other toolchain registrations. It's safe to include even when not using
226
233
register_toolchains(" @rules_scala//protoc:all" )
227
234
```
228
235
229
- Note that you _ must_ call ` scala_toolchains() ` in ` WORKSPACE ` , even if all other
230
- toolchains are disabled (i.e., if using ` scala_toolchains(scala = False) ` ). This
231
- isn't necessary under Bzlmod.
236
+ #### Using ` scala_protoc ` in ` MODULE.bazel `
237
+
238
+ The ` scala_protoc ` extension instantiates the protocol compiler toolchain
239
+ binaries under Bzlmod:
240
+
241
+ ``` py
242
+ # MODULE.bazel
243
+
244
+ scala_protoc = use_extension(
245
+ " @rules_scala//scala/extensions:protoc.bzl" ,
246
+ " scala_protoc" ,
247
+ )
248
+ ```
249
+
250
+ #### Calling ` scala_protoc_toolchains() ` in ` WORKSPACE `
251
+
252
+ The ` scala_protoc_toolchains ` macro instantiates the protocol compiler toolchain
253
+ binaries under ` WORKSPACE ` :
254
+
255
+ ``` py
256
+ # WORKSPACE
257
+
258
+ # Include this after loading `platforms` and `com_google_protobuf`.
259
+ load(" @rules_scala//protoc:toolchains.bzl" , " scala_protoc_toolchains" )
260
+
261
+ scala_protoc_toolchains()
262
+ ```
232
263
233
264
#### Specifying additional ` protoc ` platforms
234
265
235
- Use the ` protoc_platforms ` parameter to specify additional [ platforms] [ ] if the
266
+ Use the ` platforms ` parameter to specify additional [ platforms] [ ] if the
236
267
execution platform may differ from the host platform, as when building with
237
268
remote execution. Valid values come from the file name suffixes of
238
269
[ protocolbuffers/protobuf releases] [ ] . It's also safe to explicitly include the
@@ -249,12 +280,8 @@ the remote execution platform is Linux running on an x86 processor.
249
280
``` py
250
281
# MODULE.bazel
251
282
252
- scala_deps = use_extension(
253
- " @rules_scala//scala/extensions:deps.bzl" ,
254
- " scala_deps" ,
255
- )
256
- scala_deps.toolchains(
257
- protoc_platforms = [" linux-x86_64" ],
283
+ scala_protoc.toolchains(
284
+ platforms = [" linux-x86_64" ],
258
285
)
259
286
```
260
287
@@ -263,13 +290,8 @@ In `WORKSPACE` you would include:
263
290
``` py
264
291
# WORKSPACE
265
292
266
- load(
267
- " @rules_scala//scala:toolchains.bzl" ,
268
- " scala_toolchains" ,
269
- )
270
-
271
- scala_toolchains(
272
- protoc_platforms = [" linux-x86_64" ],
293
+ scala_protoc_toolchains(
294
+ platforms = [" linux-x86_64" ],
273
295
)
274
296
```
275
297
@@ -936,19 +958,15 @@ builds by avoiding `@com_google_protobuf//:protoc` recompilation.
936
958
937
959
### Minimum of ` protobuf ` v28
938
960
939
- ` rules_scala ` requires at least ` protobuf ` v28, which contains the
940
- ` bazel/common/proto_common.bzl ` required for [ protocol compiler
941
- toolchain] ( #protoc ) support. This file appeared in v27, and no ` ScalaPB ` release
942
- supports ` protobuf ` v25.6, v26, or v27.
961
+ ` rules_scala ` requires at least ` protobuf ` v28, and at least v29 for [ protocol
962
+ compiler toolchain] ( #protoc ) support. No ` ScalaPB ` release supports ` protobuf `
963
+ v25.6, v26, or v27.
943
964
944
965
#### Using earlier ` protobuf ` versions
945
966
946
- If you can't update to ` protobuf ` v28 or later right now, you will need to patch:
947
-
948
- - ` scala/toolchains.bzl ` : remove ` setup_protoc_toolchains() ` references
949
- - ` protoc/BUILD ` : remove entirely
950
-
951
- Then build using Bazel 7 and the following maximum versions of key dependencies:
967
+ If you can't update to ` protobuf ` v28 or later right now, build using Bazel 7
968
+ and the following maximum versions of key dependencies. This is not officially
969
+ supported, but should work for some time.
952
970
953
971
| Dependency | Max compatible version | Reason |
954
972
| :-: | :-: | :- |
@@ -1114,8 +1132,8 @@ flags][protoc-opts] for protocol compiler configuration requirements.
1114
1132
1115
1133
#### Using older versions of ` protobuf `
1116
1134
1117
- See [ Minimum of protobuf v28 ] ( #minimum-of -protobuf-v28 ) for details on using
1118
- older versions of protobuf.
1135
+ See [ Using earlier protobuf versions ] ( #using-earlier -protobuf-versions ) for
1136
+ details on using older versions of protobuf if necessary .
1119
1137
1120
1138
### ` scala_proto ` not supported for Scala 2.11
1121
1139
0 commit comments