Skip to content

Commit 1ec53e7

Browse files
committed
Establish minimum compatible Bazel, dep versions
Separates the latest dependency versions that we test against from the minimum required versions and bumps `protobuf` to v30.2. Part of bazel-contrib#1482. Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for Bzlmod, used by our internal test repos. Tests used to validate these dependency versions will land in a future change. Also fixes a bug in the failure message of `_default_platform()` in `protoc_toolchains.bzl` by calling `string.join()` on the `HOST_CONSTRAINTS` list. (Didn't notice this until building on Windows ARM64, since there's no such binary `protobuf` release yet.) --- This avoids forcing users to upgrade to the latest versions that `rules_scala` tests against. Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace on 2025-01-01 indicating that rules should require the minumum versions possible: - https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
1 parent 3f37e26 commit 1ec53e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+357
-142
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# - bazelbuild/bazel: Loading top-level targets in local_path_override modules
33
# in child directory breaks the build #22208
44
# https://github.com/bazelbuild/bazel/issues/22208
5+
deps/
56
dt_patches/compiler_sources
67
dt_patches/test_dt_patches
78
dt_patches/test_dt_patches_user_srcjar

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ repository-artifacts.json
2222

2323
# Used by some tests, but can also be used for local experimentation.
2424
tmp/
25+
26+
# Not required by tests.
27+
deps/latest/.bazelversion

MODULE.bazel

+31-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module(
44
name = "rules_scala",
55
version = "7.0.0",
6-
bazel_compatibility = [">=7.5.0"],
6+
bazel_compatibility = [">=7.1.0"],
77
compatibility_level = 7,
88
)
99

