Skip to content

Commit abc941a

Browse files
committed
Bump Bazel and dependencies to prepare for Bzlmod
This begins the Bzlmod compatibility migration by updating Bazel to version 7.3.2 and adding initial `MODULE.bazel` and `WORKSPACE.bzlmod` files. Part of: bazelbuild#1482 Though Bzlmod remains disabled, updating to Bazel 7.3.2 requred updating or adding the following packages to maintain `WORKSPACE` compatibility. In `rules_scala_setup()`: - bazel_skylib: 1.4.1 => 1.7.1 - rules_cc: 0.0.6 => 0.0.10 - rules_java: 5.4.1 => 7.9.0 - rules_proto: 5.3.0-21.7 => 6.0.2 Dev dependencies in `WORKSPACE`: - com_google_protobuf: 28.2 - rules_pkg: 1.0.1 - rules_jvm_external: 6.4 - com_google_absl: abseil-cpp-20240722.0 - zlib: 1.3.1 Of all of the new, explicit dev dependencies, only `com_google_protobuf` will be necessary to include in `MODULE.bazel`. The Bzlmod mechanism will discover these other transitive dev dependencies automatically. Also removed the `rules_java_extra` repo from `WORKSPACE`, which appeared unused. --- Though the current `rules_java` version is 7.12.1, and largely works with this repo, it requires a few temporary workarounds. Rather than commit the workarounds, upgrading only to 7.9.0 now seems less crufty. What follows is a very detailed explanation of what happens with 7.12.1 with Bazel 7.3.2, just to have it on the record. --- The workaround is to change a few toolchain and macro file targets from `@bazel_tools//tools/jdk:` to `@rules_java//toolchains:`. This isn't a terribly bad or invasive workaround, but `@bazel_tools//tools/jdk:` is clearly the canonical path. Best to keep it that way, lest we build up technical debt. Without the workaround, these targets would fail: - //test/src/main/resources/java_sources:CompiledWithJava11 - //test/src/main/resources/java_sources:CompiledWithJava8 - //test/toolchains:java21_toolchain - //test:JunitRuntimePlatform - //test:JunitRuntimePlatform_test_runner - //test:scala_binary_jdk_11 with this error: ```txt ERROR: .../external/rules_java_builtin/toolchains/BUILD:254:14: While resolving toolchains for target @@rules_java_builtin//toolchains:platformclasspath (096dcc8): No matching toolchains found for types @@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type. ``` This appears to be a consequence of both upgrading the Bazel version from 6.3.0 to 7.3.2 and updating `rules_java` to 7.12.1. The `rules_java_builtin` repo is part of the `WORKSPACE` prefix that adds implicit dependencies: - https://bazel.build/external/migration#builtin-default-deps This repo was added to 7.0.0-pre.20231011.2 in the following change, mapped to `@rules_java` within the scope of the `@bazel_tools` repo: - bazelbuild/bazel: Add rules_java_builtin to the users of Java modules bazelbuild/bazel@ff1abb2 This change tried to ensure `rules_java` remained compatible with earlier Bazel versions. However, it changed all instances of `@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type` to `//toolchains:bootstrap_runtime_toolchain_type`: - bazelbuild/rules_java: Make rules_java backwards compatible with Bazel 6.3.0 bazelbuild/rules_java@30ecf3f Bazel has bumped `rules_java` in its `workspace_deps.bzl` from 7.9.0 to 7.11.0, but it's only available as of 8.0.0-pre.20240911.1. - bazelbuild/bazel: Update rules_java 7.11.1 / java_tools 13.8 bazelbuild/bazel#23571 bazelbuild/bazel@f92124a --- What I believe is happening is, under Bazel 7.3.2 and `rules_java` 7.12.1: - Bazel creates `rules_java` 7.9.0 as `@rules_java_builtin` in the `WORKSPACE` prefix. - `@bazel_tools` has `@rules_java` mapped to `@rules_java_builtin` when initialized during the `WORKSPACE` prefix, during which `@bazel_tools//tools/jdk` registers `alias()` targets to `@rules_java` toolchain targets. These aliased toolchains specify `@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type` in their `toolchains` attribute. - `WORKSPACE` loads `@rules_java` 7.12.1 and registers all its toolchains with type `@rules_java//toolchains:bootstrap_runtime_toolchain_type`. - Some `@rules_java` rules explicitly specifying toolchains from `@bazel_tools//tools/jdk` can't find them, because the `@bazel_tools//tools/jdk` toolchain aliases expect toolchains of type `@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type`. This has broken other projects in the same way: - bazelbuild/bazel: [Bazel CI] Downstream project broken by rules_java upgrade #23619 bazelbuild/bazel#23619 These problems don't appear under Bzlmod, and `@rules_java_builtin` was never required. This is because `WORKSPACE` executes its statements sequentially, while Bzlmod builds the module dependency graph _before_ instantiating repositories (within module extensions). It seems a fix is on the way that removes `@rules_java_builtin` from the `WORKSPACE` prefix, and adds `@rules_java` to the suffix. At this moment, though, it's not even in a prerelase: - bazelbuild/bazel: Remove rules_java_builtin in WORKSPACE prefix bazelbuild/bazel@7506690 --- Note that the error message matches that from the following resolved issue, but that issue was for non-Bzlmod child repos when `WORKSPACE` was disabled. - bazelbuild/bazel: Undefined @@rules_java_builtin repository with --noenable_workspace option bazelbuild/bazel#22754
1 parent 3da60a8 commit abc941a

