@@ -76,7 +76,7 @@ host_platform_repo(name = "host_platform")
7676
7777# This is optional, but still safe to include even when not using
7878# `--incompatible_enable_proto_toolchain_resolution`. Requires calling
79- # `scala_toolchains ()`.
79+ # `scala_protoc_toolchains ()` as seen below .
8080register_toolchains(" @rules_scala//protoc:all" )
8181
8282load(" @rules_java//java:rules_java_deps.bzl" , " rules_java_dependencies" )
@@ -125,6 +125,13 @@ load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
125125
126126rules_proto_toolchains()
127127
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+
128135load(" @rules_scala//:scala_config.bzl" , " scala_config" )
129136
130137# 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
226233register_toolchains(" @rules_scala//protoc:all" )
227234```
228235
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+ ```
232263
233264#### Specifying additional ` protoc ` platforms
234265
235- Use the ` protoc_platforms ` parameter to specify additional [ platforms] [ ] if the
266+ Use the ` platforms ` parameter to specify additional [ platforms] [ ] if the
236267execution platform may differ from the host platform, as when building with
237268remote execution. Valid values come from the file name suffixes of
238269[ 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.
249280``` py
250281# MODULE.bazel
251282
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" ],
258285)
259286```
260287
@@ -263,13 +290,8 @@ In `WORKSPACE` you would include:
263290``` py
264291# WORKSPACE
265292
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" ],
273295)
274296```
275297
@@ -936,19 +958,15 @@ builds by avoiding `@com_google_protobuf//:protoc` recompilation.
936958
937959### Minimum of ` protobuf ` v28
938960
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.
943964
944965#### Using earlier ` protobuf ` versions
945966
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.
952970
953971| Dependency | Max compatible version | Reason |
954972| :-: | :-: | :- |
@@ -1114,8 +1132,8 @@ flags][protoc-opts] for protocol compiler configuration requirements.
11141132
11151133#### Using older versions of ` protobuf `
11161134
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 .
11191137
11201138### ` scala_proto ` not supported for Scala 2.11
11211139
0 commit comments