@@ -26,15 +26,33 @@ SCALA_3_VERSIONS = [
2626

2727
SCALA_VERSIONS = SCALA_2_VERSIONS + SCALA_3_VERSIONS
2828

29-
bazel_dep(name = "bazel_skylib", version = "1.7.1")
30-
bazel_dep(name = "platforms", version = "0.0.11")
31-
bazel_dep(name = "rules_cc", version = "0.1.1")
32-
bazel_dep(name = "abseil-cpp", version = "20250127.1")
33-
bazel_dep(name = "rules_java", version = "8.11.0")
34-
bazel_dep(name = "rules_proto", version = "7.1.0")
29+
bazel_dep(name = "bazel_skylib", version = "1.6.0")
30+
single_version_override(
31+
module_name = "bazel_skylib",
32+
version = "1.7.1",
33+
)
34+
35+
bazel_dep(name = "platforms", version = "0.0.9")
36+
single_version_override(
37+
module_name = "platforms",
38+
version = "0.0.11",
39+
)
40+
41+
bazel_dep(name = "rules_java", version = "7.6.0")
42+
single_version_override(
43+
module_name = "rules_java",
44+
version = "8.11.0",
45+
)
46+
47+
bazel_dep(name = "rules_proto", version = "6.0.0")
48+
single_version_override(
49+
module_name = "rules_proto",
50+
version = "7.1.0",
51+
)
52+
3553
bazel_dep(
3654
name = "protobuf",
37-
version = "30.1",
55+
version = "28.2",
3856
repo_name = "com_google_protobuf",
3957
)
4058

@@ -44,7 +62,7 @@ single_version_override(
4462
module_name = "protobuf",
4563
patch_strip = 1,
4664
patches = ["//protoc:0001-protobuf-19679-rm-protoc-dep.patch"],
47-
version = "30.1",
65+
version = "30.2",
4866
)
4967

5068
scala_protoc = use_extension(
@@ -247,7 +265,7 @@ go_sdk = use_extension(
247265
"go_sdk",
248266
dev_dependency = True,
249267
)
250-
go_sdk.download(version = "1.24.1")
268+
go_sdk.download(version = "1.24.2")
251269

252270
go_deps = use_extension(
253271
"@gazelle//:extensions.bzl",
@@ -269,8 +287,8 @@ go_deps = use_extension(
269287
# curl https://sum.golang.org/lookup/golang.org/x/[email protected]
270288
go_deps.module(
271289
path = "golang.org/x/tools",
272-
sum = "h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=",
273-
version = "v0.31.0",
290+
sum = "h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU=",
291+
version = "v0.32.0",
274292
)
275293
go_deps.module(
276294
path = "github.com/golang/protobuf",
@@ -283,4 +301,4 @@ use_repo(
283301
"org_golang_x_tools",
284302
)
285303

286-
bazel_dep(name = "rules_python", version = "1.2.0", dev_dependency = True)
304+
bazel_dep(name = "rules_python", version = "1.3.0", dev_dependency = True)

README.md

+74-30
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ register_toolchains(
112112
# compiler" section below.
113113
bazel_dep(
114114
name = "protobuf",
115-
version = "30.1",
115+
version = "30.2",
116116
repo_name = "com_google_protobuf",
117117
)
118118
single_version_override(
119119
module_name = "protobuf",
120120
patch_strip = 1,
121121
patches = ["//:protobuf.patch"],
122-
version = "30.1",
122+
version = "30.2",
123123
)
124124
```
125125

@@ -171,6 +171,21 @@ http_archive(
171171
url = "https://github.com/bazelbuild/rules_scala/releases/download/<VERSION>/rules_scala-<VERSION>.tar.gz",
172172
)
173173

174+
# This imports the minimum versions supported by the minimum supported Bazel
175+
# version, plus `rules_java` 8.5.0. If you use `rules_java` 7 or an earlier
176+
# `rules_java` 8 version, the corresponding `load` statements are slightly
177+
# different. See the `WORKSPACE` snippet from
178+
# https://github.com/bazelbuild/rules_java/releases corresponding to the
179+
# `rules_java` version for details.
180+
#
181+
# Also, this imports `rules_proto` 6.0.2, though 6.0.0 will work. This is
182+
# because the `WORKSPACE` snippets for different versions of `rules_proto` vary
183+
# somewhat, and the 6.0.2 snippet works with the latest version. See
184+
# https://github.com/bazelbuild/rules_proto/releases for the corresponding
185+
# `rules_proto` release for details.
186+
#
187+
# If you want the latest dependency versions, change `deps.bzl` to
188+
# `latest_deps.bzl`.
174189
load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
175190

176191
rules_scala_dependencies()
@@ -238,7 +253,8 @@ rules_proto_toolchains()
238253

239254
# Include this after loading `platforms`, `com_google_protobuf`, and
240255
# `rules_proto` to enable the `//protoc` precompiled protocol compiler
241-
# toolchains. See the "Using a precompiled protocol compiler" section below.
256+
# toolchains. Requires at least `protobuf` v29.0. See the "Using a precompiled
257+
# protocol compiler" section below.
242258
load("@rules_scala//protoc:toolchains.bzl", "scala_protoc_toolchains")
243259

244260
# This name can be anything, but we recommend `rules_scala_protoc_toolchains`.
@@ -318,22 +334,41 @@ load(
318334
### <a id="protoc"></a>Using a precompiled protocol compiler
319335

320336
`rules_scala` now supports the
321-
[`--incompatible_enable_proto_toolchain_resolution`][] flag when using
322-
[protobuf v29 or later](#why-proto-v29). When using this flag with the
323-
`MODULE.bazel` or `WORKSPACE` configurations below, `rules_scala` will use a
324-
precompiled protocol compiler binary by default.
337+
[`--incompatible_enable_proto_toolchain_resolution`][] flag when using [protobuf
338+
v29 or later](#why-proto-v29) with the minimum dependency versions specified
339+
below. When using this flag with the `MODULE.bazel` or `WORKSPACE`
340+
configurations below, `rules_scala` will use a precompiled protocol compiler
341+
binary by default.
325342

326343
[`--incompatible_enable_proto_toolchain_resolution`]: https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
327344

328345
__Windows builds now require using `protobuf` v29 or later with the precompiled
329346
protocol compiler toolchain.__ See the [Windows MSVC builds of protobuf broken
330347
by default](#protoc-msvc) section below for details.
331348

349+
#### Minimum dependency versions
350+
351+
These are the minimum dependency versions required to enable the precompiled
352+
protocol compiler toolchain.
353+
354+
Note that `rules_java` can be as low as 8.3.0, compared to `rules_java` 8.5.0
355+
specified in [Compatible Bazel versions](#compatible-bazel-versions).
356+
357+
| Dependency | Minimum version | Reason |
358+
| :-: | :-: | :- |
359+
| `protobuf` | v29.0 | See the [Why this requires 'protobuf' v29 or later](#why-proto-v29) section.|
360+
| Bazel | 7.1.0 (with `rules_java` 7.10.0, 8.3.2)<br/>7.3.2 (with `rules_java` 8.3.0) | `module(bazel_compatibility = "...")` constraints in `MODULE.bazel` |
361+
| `platforms` | 0.0.9 | Creates the `@host_platform` repo used to auto-detect the toolchain for the host platform. |
362+
| `rules_java` | 7.10.0 (with `--experimental_google_legacy_api`), 8.3.0 | `protobuf` v29 needs 7.8.0 with `--experimental_google_legacy_api` for `ProguardSpecProvider`. Then it needs 7.10.0 for `//java/private:proto_support.bzl` visibility.<br/>`protobuf` v29 needs `@rules_java//java/private:proto_support.bzl` from v8.2.0. See [bazelbuild/rules_java@94d5617](https://github.com/bazelbuild/rules_java/commit/94d5617cf3d97ddda10c81ba05a865e8e3a0408e).<br/>v8.3.0 fixes bazelbuild/rules_java#233. |
363+
| `rules_proto` | 7.0.0 | Required by `protobuf` v29 and later. |
364+
| `bazel_skylib` | 1.7.0 | Contains `paths.is_normalized`, required by `//bazel/private:bazel_proto_library_rule.bzl` in `protobuf` v29. See [bazelbuild/bazel-skylib@0e485c8](https://github.com/bazelbuild/bazel-skylib/commit/0e485c80b7992f5ebfab50637f86e966f544ad58). |
365+
332366
#### Common setup
333367

334368
To set the flag in your `.bazelrc` file:
335369

336370
```txt
371+
# .bazelrc
337372
common --incompatible_enable_proto_toolchain_resolution
338373
```
339374

@@ -455,20 +490,21 @@ package of your repository, add the following to your `MODULE.bazel`:
455490
# protocolbuffers/protobuf#19679.
456491
bazel_dep(
457492
name = "protobuf",
458-
version = "30.1",
493+
version = "30.2",
459494
repo_name = "com_google_protobuf",
460495
)
461496
single_version_override(
462497
module_name = "protobuf",
463498
patch_strip = 1,
464499
patches = ["//:protobuf.patch"],
465-
version = "30.1",
500+
version = "30.2",
466501
)
467502
```
468503

469504
#### `protobuf` patch setup under `WORKSPACE`
470505

471-
[`scala/deps.bzl`](./scala/deps.bzl) currently applies the `protobuf` patch to `protobuf` v30.1.
506+
[`scala/latest-deps.bzl`](./scala/latest-deps.bzl) currently applies the
507+
`protobuf` patch to `protobuf` v30.2.
472508

473509
If you need to apply the patch to a different version of `protobuf`, copy it to
474510
your repo as described in the Bzlmod setup above. Then apply it in your own
@@ -477,9 +513,9 @@ your repo as described in the Bzlmod setup above. Then apply it in your own
477513
```py
478514
http_archive(
479515
name = "com_google_protobuf",
480-
sha256 = "1451b03faec83aed17cdc71671d1bbdfd72e54086b827f5f6fd02bf7a4041b68",
481-
strip_prefix = "protobuf-30.1",
482-
url = "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v30.1.tar.gz",
516+
sha256 = "07a43d88fe5a38e434c7f94129cad56a4c43a51f99336074d0799c2f7d4e44c5",
517+
strip_prefix = "protobuf-30.2",
518+
url = "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v30.2.tar.gz",
483519
repo_mapping = {"@com_google_absl": "@abseil-cpp"},
484520
patches = ["//protobuf.patch"],
485521
patch_args = ["-p1"],
@@ -633,24 +669,31 @@ Bazel and `rules_java`, and their compatibility with [scalapb/ScalaPB](
633669
https://github.com/scalapb/ScalaPB) Maven artifacts. For extensive analysis,
634670
see bazelbuild/rules_scala#1647.
635671

636-
The Bazel versions and dependency versions in the table below represent the
637-
maximum available at the time of writing.
672+
The Bazel versions and dependency versions below represent the minimum versions
673+
compatible with `rules_scala` 7.x.
638674

639675
- For the actual versions used by `rules_scala`, see
640676
[MODULE.bazel](./MODULE.bazel).
641677

642678
- See [.bazelci/presubmit.yml](./.bazelci/presubmit.yml) for the exact Bazel
643679
versions verified by the continuous integration builds.
644680

645-
| Bazel/Dependency | `rules_scala` 7.x |
681+
| Mode | Supported Bazel versions |
646682
| :-: | :-: |
647-
| Bazel versions using Bzlmod<br/>(Coming soon! See bazelbuild/rules_scala#1482.) | 7.6.0, 8.x,<br/>`rolling`, `last_green` |
648-
| Bazel versions using `WORKSPACE` | 6.5.0, 7.6.0, 8.x<br/>(see the [notes on 6.5.0 compatibility](#6.5.0)) |
649-
| `protobuf` | v30.1 |
650-
| `rules_proto` | 7.1.0 |
651-
| `abseil-cpp` | 20250127.1 |
652-
| `rules_java` | 8.11.0 |
653-
| `ScalaPB` | 1.0.0-alpha.1 |
683+
| Bzlmod<br/>(Coming soon! See bazelbuild/rules_scala#1482.) | >= 7.1.0, 8.x,<br/>`rolling`, `last_green` |
684+
| `WORKSPACE` | 6.5.0, >= 7.1.0, 8.x<br/>(see the [notes on 6.5.0 compatibility](#6.5.0)) |
685+
686+
`rules_scala` 7.0.0 uses `ScalaPB` 1.0.0-alpha.1 to support `protobuf` v28.2 and
687+
later, required by newer Bazel versions and other dependencies. Below are the
688+
minimum versions of `protobuf` and related dependencies supported for Bazel 7
689+
and 8.
690+
691+
| Dependency | Bazel >= 7.1.0 | Bazel 8.x |
692+
| :--------: | :------------: | :-------: |
693+
| `bazel_skylib` | 1.6.0 | 1.7.0 |
694+
| `protobuf` | v28.2 | v29.0 |
695+
| `rules_java` | 7.6.0, 8.4.0 | 8.5.0 |
696+
| `rules_proto` | 6.0.0 | 7.0.0 |
654697

655698
The next major release will likely drop support for `protobuf` versions before
656699
v29 and remove `rules_proto` completely. This is to comply with the guidance in
@@ -662,7 +705,8 @@ https://github.com/bazelbuild/rules_scala/pull/1710#issuecomment-2750001012).
662705
### Using a prebuilt `@com_google_protobuf//:protoc` or C++ compiler flags
663706

664707
Newer versions of `abseil-cpp`, required by newer versions of
665-
`@com_google_protobuf//:protoc`, fail to compile under Bazel 6.5.0 and 7.6.0 by
708+
`@com_google_protobuf//:protoc`, fail to compile under Bazel 6.5.0 by default.
709+
The latest versions of `abseil-cpp` also fail to compile under Bazel 7 by
666710
default. [protoc will also fail to build on Windows when using
667711
MSVC](#protoc-msvc). You will have to choose one of the following approaches to
668712
resolve this problem.
@@ -1112,25 +1156,25 @@ supporting Bazel + MSVC builds per:
11121156
Enable [protocol compiler toolchainization](#protoc) to fix broken Windows
11131157
builds by avoiding `@com_google_protobuf//:protoc` recompilation.
11141158

1115-
### Minimum of `protobuf` v28
1159+
### Minimum of `protobuf` v28.2
11161160

1117-
`rules_scala` requires at least `protobuf` v28, and at least v29 for [protocol
1161+
`rules_scala` requires at least `protobuf` v28.2, and at least v29 for [protocol
11181162
compiler toolchain](#protoc) support. No `ScalaPB` release supports `protobuf`
11191163
v25.6, v26, or v27.
11201164

11211165
#### Using earlier `protobuf` versions
11221166

1123-
If you can't update to `protobuf` v28 or later right now, build using Bazel 7
1167+
If you can't update to `protobuf` v28.2 or later right now, build using Bazel 7
11241168
and the following maximum versions of key dependencies. This is not officially
11251169
supported, but should work for some time.
11261170

11271171
| Dependency | Max compatible version | Reason |
11281172
| :-: | :-: | :- |
1173+
| `ScalaPB` | 0.11.17<br/>(0.9.8 for Scala 2.11) | Later versions only support `protobuf` >= v28.2. |
11291174
| `protobuf` | v25.5 | Maximum version supported by `ScalaPB` 0.11.17. |
1130-
| `rules_proto` | 6.0.2 | Maximum version supporting `protobuf` v25.5 |
1131-
| `rules_java` | 7.12.4 | 8.x requires `protobuf` v27 and later. |
11321175
| `rules_cc` | 0.0.9 | 0.0.10 requires Bazel 7 to define `CcSharedLibraryHintInfo`.<br/>0.0.13 requires at least `protobuf` v27.0. |
1133-
| `ScalaPB` | 0.11.17<br/>(0.9.8 for Scala 2.11) | Later versions only support `protobuf` >= v28. |
1176+
| `rules_java` | 7.12.5 | 8.x requires `protobuf` v27 and later. |
1177+
| `rules_proto` | 6.0.2 | Maximum version supporting `protobuf` v25.5 |
11341178

11351179
### Embedded resource paths no longer begin with `external/<repo_name>`
11361180

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
workspace(name = "rules_scala")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4-
load("//scala:deps.bzl", "rules_scala_dependencies")
4+
load("//scala:latest_deps.bzl", "rules_scala_dependencies")
55

66
rules_scala_dependencies()
77

deps/latest/MODULE.bazel

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Bazel module defining the latest available dependency versions."""
2+
3+
module(
4+
name = "latest_dependencies",
5+
version = "0.0.0",
6+
bazel_compatibility = [">=7.1.0"],
7+
)
8+
9+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
10+
bazel_dep(name = "platforms", version = "0.0.11")
11+
bazel_dep(name = "protobuf", version = "30.2")
12+
bazel_dep(name = "rules_java", version = "8.11.0")
13+
bazel_dep(name = "rules_proto", version = "7.1.0")
14+
15+
# https://github.com/bazelbuild/bazel/pull/25681 removed
16+
# `bazel_tools/tools/cpp/osx_cc_wrapper.sh.tpl` in the `last_green` Bazel as of
17+
# 2025-04-08. At least `test_cross_build` breaks without this.
18+
bazel_dep(name = "rules_cc", version = "0.1.1")

dt_patches/test_dt_patches/MODULE.bazel

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ local_path_override(
88
path = "../..",
99
)
1010

11+
bazel_dep(name = "latest_dependencies")
12+
local_path_override(
13+
module_name = "latest_dependencies",
14+
path = "../../deps/latest",
15+
)
16+
1117
scala_config = use_extension(
1218
"@rules_scala//scala/extensions:config.bzl",
1319
"scala_config",
@@ -70,12 +76,12 @@ register_toolchains(
7076
# protocolbuffers/protobuf#19679.
7177
bazel_dep(
7278
name = "protobuf",
73-
version = "30.1",
79+
version = "30.2",
7480
repo_name = "com_google_protobuf",
7581
)
7682
single_version_override(
7783
module_name = "protobuf",
7884
patch_strip = 1,
7985
patches = ["//:protobuf.patch"],
80-
version = "30.1",
86+
version = "30.2",
8187
)

dt_patches/test_dt_patches/WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local_repository(
77
path = "../..",
88
)
99

10-
load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
10+
load("@rules_scala//scala:latest_deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

0 commit comments

Comments
 (0)