@@ -75,9 +75,10 @@ load("@platforms//host:extension.bzl", "host_platform_repo")
75
75
host_platform_repo(name = " host_platform" )
76
76
77
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" )
78
+ # `--incompatible_enable_proto_toolchain_resolution`. Requires invoking the
79
+ # `scala_protoc_toolchains` repo rule. Register this toolchain before any
80
+ # others. See the "Using a precompiled protocol compiler" section below.
81
+ register_toolchains(" @rules_scala_protoc_toolchains//...:all" )
81
82
82
83
load(" @rules_java//java:rules_java_deps.bzl" , " rules_java_dependencies" )
83
84
@@ -125,12 +126,13 @@ load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
125
126
126
127
rules_proto_toolchains()
127
128
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.
131
132
load(" @rules_scala//protoc:toolchains.bzl" , " scala_protoc_toolchains" )
132
133
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" )
134
136
135
137
load(" @rules_scala//:scala_config.bzl" , " scala_config" )
136
138
@@ -224,41 +226,57 @@ To set the flag in your `.bazelrc` file:
224
226
common --incompatible_enable_proto_toolchain_resolution
225
227
```
226
228
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 ` , add the following ` register_toolchains `
230
+ statement _ before_ any other toolchain registrations. It's safe to include even
231
+ when not using ` --incompatible_enable_proto_toolchain_resolution ` .
232
+
233
+ The repository name of the target is determined by the
234
+ ` scala_protoc_toolchains() ` repo rule invocation, as illustrated below. It is OK
235
+ to call ` register_toolchains ` before the repo rule.
230
236
231
237
``` 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" )
234
246
```
235
247
236
- #### Using ` scala_protoc ` in ` MODULE.bazel `
248
+ #### Invoking the ` scala_protoc_toolchains() ` repo rule
237
249
238
- The ` scala_protoc ` extension instantiates the protocol compiler toolchain
239
- binaries under Bzlmod:
250
+ The ` scala_protoc_toolchains ` repo rule instantiates the protocol compiler
251
+ toolchain. The repo name can be anything, but we recommend ` rules_scala_protoc_toolchains ` .
252
+
253
+ Under Bzlmod, this looks like:
240
254
241
255
``` py
242
256
# MODULE.bazel
243
257
244
- scala_protoc = use_extension (
245
- " @rules_scala//scala/extensions: protoc.bzl" ,
246
- " scala_protoc " ,
258
+ scala_protoc_toolchains = use_repo_rule (
259
+ " @rules_scala//protoc:toolchains .bzl" ,
260
+ " scala_protoc_toolchains " ,
247
261
)
248
- ```
249
262
250
- #### Calling ` scala_protoc_toolchains() ` in ` WORKSPACE `
263
+ # This name can be anything, but we recommend `rules_scala_protoc_toolchains`.
264
+ scala_protoc_toolchains(
265
+ name = " rules_scala_protoc_toolchains" ,
266
+ dev_dependency = True ,
267
+ )
268
+ ```
251
269
252
- The ` scala_protoc_toolchains ` macro instantiates the protocol compiler toolchain
253
- binaries under ` WORKSPACE ` :
270
+ Under ` WORKSPACE ` , this looks like:
254
271
255
272
``` py
256
273
# WORKSPACE
257
274
258
- # Include this after loading `platforms` and `com_google_protobuf`.
275
+ # Include this after loading `platforms`, `com_google_protobuf`, and
276
+ # `rules_proto`.
259
277
load(" @rules_scala//protoc:toolchains.bzl" , " scala_protoc_toolchains" )
260
278
261
- scala_protoc_toolchains()
279
+ scala_protoc_toolchains(name = " rules_scala_protoc_toolchains " )
262
280
```
263
281
264
282
#### Specifying additional ` protoc ` platforms
@@ -280,8 +298,10 @@ the remote execution platform is Linux running on an x86 processor.
280
298
``` py
281
299
# MODULE.bazel
282
300
283
- scala_protoc.toolchains(
301
+ scala_protoc_toolchains(
302
+ name = " rules_scala_protoc_toolchains" ,
284
303
platforms = [" linux-x86_64" ],
304
+ dev_dependency = True ,
285
305
)
286
306
```
287
307
@@ -291,6 +311,7 @@ In `WORKSPACE` you would include:
291
311
# WORKSPACE
292
312
293
313
scala_protoc_toolchains(
314
+ name = " rules_scala_protoc_toolchains" ,
294
315
platforms = [" linux-x86_64" ],
295
316
)
296
317
```
@@ -308,7 +329,7 @@ transitive dependency on `@com_google_protobuf//:protoc` remains, causing
308
329
If and when ` protobuf ` merges that pull request, or applies an equivalent fix,
309
330
this patch will no longer be necessary.
310
331
311
- #### Bzlmod setup
332
+ #### ` protobuf ` patch setup under Bzlmod
312
333
313
334
Applying the ` protobuf ` patch requires using [ ` single_version_override ` ] [ ] ,
314
335
which also requires that the patch be a regular file in your own repo. In other
@@ -339,7 +360,7 @@ single_version_override(
339
360
)
340
361
```
341
362
342
- #### ` WORKSPACE ` setup
363
+ #### ` protobuf ` patch setup under ` WORKSPACE `
343
364
344
365
[ ` scala/deps.bzl ` ] ( ./scala/deps.bzl ) already applies the ` protobuf ` patch by
345
366
default. If you need to apply it yourself, you can also copy it to your repo as
0 commit comments