@@ -74,10 +74,11 @@ load("@platforms//host:extension.bzl", "host_platform_repo")
7474# - https://github.com/bazelbuild/bazel/issues/22558
7575host_platform_repo(name = " host_platform" )
7676
77- # This is optional, but still safe to include even when not using
78- # `--incompatible_enable_proto_toolchain_resolution`. Requires calling
79- # `scala_protoc_toolchains()` as seen below.
80- register_toolchains(" @rules_scala//protoc:all" )
77+ # This is optional, but register this toolchain before any others. Requires
78+ # invoking the `scala_protoc_toolchains` repo rule, but is safe to include even
79+ # `--incompatible_enable_proto_toolchain_resolution` is `False`.
80+ # See the "Using a precompiled protocol compiler" section below.
81+ register_toolchains(" @rules_scala_protoc_toolchains//...:all" )
8182
8283load(" @rules_java//java:rules_java_deps.bzl" , " rules_java_dependencies" )
8384
@@ -125,12 +126,13 @@ load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
125126
126127rules_proto_toolchains()
127128
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.
129+ # Include this after loading `platforms`, `com_google_protobuf`, and
130+ # `rules_proto` to enable the ` //protoc` precompiled protocol compiler
131+ # toolchains. See the "Using a precompiled protocol compiler" section below.
131132load(" @rules_scala//protoc:toolchains.bzl" , " scala_protoc_toolchains" )
132133
133- scala_protoc_toolchains()
134+ # This name can be anything, but we recommend `rules_scala_protoc_toolchains`.
135+ scala_protoc_toolchains(name = " rules_scala_protoc_toolchains" )
134136
135137load(" @rules_scala//:scala_config.bzl" , " scala_config" )
136138
@@ -224,41 +226,55 @@ To set the flag in your `.bazelrc` file:
224226common --incompatible_enable_proto_toolchain_resolution
225227```
226228
227- In both ` MODULE.bazel ` and ` WORKSPACE ` , add the following statement _ before_ any
228- other toolchain registrations. It's safe to include even when not using
229- ` --incompatible_enable_proto_toolchain_resolution ` .
229+ In both ` MODULE.bazel ` and ` WORKSPACE ` , you must register the protocol compiler
230+ toolchains _ before_ any other toolchains. It's safe to use even when
231+ ` --incompatible_enable_proto_toolchain_resolution ` is ` False ` .
232+
233+ It is OK to call ` register_toolchains ` before using the ` scala_protoc ` extension
234+ under Bzlmod, and before the ` scala_protoc_toolchains() ` repo rule under
235+ ` WORKSPACE ` .
230236
231237``` py
232- # MODULE.bazel or WORKSPACE
233- register_toolchains(" @rules_scala//protoc:all" )
238+ # MODULE.bazel
239+ register_toolchains(
240+ " @rules_scala_protoc_toolchains//...:all" ,
241+ dev_dependency = True ,
242+ )
243+
244+ # WORKSPACE
245+ register_toolchains(" @rules_scala_protoc_toolchains//...:all" )
234246```
235247
236- #### Using ` scala_protoc ` in ` MODULE.bazel `
248+ #### Using the ` scala_protoc ` module extension under Bzlmod
237249
238- The ` scala_protoc ` extension instantiates the protocol compiler toolchain
239- binaries under Bzlmod:
250+ The ` scala_protoc ` module extension instantiates the protocol compiler
251+ toolchain under Bzlmod. It _ must _ be marked as a ` dev_dependency ` .
240252
241253``` py
242254# MODULE.bazel
243255
244256scala_protoc = use_extension(
245257 " @rules_scala//scala/extensions:protoc.bzl" ,
246258 " scala_protoc" ,
259+ dev_dependency = True ,
247260)
261+ use_repo(scala_protoc, " rules_scala_protoc_toolchains" )
248262```
249263
250- #### Calling ` scala_protoc_toolchains() ` in ` WORKSPACE `
264+ #### Invoking the ` scala_protoc_toolchains() ` repo rule under ` WORKSPACE `
251265
252- The ` scala_protoc_toolchains ` macro instantiates the protocol compiler toolchain
253- binaries under ` WORKSPACE ` :
266+ The ` scala_protoc_toolchains ` repo rule instantiates the protocol compiler
267+ toolchain. The repo name can be anything, but we recommend
268+ ` rules_scala_protoc_toolchains ` .
254269
255270``` py
256271# WORKSPACE
257272
258- # Include this after loading `platforms` and `com_google_protobuf`.
273+ # Include this after loading `platforms`, `com_google_protobuf`, and
274+ # `rules_proto`.
259275load(" @rules_scala//protoc:toolchains.bzl" , " scala_protoc_toolchains" )
260276
261- scala_protoc_toolchains()
277+ scala_protoc_toolchains(name = " rules_scala_protoc_toolchains " )
262278```
263279
264280#### Specifying additional ` protoc ` platforms
@@ -280,8 +296,10 @@ the remote execution platform is Linux running on an x86 processor.
280296``` py
281297# MODULE.bazel
282298
283- scala_protoc.toolchains(
299+ scala_protoc_toolchains(
300+ name = " rules_scala_protoc_toolchains" ,
284301 platforms = [" linux-x86_64" ],
302+ dev_dependency = True ,
285303)
286304```
287305
@@ -291,6 +309,7 @@ In `WORKSPACE` you would include:
291309# WORKSPACE
292310
293311scala_protoc_toolchains(
312+ name = " rules_scala_protoc_toolchains" ,
294313 platforms = [" linux-x86_64" ],
295314)
296315```
@@ -308,7 +327,7 @@ transitive dependency on `@com_google_protobuf//:protoc` remains, causing
308327If and when ` protobuf ` merges that pull request, or applies an equivalent fix,
309328this patch will no longer be necessary.
310329
311- #### Bzlmod setup
330+ #### ` protobuf ` patch setup under Bzlmod
312331
313332Applying the ` protobuf ` patch requires using [ ` single_version_override ` ] [ ] ,
314333which also requires that the patch be a regular file in your own repo. In other
@@ -339,7 +358,7 @@ single_version_override(
339358)
340359```
341360
342- #### ` WORKSPACE ` setup
361+ #### ` protobuf ` patch setup under ` WORKSPACE `
343362
344363[ ` scala/deps.bzl ` ] ( ./scala/deps.bzl ) already applies the ` protobuf ` patch by
345364default. If you need to apply it yourself, you can also copy it to your repo as
0 commit comments