Skip to content

Commit 4daa608

Browse files
committed
Fix last_green w/bazel_worker_api, rules_java 8.14
Uses the `bazel_worker_{api,java}` modules and a legacy `WORKSPACE` shim to replace `@bazel_tools//src/main/protobuf:worker_protocol_java_proto`. This, and bumping `rules_java` to 8.14.0, fixes breakages in the latest `last_green` Bazel at commit 00b48b27aa216befc419e540919a1f1df4cda337. Also: - Removes the `--incompatible_autoload_externally` flag from `.bazelrc`. - Fixes `_get_compiler_srcjar` to return empty `compiler_srcjar_objects` instead of returning a valid object. `test_compiler_srcjar_error 2.12.11` from `dt_patches/dt_patch_test.sh` caught this under `WORKSPACE`. Added `test_fail_if_compiler_srcjar_object_is_empty` to `test/shell/test_compiler_sources_integrity.sh` to catch the specific problem sooner. - Fixed regex in `target_file_location` from `test_helper.sh` to work with Bazel 6.5.0, and fixed unbound variable in `fail` message. - Added logic to `teardown_suite` in `test_bzlmod_macros.sh` to avoid unbound variable breakage when running under Bazel 6.5.0. - Added logic to skip `test_check_module_bazel_template` under Bazel 6 in `test_version.sh`. - Removed restriction to use `protobuf` v29 or lower with Bazel 6 from `README.md`. - Added `scala_compiler_source.*` to the regular expressions for "canonical reproducible" messages in `dt_patches/dt_patch_test.sh`. This resolved a test breakage when `rules_python` began to emit a "canonical reproducible" message. (Also changed `--expunge` to `--expunge_async`.) --- bazelbuild/bazel#26477, which also landed in the 9.0.0-pre.20250714.1 rolling release, broke the `last_green` build: ``` $ USE_BAZEL_VERSION=9.0.0-pre.20250714.1 bazel test //src/... //test/... ERROR: error loading package '@@bazel_tools//src/main/protobuf': Unable to find package for @@[unknown repo 'grpc-java' requested from @@bazel_tools]//:java_grpc_library.bzl: The repository '@@[unknown repo 'grpc-java' requested from @@bazel_tools]' could not be resolved: No repository visible as '@grpc-java' from repository '@@bazel_tools'. ``` The failing target, and several others, depended upon `@bazel_tools//src/main/protobuf:worker_protocol_java_proto`. Nothing else depends on any other target from that package. So upon @Wyverald's advice, I attempted to use the `bazel_worker_java` module to replace this specific dependency: - bazelbuild/bazel#26579 (comment) Using just `bazel_worker_java` 0.0.5 at first produced this breakage: ```txt $ USE_BAZEL_VERSION=last_green bazel build //src/... //test/... ERROR: .../external/bazel_worker_api+/BUILD.bazel:3:1: name 'proto_library' is not defined ``` This is because that version of `bazel_worker_java` still depends upon `bazel_worker_api` 0.0.1, which didn't load `proto_library` from `@com_google_protobuf`. Adding `bazel_worker_api` 0.0.5 directly to `MODULE.bazel` fixed this. The next failure was due to `rules_scala` overriding `rules_java` to be 8.12.0, whereas `last_green` now requires 8.14.0: ```txt $ USE_BAZEL_VERSION=last_green bazel build //src/... //test/... ERROR: src/java/io/bazel/rulesscala/jar/BUILD:3:13: in java_library rule //src/java/io/bazel/rulesscala/jar:jar: Traceback (most recent call last): File ".../external/rules_java+/java/bazel/rules/bazel_java_library.bzl", line 26, column 35, in _proxy return bazel_java_library_rule( File ".../external/rules_java+/java/common/rules/impl/bazel_java_library_impl.bzl", line 68, column 43, in bazel_java_library_rule target, base_info = basic_java_library( File ".../external/rules_java+/java/common/rules/impl/basic_java_library_impl.bzl", line 127, column 49, in basic_java_library java_info, compilation_info = compile_action( File ".../external/rules_java+/java/common/rules/impl/compile_action.bzl", line 139, column 46, in compile_action java_info = _compile_private_for_builtins( File ".../external/rules_java+/java/private/java_common_internal.bzl", line 217, column 68, in compile get_internal_java_common().create_header_compilation_action( Error in create_header_compilation_action: create_header_compilation_action() missing 2 required positional arguments: header_compilation_jar, header_compilation_direct_deps ERROR: src/java/io/bazel/rulesscala/jar/BUILD:3:13: Analysis of target '//src/java/io/bazel/rulesscala/jar:jar' failed ``` Bumping `rules_java` to 8.14.0 in the `single_version_override` fixed that. Finally, since there's no legacy `WORKSPACE` API in bazelbuild/bazel-worker-api, I had to roll my own new `workspace_compat()` macro. This macro creates `@bazel_worker_{api,java}` repos with aliases to targets in `@bazel-worker-api`. Regarding `--incompatible_autoload_externally`, I'd added it in bazel-contrib#1748 when fixing problems with `WORKSPACE` builds under Bazel 8.2.1. However, it's not really necessary, so I removed it.
1 parent 933d698 commit 4daa608