File tree

8 files changed

+88
-33
lines changed

8 files changed

+88
-33
lines changed

.bazelrc

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ build --enable_platform_specific_config
33
#Windows needs --worker_quit_after_build due to workers not being shut down when the compiler tools need to be rebuilt (resulting in 'file in use' errors). See Bazel Issue#10498.
44

55
build:windows --worker_quit_after_build --enable_runfiles
6+
7+
# Remove these upon completing Bzlmod compatibility work.
8+
# - https://github.com/bazelbuild/rules_scala/issues/1482
9+
build --noenable_bzlmod
10+
build --enable_workspace

.bazelversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.3.0
1+
7.3.2

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ hash2
1010
.vscode
1111
unformatted-*.backup.scala
1212
.scala-build
13-
test/semanticdb/tempsrc
13+
test/semanticdb/tempsrc
14+
15+
# Consider removing after Bzlmod conversion is complete.
16+
# - https://github.com/bazelbuild/rules_scala/issues/1482
17+
MODULE.bazel.lock

MODULE.bazel

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Bazel module definition for rules_scala"""
2+
3+
# Bzlmod compatibility work is currently underway. See:
4+
# - https://github.com/bazelbuild/rules_scala/issues/1482
5+
6+
module(
7+
name = "rules_scala", version = "6.6.1", repo_name = "io_bazel_rules_scala"
8+
)

WORKSPACE

+55-18
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ rules_scala_setup()
3434

3535
rules_scala_toolchain_deps_repositories(fetch_sources = True)
3636

37-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
38-
39-
# Declares @com_google_protobuf//:protoc pointing to released binary
40-
# This should stop building protoc during bazel build
41-
# See https://github.com/bazelbuild/rules_proto/pull/36
37+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
4238
rules_proto_dependencies()
4339

40+
load("@rules_proto//proto:setup.bzl", "rules_proto_setup")
41+
rules_proto_setup()
42+
43+
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
4444
rules_proto_toolchains()
4545

4646
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
@@ -144,19 +144,6 @@ go_rules_dependencies()
144144

145145
go_register_toolchains(version = "1.19.5")
146146

147-
# Explicitly pull in a different (newer) version of rules_java for remote jdks
148-
rules_java_extra_version = "5.1.0"
149-
150-
rules_java_extra_sha = "d974a2d6e1a534856d1b60ad6a15e57f3970d8596fbb0bb17b9ee26ca209332a"
151-
152-
rules_java_extra_url = "https://github.com/bazelbuild/rules_java/releases/download/{}/rules_java-{}.tar.gz".format(rules_java_extra_version, rules_java_extra_version)
153-
154-
http_archive(
155-
name = "rules_java_extra",
156-
sha256 = rules_java_extra_sha,
157-
url = rules_java_extra_url,
158-
)
159-
160147
load("@rules_java//java:repositories.bzl", "remote_jdk8_repos")
161148

162149
# We need to select based on platform when we use these
@@ -209,3 +196,53 @@ load("//test/toolchains:jdk.bzl", "remote_jdk21_repositories", "remote_jdk21_too
209196
remote_jdk21_repositories()
210197

211198
remote_jdk21_toolchains()
199+
200+
http_archive(
201+
name = "com_google_protobuf",
202+
sha256 = "b2340aa47faf7ef10a0328190319d3f3bee1b24f426d4ce8f4253b6f27ce16db",
203+
strip_prefix = "protobuf-28.2",
204+
url = "https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protobuf-28.2.tar.gz",
205+
)
206+
207+
http_archive(
208+
name = "rules_pkg",
209+
sha256 = "d20c951960ed77cb7b341c2a59488534e494d5ad1d30c4818c736d57772a9fef",
210+
url = "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.1/rules_pkg-1.0.1.tar.gz",
211+
)
212+
213+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
214+
215+
rules_pkg_dependencies()
216+
217+
RULES_JVM_EXTERNAL_TAG = "6.4"
218+
RULES_JVM_EXTERNAL_SHA = "85776be6d8fe64abf26f463a8e12cd4c15be927348397180a01693610da7ec90"
219+
220+
http_archive(
221+
name = "rules_jvm_external",
222+
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
223+
sha256 = RULES_JVM_EXTERNAL_SHA,
224+
url = "https://github.com/bazel-contrib/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG)
225+
)
226+
227+
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
228+
229+
rules_jvm_external_deps()
230+
231+
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
232+
233+
rules_jvm_external_setup()
234+
235+
http_archive(
236+
name = "com_google_absl",
237+
strip_prefix = "abseil-cpp-20240722.0",
238+
sha256 = "f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3",
239+
url = "https://github.com/abseil/abseil-cpp/releases/download/20240722.0/abseil-cpp-20240722.0.tar.gz",
240+
)
241+
242+
http_archive(
243+
name = "zlib",
244+
strip_prefix = "zlib-1.3.1",
245+
sha256 = "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23",
246+
url = "https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz",
247+
build_file = "@com_google_protobuf//third_party:zlib.BUILD",
248+
)

WORKSPACE.bzlmod

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Bzlmod compatibility work is currently underway. See:
2+
# - https://github.com/bazelbuild/rules_scala/issues/1482

scala/private/macros/scala_repositories.bzl

+11-12
Original file line numberDiff line numberDiff line change
@@ -85,38 +85,37 @@ def rules_scala_setup(scala_compiler_srcjar = None):
8585
if not native.existing_rule("bazel_skylib"):
8686
http_archive(
8787
name = "bazel_skylib",
88-
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
88+
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
8989
urls = [
90-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
91-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
90+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.4.1.tar.gz",
91+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
9292
],
9393
)
9494

9595
if not native.existing_rule("rules_cc"):
9696
http_archive(
9797
name = "rules_cc",
98-
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.6/rules_cc-0.0.6.tar.gz"],
99-
sha256 = "3d9e271e2876ba42e114c9b9bc51454e379cbf0ec9ef9d40e2ae4cec61a31b40",
100-
strip_prefix = "rules_cc-0.0.6",
98+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.10/rules_cc-0.0.10.tar.gz"],
99+
sha256 = "65b67b81c6da378f136cc7e7e14ee08d5b9375973427eceb8c773a4f69fa7e49",
100+
strip_prefix = "rules_cc-0.0.10",
101101
)
102102

103103
if not native.existing_rule("rules_java"):
104104
http_archive(
105105
name = "rules_java",
106106
urls = [
107-
"https://github.com/bazelbuild/rules_java/releases/download/5.4.1/rules_java-5.4.1.tar.gz",
107+
"https://github.com/bazelbuild/rules_java/releases/download/7.9.0/rules_java-7.9.0.tar.gz",
108108
],
109-
sha256 = "a1f82b730b9c6395d3653032bd7e3a660f9d5ddb1099f427c1e1fe768f92e395",
109+
sha256 = "41131de4417de70b9597e6ebd515168ed0ba843a325dc54a81b92d7af9a7b3ea",
110110
)
111111

112112
if not native.existing_rule("rules_proto"):
113113
http_archive(
114114
name = "rules_proto",
115-
sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",
116-
strip_prefix = "rules_proto-5.3.0-21.7",
115+
sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295",
116+
strip_prefix = "rules_proto-6.0.2",
117117
urls = [
118-
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz",
119-
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz",
118+
"https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
120119
],
121120
)
122121

test/proto_cross_repo_boundary/repo.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ def proto_cross_repo_boundary_repository():
22
native.new_local_repository(
33
name = "proto_cross_repo_boundary",
44
path = "test/proto_cross_repo_boundary/repo",
5-
build_file = "test/proto_cross_repo_boundary/repo/BUILD.repo",
5+
build_file = "//test/proto_cross_repo_boundary:repo/BUILD.repo",
66
)

0 commit comments

Comments
 (0)