Skip to content

Commit e70be99

Browse files
committed
Enable Bzlmod
Fulfills most of bazel-contrib#1482. Compatible with Bazel 6.5.0 and 7.5.0, but not Bazel 8. New `MODULE.bazel` files mirroring existing `WORKSPACE` configurations comprise the bulk of the commit. The empty `WORKSPACE.bzlmod` files ensure that Bzlmod won't evaluate the existing `WORKSPACE` files. These new files comprise the most significant part of the change: - scala/extensions/config.bzl - scala/extensions/deps.bzl - scala/private/extensions/dev_deps.bzl - scala/private/macros/bzlmod.bzl - scala/private/macros/test/BUILD.bzlmod_test - scala/private/macros/test/MODULE.bzlmod_test - scala/private/macros/test/bzlmod_test_ext.bzl - test/shell/test_bzlmod_macros.sh The pattern employed throughout the new module extensions is explained in the `scala/private/macros/bzlmod.bzl` docstring. Adding `test/shell/test_bzlmod_macros.sh` also precipitated adding a new `assert_matches` helper to `test/shell/test_helper.sh`. "Publish to BCR" configuration will come in a future commit. After that, we can publish a new major version and then close bazel-contrib#1482. Per bazel-contrib#1647, `com_google_protobuf` remains at v21.7, and versions up to v25.5 can work after bumping `com_google_absl` to 20240722.0 and setting C++17 compiler flags in `.bazelrc`. This change enables Bazel 6 and 7 users to migrate their `rules_scala` dependency from `WORKSPACE` to `MODULE.bazel` whenever they're ready. After the next major version release includes this change, we can update `com_google_protobuf`, `rules_java`, and related dependencies as part of enabling Bazel 8 compatibility (bazel-contrib#1652). The `rules_jvm_external` update in that change will effectively end Bzlmod support for Bazel 6.5.0, requiring another major version release after that.
1 parent 17ef600 commit e70be99

Some content is hidden

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

51 files changed

+1614
-10
lines changed

.bazelignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Remove once the following is fixed:
2+
# - bazelbuild/bazel: Loading top-level targets in local_path_override modules
3+
# in child directory breaks the build #22208
4+
# https://github.com/bazelbuild/bazel/issues/22208
5+
third_party/test/example_external_workspace
6+
third_party/test/proto

.bazelrc

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
common --enable_bzlmod
2+
13
build --enable_platform_specific_config
24

35
#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.
46

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

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ test/semanticdb/tempsrc
1616

1717
# From scripts/create_repository.py
1818
repository-artifacts.json
19+
20+
# Until it settles down
21+
**/MODULE.bazel.lock
22+
23+
# Used by some tests, but can also be used for local experimentation.
24+
tmp/

MODULE.bazel