File tree

20 files changed

+124
-46
lines changed

20 files changed

+124
-46
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Remove once Bazel 8 becomes the minimum supported version.
2-
common --noenable_workspace --incompatible_use_plus_in_repo_names --incompatible_autoload_externally=
2+
common --noenable_workspace --incompatible_use_plus_in_repo_names
33

44
# Uncomment to run tests under `WORKSPACE`. Remove once Bazel 9 becomes the
55
# minimum supported version.

MODULE.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ single_version_override(
4242
bazel_dep(name = "rules_java", version = "7.6.0")
4343
single_version_override(
4444
module_name = "rules_java",
45-
version = "8.12.0",
45+
version = "8.14.0",
4646
)
4747

4848
bazel_dep(name = "rules_proto", version = "6.0.0")
@@ -66,6 +66,9 @@ single_version_override(
6666
version = "31.1",
6767
)
6868

69+
bazel_dep(name = "bazel_worker_api", version = "0.0.5")
70+
bazel_dep(name = "bazel_worker_java", version = "0.0.5")
71+
6972
scala_protoc = use_extension(
7073
"//scala/extensions:protoc.bzl",
7174
"scala_protoc",

README.md

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,36 +1318,12 @@ future compatibility.
13181318

13191319
__`rules_scala` 7.x officially drops support for Bazel 6.5.0.__ Bzlmod builds
13201320
with Bazel 6.5.0 won't work at all because [Bazel 6.5.0 doesn't support
1321-
'use_repo_rule']( https://bazel.build/versions/6.5.0/rules/lib/globals), which
1321+
'use_repo_rule'](https://bazel.build/versions/6.5.0/rules/lib/globals), which
13221322
['rules_jvm_external' >= 6.3 requires](
13231323
https://github.com/bazelbuild/rules_scala/issues/1482#issuecomment-2515496234).
13241324

13251325
At the moment, `WORKSPACE` builds mostly continue to work with Bazel 6.5.0, but
1326-
not out of the box, and may break at any time.
1327-
1328-
#### Maximum of `protobuf` v29
1329-
1330-
You _must_ use `protobuf` v29 or earlier. `rules_scala` now uses v30 by default,
1331-
which removes `py_proto_library` and other symbols that Bazel 6.5.0 requires:
1332-
1333-
```txt
1334-
ERROR: Traceback (most recent call last):
1335-
File ".../external/bazel_tools/src/main/protobuf/BUILD",
1336-
line 1, column 46, in <toplevel>
1337-
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
1338-
1339-
Error: file '@com_google_protobuf//:protobuf.bzl'
1340-
does not contain symbol 'py_proto_library'
1341-
1342-
ERROR: .../src/java/io/bazel/rulesscala/worker/BUILD:3:13:
1343-
no such target '@bazel_tools//src/main/protobuf:worker_protocol_java_proto':
1344-
target 'worker_protocol_java_proto'
1345-
not declared in package 'src/main/protobuf'
1346-
defined by .../external/bazel_tools/src/main/protobuf/BUILD
1347-
(Tip: use `query "@bazel_tools//src/main/protobuf:*"`
1348-
to see all the targets in that package)
1349-
and referenced by '//src/java/io/bazel/rulesscala/worker:worker'
1350-
```
1326+
may break at any time.
13511327

13521328
#### Configuring the protocol compiler toolchain
13531329

deps/latest/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module(
99
bazel_dep(name = "bazel_skylib", version = "1.7.1")
1010
bazel_dep(name = "platforms", version = "1.0.0")
1111
bazel_dep(name = "protobuf", version = "31.1")
12-
bazel_dep(name = "rules_java", version = "8.12.0")
12+
bazel_dep(name = "rules_java", version = "8.14.0")
1313
bazel_dep(name = "rules_proto", version = "7.1.0")
1414

1515
# https://github.com/bazelbuild/bazel/pull/25681 removed

dt_patches/dt_patch_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test_compiler_srcjar() {
3636
run_in_test_repo \
3737
test_dt_patches_user_srcjar \
3838
bazel build "--repo_env=SCALA_VERSION=${SCALA_VERSION}" //... 2>&1 |
39-
(! grep "canonical reproducible")
39+
(! grep "scala_compiler_source.*canonical reproducible")
4040
}
4141

4242
test_compiler_srcjar_nonhermetic() {
@@ -46,7 +46,7 @@ test_compiler_srcjar_nonhermetic() {
4646
run_in_test_repo \
4747
test_dt_patches_user_srcjar \
4848
bazel build "--repo_env=SCALA_VERSION=${SCALA_VERSION}" //... 2>&1 |
49-
grep 'canonical reproducible'
49+
grep 'scala_compiler_source.*canonical reproducible'
5050
}
5151

5252
test_compiler_srcjar_error() {
@@ -129,7 +129,7 @@ $runner test_compiler_srcjar_error 2.12.13
129129
# that we grep for will only be outputted the first time (on Bazel >= 6).
130130
# So we clean the repo first to ensure consistency.
131131

132-
run_in_test_repo 'test_dt_patches_user_srcjar' bazel clean --expunge
132+
run_in_test_repo 'test_dt_patches_user_srcjar' bazel clean --expunge_async
133133

134134
$runner test_compiler_srcjar 2.12.14
135135
$runner test_compiler_srcjar 2.12.15

scala/deps.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5+
load("//scala/private:macros/workspace_compat.bzl", "workspace_compat")
56

67
def rules_scala_dependencies():
78
"""Instantiates repos needed by rules provided by `rules_scala`."""
@@ -64,3 +65,5 @@ def rules_scala_dependencies():
6465
strip_prefix = "rules_proto-6.0.2",
6566
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
6667
)
68+
69+
workspace_compat()

scala/latest_deps.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5+
load("//scala/private:macros/workspace_compat.bzl", "workspace_compat")
56

67
def rules_scala_dependencies():
78
"""Instantiates repos needed by rules provided by `rules_scala`."""
@@ -29,9 +30,9 @@ def rules_scala_dependencies():
2930
http_archive,
3031
name = "rules_java",
3132
urls = [
32-
"https://github.com/bazelbuild/rules_java/releases/download/8.12.0/rules_java-8.12.0.tar.gz",
33+
"https://github.com/bazelbuild/rules_java/releases/download/8.14.0/rules_java-8.14.0.tar.gz",
3334
],
34-
sha256 = "1558508fc6c348d7f99477bd21681e5746936f15f0436b5f4233e30832a590f9",
35+
sha256 = "bbe7d94360cc9ed4607ec5fd94995fd1ec41e84257020b6f09e64055281ecb12",
3536
)
3637

3738
maybe(
@@ -69,3 +70,5 @@ def rules_scala_dependencies():
6970
rules_jvm_external_tag,
7071
),
7172
)
73+
74+
workspace_compat()

scala/private/macros/scala_repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ compiler_sources_repo = repository_rule(
5858
)
5959

6060
def _get_compiler_srcjar(scala_version, scala_compiler_srcjar):
61-
if scala_compiler_srcjar:
61+
if scala_compiler_srcjar != None:
6262
return scala_compiler_srcjar
6363

6464
compiler_srcjar = COMPILER_SOURCES.get(scala_version, None)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Macro to translate Bazel modules into legacy WORKSPACE compatible repos
2+
3+
Used only for Bazel modules that don't offer a legacy WORKSPACE compatible API
4+
already. Originally became necessary due to:
5+
6+
- https://github.com/bazelbuild/bazel/issues/26579#issuecomment-3120862995
7+
"""
8+
9+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
10+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
11+
12+
_ALIAS_REPO_BUILD_FMT = """\
13+
package(default_visibility = ["//visibility:public"])
14+
15+
{aliases}"""
16+
17+
_ALIAS_FMT = """\
18+
alias(
19+
name = "{name}",
20+
actual = "{actual}",
21+
)
22+
"""
23+
24+
def _alias_repo_impl(repository_ctx):
25+
aliases = "\n".join([
26+
_ALIAS_FMT.format(name = name, actual = actual)
27+
for name, actual in repository_ctx.attr.aliases.items()
28+
])
29+
repository_ctx.file(
30+
"BUILD",
31+
_ALIAS_REPO_BUILD_FMT.format(aliases = aliases),
32+
executable = False,
33+
)
34+
35+
_alias_repo = repository_rule(
36+
implementation = _alias_repo_impl,
37+
attrs = {"aliases": attr.string_dict(mandatory = True)},
38+
)
39+
40+
def workspace_compat():
41+
maybe(
42+
http_archive,
43+
name = "bazel-worker-api",
44+
sha256 = "07b5fa9c883558e378a00c67dae05a4dcb8d43cc12486722d6875224454a8a30",
45+
urls = [
46+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-worker-api/releases/download/v0.0.5/bazel-worker-api-v0.0.5.tar.gz",
47+
"https://github.com/bazelbuild/bazel-worker-api/releases/download/v0.0.5/bazel-worker-api-v0.0.5.tar.gz",
48+
],
49+
strip_prefix = "bazel-worker-api-0.0.5",
50+
)
51+
52+
_alias_repo(
53+
name = "bazel_worker_api",
54+
aliases = {
55+
"worker_protocol_proto": "@bazel-worker-api//proto:worker_protocol_proto",
56+
},
57+
)
58+
59+
_alias_repo(
60+
name = "bazel_worker_java",
61+
aliases = {
62+
"worker_protocol_java_proto": "@bazel-worker-api//java:worker_protocol_java_proto",
63+
},
64+
)

src/java/io/bazel/rulesscala/coverage/instrumenter/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ java_binary(
1515
"//src/java/io/bazel/rulesscala/io_utils",
1616
"//src/java/io/bazel/rulesscala/jar",
1717
"//src/java/io/bazel/rulesscala/worker",
18-
"@bazel_tools//src/main/protobuf:worker_protocol_java_proto",
1918
"@bazel_tools//tools/jdk:JacocoCoverage",
19+
"@bazel_worker_java//:worker_protocol_java_proto",
2020
],
2121
)
2222

0 commit comments

Comments
 (0)