@@ -47,8 +47,12 @@ the following dependency versions, make sure to `load()` them before calling
47
47
48
48
As of version 7.0.0, __ ` rules_scala ` no longer requires the
49
49
` io_bazel_rules_scala ` repository name__ unless your ` BUILD ` files or those of
50
- your dependencies require it (bazelbuild/rules_scala #1696 ). In that case, the
51
- old name will still work when using ` http_archive ` .
50
+ your dependencies require it (bazelbuild/rules_scala #1696 ).
51
+
52
+ Note that __ ` rules_scala ` 7 introduces a new ` scala_toolchains() ` API that is
53
+ very different from ` rules_scala ` 6__ . For details on what's changed, see the
54
+ [ New ` scala_toolchains() ` API for ` WORKSPACE ` ] ( #new-toolchains-api ) section
55
+ below.
52
56
53
57
``` py
54
58
# WORKSPACE
@@ -57,7 +61,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
57
61
# See https://github.com/bazelbuild/rules_scala/releases for up to date version
58
62
# information, including `<SHASUM>` values.
59
63
http_archive(
60
- name = " rules_scala" ,
64
+ name = " rules_scala" , # Can be "io_bazel_rules_scala" if you still need it.
61
65
sha256 = " <SHASUM>" ,
62
66
strip_prefix = " rules_scala-7.0.0" ,
63
67
url = " https://github.com/bazelbuild/rules_scala/releases/download/7.0.0/rules_scala-7.0.0.tar.gz" ,
@@ -78,7 +82,7 @@ bazel_skylib_workspace()
78
82
# If you need a specific `rules_python` version, specify it here.
79
83
# Otherwise you may get the version defined in the `com_google_protobuf` repo.
80
84
# We use 0.38.0 to maintain compatibility with Bazel 6.5.0; this will change in
81
- # the next release .
85
+ # rules_scala 8.0.0 .
82
86
http_archive(
83
87
name = " rules_python" ,
84
88
sha256 = " ca2671529884e3ecb5b79d6a5608c7373a82078c3553b1fa53206e6b9dddab34" ,
@@ -146,10 +150,9 @@ scala_toolchains(
146
150
scala_register_toolchains()
147
151
```
148
152
149
- This will load the ` rules_scala ` repository at the commit sha
150
- ` rules_scala_version ` into your Bazel project and register a [ scala_toolchain] ( docs/scala_toolchain.md ) at the default Scala version (2.12.20)
153
+ ### Loading the ` scala_* ` rules
151
154
152
- Then in your BUILD file just add the following so the rules will be available:
155
+ Add the following to your ` BUILD ` files to make the ` scala_* ` rules available:
153
156
154
157
``` py
155
158
load(
@@ -160,23 +163,19 @@ load(
160
163
)
161
164
```
162
165
163
- You may wish to have these rules loaded by default using bazel's prelude. You can add the above to the file ` tools/build_rules/prelude_bazel ` in your repo (don't forget to have a, possibly empty, BUILD file there) and then it will be automatically prepended to every BUILD file in the workspace.
166
+ ### Persistent workers
164
167
165
- To run with a persistent worker (much faster), you need to add
168
+ To run with a persistent worker (much faster), add the following to
169
+ your ` .bazelrc ` file:
166
170
167
171
``` txt
168
172
build --strategy=Scalac=worker
169
173
build --worker_sandboxing
170
174
```
171
175
172
- to your command line, or to enable by default for building/testing add it to
173
- your ` .bazelrc ` .
174
-
175
176
## Coverage support
176
177
177
- It will produce several .dat files with results for your targets.
178
-
179
- You can also add more options to receive a combined coverage report:
178
+ To produce a combined coverage report:
180
179
181
180
``` txt
182
181
bazel coverage \
@@ -211,24 +210,8 @@ Please check [coverage.md](docs/coverage.md) for more details on coverage suppor
211
210
` rules_scala ` supports the last two released minor versions for each of Scala 2.11, 2.12, 2.13.
212
211
Previous minor versions may work but are supported only on a best effort basis.
213
212
214
- First select the default Scala version by calling ` scala_config(scala_version = "2.xx.xx") ` and configure
215
- dependencies by calling [ scala_toolchains()] ( docs/scala_toolchain.md ) and ` scala_register_toolchains() ` :
216
-
217
- ``` py
218
- # WORKSPACE
219
- load(" @rules_scala//:scala_config.bzl" , " scala_config" )
220
- scala_config(scala_version = " 2.13.15" )
221
-
222
- load(
223
- " @rules_scala//scala:toolchains.bzl" ,
224
- " scala_register_toolchains" ,
225
- " scala_toolchains" ,
226
- )
227
-
228
- scala_toolchains()
229
-
230
- scala_register_toolchains()
231
- ```
213
+ The [ Getting started] ( #getting-started ) section illustrates how to select the
214
+ default Scala version and configure its dependencies.
232
215
233
216
### With custom toolchains
234
217
@@ -361,7 +344,7 @@ to Bazel 7 and Bzlmod.__ To facilitate a gradual migration, it remains
361
344
compatible with both `WORKSPACE` and Bzlmod. However, it contains the following
362
345
breaking changes when upgrading from `rules_scala` 6.x.
363
346
364
- # ## New `scala_toolchains()` API for `WORKSPACE`
347
+ # ## <a id="new-toolchains-api"></a> New `scala_toolchains()` API for `WORKSPACE`
365
348
366
349
` rules_scala` 7.0.0 replaces existing `*_repositories()` and `*_toolchains()`
367
350
macros with the combination of `rules_scala_dependencies()`,
@@ -464,16 +447,14 @@ parameter list, which is almost in complete correspondence with parameters from
464
447
the previous macros. The ` WORKSPACE ` files in this repository also provide many
465
448
examples.
466
449
467
- ### Replacing toolchain registration macros
468
-
469
- ` MODULE.bazel ` not only doesn't allow ` load() ` statements, and therefore macros,
470
- but _ all ` register_toolchains() ` calls_ __ must__ _ appear in ` MODULE.bazel ` _ .
450
+ ### Replacing toolchain registration macros in ` WORKSPACE `
471
451
472
452
Almost all ` rules_scala ` toolchains are automatically configured and registered by
473
- ` scala_toolchains() ` and ` scala_register_toolchains() ` . There are two exceptions.
453
+ ` scala_toolchains() ` and ` scala_register_toolchains() ` . There are two toolchain
454
+ macro replacements that require special handling.
474
455
475
- The first exception is ` scala_proto_register_enable_all_options_toolchain() ` .
476
- Replace this macro with :
456
+ The first is replacing ` scala_proto_register_enable_all_options_toolchain() `
457
+ with the following ` scala_toolchains() ` parameters :
477
458
478
459
``` py
479
460
scala_toolchains(
@@ -482,30 +463,32 @@ scala_toolchains(
482
463
)
483
464
```
484
465
485
- The other exception is ` scala_register_unused_deps_toolchains() ` . Replace this
486
- macro with :
466
+ The other is replacing ` scala_register_unused_deps_toolchains() ` with an
467
+ explicit ` register_toolchains() ` call :
487
468
488
469
``` py
489
470
register_toolchains(
490
471
" @rules_scala//scala:unused_dependency_checker_error_toolchain" ,
491
472
)
492
473
```
493
474
494
- In ` WORKSPACE ` , this must come before calling ` scala_register_toolchains() ` to
495
- ensure this toolchain takes precedence. The same exact call will also work in
496
- ` MODULE.bazel ` .
475
+ In ` WORKSPACE ` , this ` register_toolchains() ` call must come before calling
476
+ ` scala_register_toolchains() ` to ensure this toolchain takes precedence. The
477
+ same exact call will also work in ` MODULE.bazel ` .
478
+
479
+ #### Copy ` register_toolchains() ` calls from ` WORKSPACE ` to ` MODULE.bazel `
497
480
498
- ` scala_register_toolchains() ` should remain in ` WORKSPACE ` , but there's no
499
- equivalent for ` MODULE.bazel ` . The ` MODULE.bazel ` file from ` rules_scala ` will
500
- automatically call ` register_toolchains() ` for toolchains configured via its
501
- module extension, so you don't have to.
481
+ The ` MODULE.bazel ` file from ` rules_scala ` will automatically call
482
+ ` register_toolchains() ` for toolchains configured via its ` scala_deps ` module
483
+ extension. However, you must register explicitly in your ` MODULE.bazel ` file any
484
+ toolchains that you want to take precedence over the toolchains configured by
485
+ ` scala_deps ` .
502
486
503
487
### Bzlmod configuration (coming soon!)
504
488
505
489
The upcoming Bzlmod implementation will funnel through the ` scala_toolchains() `
506
490
macro as well, ensuring maximum compatibility with ` WORKSPACE ` configurations.
507
- The equivalent Bzlmod stanza for the ` scala_toolchains() ` stanza above would be
508
- the following.
491
+ The equivalent Bzlmod stanza for the ` scala_toolchains() ` stanza above would be:
509
492
510
493
``` py
511
494
bazel_dep(name = " rules_scala" , version = " 7.0.0" )
@@ -528,8 +511,8 @@ scala_deps.toolchains(
528
511
)
529
512
```
530
513
531
- The module extensions will call ` scala_config() ` and ` scala_toolchains() ` in
532
- their implementation . The ` MODULE.bazel ` file for ` rules_scala ` declares its own
514
+ The module extensions will call ` scala_config() ` and ` scala_toolchains() `
515
+ respectively . The ` MODULE.bazel ` file for ` rules_scala ` declares its own
533
516
dependencies via ` bazel_dep() ` , allowing Bazel to resolve versions according to
534
517
the main repository/root module configuration. It also calls
535
518
[ ` register_toolchains() ` ] [ reg_tool ] , so you don't have to (unless you want to
@@ -623,17 +606,20 @@ improves performance.
623
606
[ ` compatibility_level ` ] ( https://bazel.build/external/module#compatibility_level )
624
607
values for their [ ` module() ` ] ( https://bazel.build/rules/lib/globals/module )
625
608
directives. This is due to the gap in supported ` protobuf ` versions documented
626
- in #1647 (between v25.5 and v28).
609
+ in #1647 (between v25.5 and v28) and dropping support for Bazel 6.5.0 Bzlmod
610
+ builds.
627
611
628
612
This will ensure any users attempting to mismatch ` protobuf ` and ` rules_scala `
629
613
versions will break during module resolution, rather than during a later
630
- execution step. (Though, as described in #1647 , there are now measures in place
631
- to cause the build to crash during a mismatch instead of hanging.)
614
+ execution step. (Though, as described in bazelbuild/rules_scala #1647 , there are
615
+ now measures in place to cause the build to crash during a mismatch instead of
616
+ hanging.)
632
617
633
618
The concept of proper ` compatibility_level ` usage is still up for discussion in
634
- bazelbuild/bazel #24302 . The ` rules_scala ` implementation will track semantic
635
- versioning major version numbers, and clearly document the reason for the level
636
- bump. If a version bump may break builds for any known reason, we should explain
619
+ bazelbuild/bazel #24302 . The ` compatibility_level ` for ` rules_scala `
620
+ implementation will track major version numbers (per [ semantic
621
+ versioning] ( https://semver.org/ ) ), and clearly document the reason for the level
622
+ bump. If a version bump may break builds for any known reason, we will explain
637
623
why up front instead of waiting for users to be surprised.
638
624
639
625
[ A comment from #1647 illustrates how ` rules_erlang ` fails due to
0 commit comments