Skip to content

Commit c67ae3b

Browse files
committed
Fix last_green w/bazel_worker_java rules_java 8.15
Uses the `bazel_worker_java` module 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 from commit 00b48b27aa216befc419e540919a1f1df4cda337. Note, though, that this change bumps `rules_java` to 8.15.0, since it's now available. This change also updates: - `gazelle`: 0.44.0 => 0.45.0 - `rules_go`: 0.55.1 => 0.56.1 - `rules_shell`: 0.5.0 => 0.5.1 Also: - Removes the `--incompatible_autoload_externally` flag from `.bazelrc`. - Removes the Bazel 9.0.0-pre.20250710.1 CI job added by bazel-contrib#1755, since it's no longer necessary given the fix from this change. - 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) 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 from the `bazel-worker-api` archive using @Wyverald's `http_archive` and `strip_prefix` suggestion from bazel-contrib#1756. 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 f7bacdf commit c67ae3b

File tree

18 files changed

+81
-66
lines changed

18 files changed

+81
-66
lines changed

.bazelci/presubmit.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ tasks:
3737
# Install xmllint
3838
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
3939
- "./test_rules_scala.sh || buildkite-agent annotate --style 'warning' \"Optional build with last_green Bazel version failed, [see here](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) (It is not mandatory but worth checking)\""
40-
# Remove this job once the last_green job passes after a fix lands for
41-
# bazelbuild/bazel#26579.
42-
test_rules_scala_linux_9_prerelease:
43-
name: "./test_rules_scala (Bazel 9 rolling prerelease)"
44-
platform: ubuntu2004
45-
bazel: 9.0.0-pre.20250710.1
46-
shell_commands:
47-
# Install xmllint
48-
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
49-
- "./test_rules_scala.sh"
5040
test_rules_scala_macos:
5141
name: "./test_rules_scala"
5242
platform: macos

MODULE.bazel

Lines changed: 7 additions & 5 deletions
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.14.0",
45+
version = "8.15.0",
4646
)
4747

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

69+
bazel_dep(name = "bazel_worker_java", version = "0.0.6")
70+
6971
scala_protoc = use_extension(
7072
"//scala/extensions:protoc.bzl",
7173
"scala_protoc",
@@ -254,11 +256,11 @@ bazel_dep(
254256
)
255257
bazel_dep(
256258
name = "rules_go",
257-
version = "0.55.1",
259+
version = "0.56.1",
258260
dev_dependency = True,
259261
repo_name = "io_bazel_rules_go", # for com_github_bazelbuild_buildtools
260262
)
261-
bazel_dep(name = "gazelle", version = "0.44.0", dev_dependency = True)
263+
bazel_dep(name = "gazelle", version = "0.45.0", dev_dependency = True)
262264

263265
go_sdk = use_extension(
264266
"@io_bazel_rules_go//go:extensions.bzl",
@@ -284,7 +286,7 @@ go_deps = use_extension(
284286
# - https://go.dev/ref/mod#checksum-database
285287
#
286288
# go list -m golang.org/x/tools@latest
287-
# curl https://sum.golang.org/lookup/golang.org/x/tools@v0.34.0
289+
# curl https://sum.golang.org/lookup/golang.org/x/tools@v0.35.0
288290
go_deps.module(
289291
path = "golang.org/x/tools",
290292
sum = "h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=",
@@ -302,4 +304,4 @@ use_repo(
302304
)
303305

304306
bazel_dep(name = "rules_python", version = "1.5.1", dev_dependency = True)
305-
bazel_dep(name = "rules_shell", version = "0.5.0", dev_dependency = True)
307+
bazel_dep(name = "rules_shell", version = "0.5.1", dev_dependency = True)

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

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ local_repository(
105105

106106
http_archive(
107107
name = "io_bazel_rules_go",
108-
sha256 = "9d72f7b8904128afb98d46bbef82ad7223ec9ff3718d419afb355fddd9f9484a",
108+
sha256 = "89d2050410602142c9acafd01c95baf48b65f8dd16f4771d37c89f82f5e147f2",
109109
urls = [
110-
"https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.55.1/rules_go-v0.55.0.zip",
111-
"https://github.com/bazel-contrib/rules_go/releases/download/v0.55.1/rules_go-v0.55.1.zip",
110+
"https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.56.1/rules_go-v0.56.1.zip",
111+
"https://github.com/bazel-contrib/rules_go/releases/download/v0.56.1/rules_go-v0.56.1.zip",
112112
],
113113
)
114114

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.8.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.14.0")
12+
bazel_dep(name = "rules_java", version = "8.15.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: 10 additions & 6 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.14.0/rules_java-8.14.0.tar.gz",
33+
"https://github.com/bazelbuild/rules_java/releases/download/8.15.0/rules_java-8.15.0.tar.gz",
3334
],
34-
sha256 = "bbe7d94360cc9ed4607ec5fd94995fd1ec41e84257020b6f09e64055281ecb12",
35+
sha256 = "0a7e8811cac04b553f6c6c0d185046e3c68a4cb774e83f37a7a5fb6a3deee261",
3536
)
3637

3738
maybe(
@@ -72,7 +73,8 @@ def rules_scala_dependencies():
7273

7374
# Can't upgrade for now because https://github.com/bazel-contrib/rules_python/pull/2760
7475
# broke Bazel 7 WORKSPACE builds. It's really only a dev dep anyway.
75-
# If it's fixed per https://github.com/bazel-contrib/rules_python/issues/3119,
76+
# If it's fixed per https://github.com/bazel-contrib/rules_python/issues/3119
77+
# (i.e., once https://github.com/bazel-contrib/rules_python/pull/3134 lands),
7678
# then we can upgrade.
7779
maybe(
7880
http_archive,
@@ -85,7 +87,9 @@ def rules_scala_dependencies():
8587
maybe(
8688
http_archive,
8789
name = "rules_shell",
88-
sha256 = "b15cc2e698a3c553d773ff4af35eb4b3ce2983c319163707dddd9e70faaa062d",
89-
strip_prefix = "rules_shell-0.5.0",
90-
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.5.0/rules_shell-v0.5.0.tar.gz",
90+
sha256 = "99bfc7aaefd1ed69613bbd25e24bf7871d68aeafca3a6b79f5f85c0996a41355",
91+
strip_prefix = "rules_shell-0.5.1",
92+
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.5.1/rules_shell-v0.5.1.tar.gz",
9193
)
94+
95+
workspace_compat()

scala/private/macros/test/MODULE.bzlmod_test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ dev_test_ext = use_extension(
1717
dev_dependency = True,
1818
)
1919

20-
bazel_dep(name = "rules_shell", version = "0.4.1")
20+
bazel_dep(name = "rules_shell", version = "0.5.1")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
def _bazel_worker_api_repo(name, strip_prefix):
13+
maybe(
14+
http_archive,
15+
name = name,
16+
sha256 = "5aac6ae6a23015cc7984492a114dc539effc244ec5ac7f8f6b1539c15fb376eb",
17+
urls = [
18+
"https://github.com/bazelbuild/bazel-worker-api/releases/download/v0.0.6/bazel-worker-api-v0.0.6.tar.gz",
19+
],
20+
strip_prefix = "bazel-worker-api-0.0.6/" + strip_prefix,
21+
)
22+
23+
def workspace_compat():
24+
_bazel_worker_api_repo(
25+
name = "bazel_worker_api",
26+
strip_prefix = "proto",
27+
)
28+
29+
_bazel_worker_api_repo(
30+
name = "bazel_worker_java",
31+
strip_prefix = "java",
32+
)

0 commit comments

Comments
 (0)