+290
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
"""Bazel module definition for rules_scala"""
2+
3+
module(
4+
name = "rules_scala",
5+
version = "7.0.0",
6+
compatibility_level = 7,
7+
bazel_compatibility = [">=6.5.0", "<8.0.0"],
8+
)
9+
10+
SCALA_VERSION = "2.12.20"
11+
12+
# These versions match those required by some tests, including
13+
# test_thirdparty_version.sh.
14+
SCALA_2_VERSIONS = [
15+
"2.11.12",
16+
"2.12.20",
17+
"2.13.15",
18+
]
19+
20+
SCALA_3_VERSIONS = [
21+
"3.1.3",
22+
"3.3.5",
23+
"3.5.2",
24+
"3.6.3",
25+
]
26+
27+
SCALA_VERSIONS = SCALA_2_VERSIONS + SCALA_3_VERSIONS
28+
29+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
30+
31+
# Bazel 6 breaks with any higher version of `rules_cc`, because:
32+
# - 0.0.10 requires Bazel 7 to define `CcSharedLibraryHintInfo`
33+
# - 0.0.13 and up don't support `protobuf` v21.7, requiring at least v27.0
34+
# - 0.1.0 should work, but requires `stardoc` 0.7.0, which requires Bazel 7
35+
# (though it's a `dev_dependency`, it still gets pulled in during analysis,
36+
# breaking the build)
37+
bazel_dep(name = "rules_cc", version = "0.0.9")
38+
single_version_override(
39+
module_name = "rules_cc",
40+
version = "0.0.9",
41+
)
42+
43+
bazel_dep(name = "rules_java", version = "7.12.4")
44+
bazel_dep(name = "rules_proto", version = "6.0.2")
45+
46+
# For now, users are revlocked to protobuf-21.7 or protobuf-25.5 (which doesn't
47+
# build under Bazel 6).
48+
bazel_dep(
49+
name = "protobuf",
50+
version = "21.7",
51+
repo_name = "com_google_protobuf",
52+
)
53+
single_version_override(
54+
module_name = "protobuf",
55+
version = "21.7",
56+
)
57+
58+
scala_config = use_extension(
59+
"//scala/extensions:config.bzl",
60+
"scala_config",
61+
)
62+
use_repo(scala_config, "io_bazel_rules_scala_config")
63+
64+
dev_config = use_extension(
65+
"//scala/extensions:config.bzl",
66+
"scala_config",
67+
dev_dependency = True,
68+
)
69+
dev_config.settings(
70+
enable_compiler_dependency_tracking = True,
71+
scala_version = SCALA_VERSION,
72+
scala_versions = SCALA_VERSIONS,
73+
)
74+
75+
scala_deps = use_extension("//scala/extensions:deps.bzl", "scala_deps")
76+
77+
# Register some of our testing toolchains first when building our repo.
78+
register_toolchains(
79+
"//scala:unused_dependency_checker_error_toolchain",
80+
"//test/proto:scalapb_toolchain",
81+
"//test/toolchains:java21_toolchain_definition",
82+
dev_dependency = True,
83+
)
84+
85+
use_repo(
86+
scala_deps,
87+
"rules_scala_toolchains",
88+
"scala_compiler_sources",
89+
)
90+
91+
register_toolchains("@rules_scala_toolchains//...:all")
92+
93+
# Dev dependencies
94+
95+
dev_deps = use_extension(
96+
"//scala/extensions:deps.bzl",
97+
"scala_deps",
98+
dev_dependency = True,
99+
)
100+
dev_deps.toolchains(
101+
jmh = True,
102+
scala_proto = True,
103+
#scala_proto_enable_all_options = True,
104+
scalafmt = True,
105+
testing = True,
106+
#scalatest = True,
107+
#junit = True,
108+
#specs2 = True,
109+
twitter_scrooge = True,
110+
)
111+
112+
use_repo(
113+
dev_deps,
114+
"scala_proto_rules_scalapb_compilerplugin",
115+
"scala_proto_rules_scalapb_protoc_bridge",
116+
"scalafmt_default",
117+
)
118+
119+
# Default versions of version specific repos needed by some of our tests. Tests
120+
# that set `--repo_env=SCALA_VERSION=...` break without using the default here,
121+
# because version specific repos for other versions won't be available.
122+
use_repo(
123+
dev_deps,
124+
"io_bazel_rules_scala_guava",
125+
"io_bazel_rules_scala_junit_junit",
126+
"io_bazel_rules_scala_scala_compiler",
127+
"io_bazel_rules_scala_scala_library",
128+
)
129+
130+
[
131+
[
132+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
133+
for dep in [
134+
"io_bazel_rules_scala_junit_junit",
135+
"io_bazel_rules_scala_scala_compiler",
136+
"io_bazel_rules_scala_scala_library",
137+
] + (
138+
# We can remove this condition once we drop support for Scala 2.11.
139+
["scala_proto_rules_scalapb_protoc_gen"]
140+
if not scala_version.startswith("2.11.") else []
141+
)
142+
]
143+
for scala_version in SCALA_VERSIONS
144+
]
145+
146+
[
147+
[
148+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
149+
for dep in [
150+
"io_bazel_rules_scala_scala_reflect",
151+
]
152+
]
153+
for scala_version in SCALA_2_VERSIONS
154+
]
155+
156+
[
157+
[
158+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
159+
for dep in [
160+
"io_bazel_rules_scala_scala_compiler_2",
161+
"io_bazel_rules_scala_scala_library_2",
162+
"io_bazel_rules_scala_scala_reflect_2",
163+
]
164+
]
165+
for scala_version in SCALA_3_VERSIONS
166+
]
167+
168+
internal_dev_deps = use_extension(
169+
"//scala/private/extensions:dev_deps.bzl",
170+
"dev_deps",
171+
dev_dependency = True,
172+
)
173+
174+
# See //scala/private:extensions/dev_deps.bzl for notes on some of these repos.
175+
use_repo(
176+
internal_dev_deps,
177+
"com_github_bazelbuild_buildtools",
178+
"com_github_jnr_jffi_native",
179+
"com_google_guava_guava_21_0",
180+
"com_google_guava_guava_21_0_with_file",
181+
"com_twitter__scalding_date",
182+
"org_apache_commons_commons_lang_3_5",
183+
"org_apache_commons_commons_lang_3_5_without_file",
184+
"org_springframework_spring_core",
185+
"org_springframework_spring_tx",
186+
"org_typelevel__cats_core",
187+
"org_typelevel_kind_projector",
188+
)
189+
190+
java_toolchains = use_extension(
191+
"@rules_java//java:extensions.bzl",
192+
"toolchains",
193+
dev_dependency = True,
194+
)
195+
196+
use_repo(
197+
java_toolchains,
198+
# //test/toolchains:java21_toolchain
199+
"remotejdk21_linux",
200+
"remotejdk21_macos",
201+
"remotejdk21_win",
202+
# //test/jmh:test_jmh_jdk8
203+
"remote_jdk8_linux",
204+
"remote_jdk8_macos",
205+
"remote_jdk8_windows",
206+
)
207+
208+
[
209+
(
210+
bazel_dep(name = name, dev_dependency = True),
211+
local_path_override(module_name = name, path = path)
212+
)
213+
for name, path in [
214+
(
215+
"proto_cross_repo_boundary",
216+
"test/proto_cross_repo_boundary/repo",
217+
),
218+
(
219+
"test_new_local_repo",
220+
"third_party/test/new_local_repo",
221+
),
222+
(
223+
"example_external_workspace",
224+
"third_party/test/example_external_workspace",
225+
),
226+
]
227+
]
228+
229+
bazel_dep(
230+
name = "platforms",
231+
version = "0.0.11",
232+
dev_dependency = True,
233+
)
234+
bazel_dep(
235+
name = "bazel_ci_rules",
236+
version = "1.0.0",
237+
dev_dependency = True,
238+
repo_name = "bazelci_rules",
239+
)
240+
bazel_dep(
241+
name = "rules_go",
242+
version = "0.53.0",
243+
dev_dependency = True,
244+
repo_name = "io_bazel_rules_go", # for com_github_bazelbuild_buildtools
245+
)
246+
bazel_dep(name = "gazelle", version = "0.42.0", dev_dependency = True)
247+
248+
go_sdk = use_extension(
249+
"@io_bazel_rules_go//go:extensions.bzl",
250+
"go_sdk",
251+
dev_dependency = True,
252+
)
253+
go_sdk.download(version = "1.24.0")
254+
255+
go_deps = use_extension(
256+
"@gazelle//:extensions.bzl",
257+
"go_deps",
258+
dev_dependency = True,
259+
)
260+
261+
# The go_deps.module calls are inspired by the following to get the
262+
# com_github_bazelbuild_buildtools repo to work:
263+
#
264+
# - https://github.com/bazelbuild/bazel-central-registry/blob/main/modules/gazelle/0.39.1/MODULE.bazel#L31-L57
265+
#
266+
# To get the latest version and hashes for each per:
267+
#
268+
# - https://go.dev/ref/mod#go-list-m
269+
# - https://go.dev/ref/mod#checksum-database
270+
#
271+
# go list -m golang.org/x/tools@latest
272+
# curl https://sum.golang.org/lookup/golang.org/x/tools@v0.29.0
273+
go_deps.module(
274+
path = "golang.org/x/tools",
275+
sum = "h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=",
276+
version = "v0.30.0",
277+
)
278+
279+
go_deps.module(
280+
path = "github.com/golang/protobuf",
281+
sum = "h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=",
282+
version = "v1.5.4",
283+
)
284+
use_repo(
285+
go_deps,
286+
"com_github_golang_protobuf",
287+
"org_golang_x_tools",
288+
)
289+
290+
bazel_dep(name = "rules_python", version = "0.38.0", dev_dependency = True)

