Skip to content

Commit 403d7ed

Browse files
committed
More small README.md improvements
1 parent e6973f4 commit 403d7ed

File tree

1 file changed

+46
-60
lines changed

1 file changed

+46
-60
lines changed

README.md

+46-60
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ the following dependency versions, make sure to `load()` them before calling
4747

4848
As of version 7.0.0, __`rules_scala` no longer requires the
4949
`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.
5256

5357
```py
5458
# WORKSPACE
@@ -57,7 +61,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5761
# See https://github.com/bazelbuild/rules_scala/releases for up to date version
5862
# information, including `<SHASUM>` values.
5963
http_archive(
60-
name = "rules_scala",
64+
name = "rules_scala", # Can be "io_bazel_rules_scala" if you still need it.
6165
sha256 = "<SHASUM>",
6266
strip_prefix = "rules_scala-7.0.0",
6367
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()
7882
# If you need a specific `rules_python` version, specify it here.
7983
# Otherwise you may get the version defined in the `com_google_protobuf` repo.
8084
# 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.
8286
http_archive(
8387
name = "rules_python",
8488
sha256 = "ca2671529884e3ecb5b79d6a5608c7373a82078c3553b1fa53206e6b9dddab34",
@@ -146,10 +150,9 @@ scala_toolchains(
146150
scala_register_toolchains()
147151
```
148152

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
151154

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:
153156

154157
```py
155158
load(
@@ -160,23 +163,19 @@ load(
160163
)
161164
```
162165

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
164167

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:
166170

167171
```txt
168172
build --strategy=Scalac=worker
169173
build --worker_sandboxing
170174
```
171175

172-
to your command line, or to enable by default for building/testing add it to
173-
your `.bazelrc`.
174-
175176
## Coverage support
176177

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:
180179

181180
```txt
182181
bazel coverage \
@@ -211,24 +210,8 @@ Please check [coverage.md](docs/coverage.md) for more details on coverage suppor
211210
`rules_scala` supports the last two released minor versions for each of Scala 2.11, 2.12, 2.13.
212211
Previous minor versions may work but are supported only on a best effort basis.
213212

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.
232215

233216
### With custom toolchains
234217

@@ -361,7 +344,7 @@ to Bazel 7 and Bzlmod.__ To facilitate a gradual migration, it remains
361344
compatible with both `WORKSPACE` and Bzlmod. However, it contains the following
362345
breaking changes when upgrading from `rules_scala` 6.x.
363346

364-
### New `scala_toolchains()` API for `WORKSPACE`
347+
### <a id="new-toolchains-api"></a>New `scala_toolchains()` API for `WORKSPACE`
365348

366349
`rules_scala` 7.0.0 replaces existing `*_repositories()` and `*_toolchains()`
367350
macros with the combination of `rules_scala_dependencies()`,
@@ -464,16 +447,14 @@ parameter list, which is almost in complete correspondence with parameters from
464447
the previous macros. The `WORKSPACE` files in this repository also provide many
465448
examples.
466449

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`
471451

472452
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.
474455

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:
477458

478459
```py
479460
scala_toolchains(
@@ -482,30 +463,32 @@ scala_toolchains(
482463
)
483464
```
484465

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:
487468

488469
```py
489470
register_toolchains(
490471
"@rules_scala//scala:unused_dependency_checker_error_toolchain",
491472
)
492473
```
493474

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`
497480

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`.
502486

503487
### Bzlmod configuration (coming soon!)
504488

505489
The upcoming Bzlmod implementation will funnel through the `scala_toolchains()`
506490
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:
509492

510493
```py
511494
bazel_dep(name = "rules_scala", version = "7.0.0")
@@ -528,8 +511,8 @@ scala_deps.toolchains(
528511
)
529512
```
530513

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
533516
dependencies via `bazel_dep()`, allowing Bazel to resolve versions according to
534517
the main repository/root module configuration. It also calls
535518
[`register_toolchains()`][reg_tool], so you don't have to (unless you want to
@@ -623,17 +606,20 @@ improves performance.
623606
[`compatibility_level`](https://bazel.build/external/module#compatibility_level)
624607
values for their [`module()`](https://bazel.build/rules/lib/globals/module)
625608
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.
627611

628612
This will ensure any users attempting to mismatch `protobuf` and `rules_scala`
629613
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.)
632617

633618
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
637623
why up front instead of waiting for users to be surprised.
638624

639625
[A comment from #1647 illustrates how `rules_erlang` fails due to

0 commit comments

Comments
 (0)