WORKSPACE.bzlmod

Whitespace-only changes.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Bazel module ./test/shell/test_examples.sh tests"""
2+
3+
module(name = "compiler_sources")
4+
5+
bazel_dep(name = "rules_scala")
6+
local_path_override(
7+
module_name = "rules_scala",
8+
path = "../..",
9+
)
10+
11+
scala_config = use_extension(
12+
"@rules_scala//scala/extensions:config.bzl",
13+
"scala_config",
14+
)
15+
use_repo(scala_config, "io_bazel_rules_scala_config")

dt_patches/compiler_sources/WORKSPACE.bzlmod

Whitespace-only changes.

dt_patches/compiler_sources/extensions.bzl

+7
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ def import_compiler_source_repos():
6161
licenses = ["notice"],
6262
server_urls = default_maven_server_urls(),
6363
)
64+
65+
def _compiler_source_repos_impl(_ctx):
66+
import_compiler_source_repos()
67+
68+
compiler_source_repos = module_extension(
69+
implementation = _compiler_source_repos_impl,
70+
)

dt_patches/test_dt_patches/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ SCALA_LIBS = ["@scala_library"] + select_for_scala_version(
1717

1818
setup_scala_toolchain(
1919
name = "dt_scala_toolchain",
20+
parser_combinators_deps = [],
2021
scala_compile_classpath = ["@scala_compiler"] + SCALA_LIBS,
2122
scala_library_classpath = SCALA_LIBS,
2223
scala_macro_classpath = SCALA_LIBS,
24+
scala_xml_deps = [],
2325
)

0 commit comments

Comments
 (0)