Skip to content

Commit 525f8b4

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: - `examples/overridden_artifacts` - `scala/extensions/config.bzl` - `scala/extensions/deps.bzl` - `scala/private/extensions/dev_deps.bzl` - `scala/private/macros/bzlmod.bzl` `config.bzl`, `deps.bzl`, and `dev_deps.bzl` are thoroughly tested by existing tests. The following files thoroughly test the helpers from `scala/private/macros/bzlmod.bzl` specifically: - scala/private/macros/test/... - 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`. `test/shell/test_helper.sh` also introduces a mechanism for automatically finding and skipping tests, documented in the comment at the bottom of the file. "Publish to BCR" configuration in the `.bcr` directory comes from: - https://github.com/bazel-contrib/publish-to-bcr/tree/main/templates The bazel-contrib/publish-to-bcr README contains further guidance on configuring the app. Once that's done, we can use the app to publish a new version to https://registry.bazel.build/ 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 94d342c commit 525f8b4

Some content is hidden

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

71 files changed

+2357
-55
lines changed

.bazelignore

Lines changed: 6 additions & 0 deletions
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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
# Remove once Bazel 7.5.0 becomes the default supported version.
2+
common --enable_bzlmod
3+
14
build --enable_platform_specific_config
25

36
#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.
47

58
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

.bcr/config.yml

Whitespace-only changes.

.bcr/metadata.template.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"homepage": "https://github.com/bazelbuild/rules_scala",
3+
"maintainers": [
4+
{
5+
"name": "Simonas Pinevičius",
6+
"email": "[email protected]",
7+
"github": "simuons"
8+
},
9+
{
10+
"name": "Vaidas Pilkauskas",
11+
"email": "[email protected]",
12+
"github": "liucijus"
13+
}
14+
],
15+
"repository": [
16+
"github:bazelbuild/rules_scala"
17+
],
18+
"versions": [],
19+
"yanked_versions": {}
20+
}

.bcr/presubmit.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# We recommend included a bcr test workspace that exercises your ruleset with bzlmod.
2+
# For an example, see https://github.com/aspect-build/bazel-lib/tree/main/e2e/bzlmod.
3+
bcr_test_module:
4+
module_path: "examples/crossbuild"
5+
matrix:
6+
platform: ["debian10", "macos", "ubuntu2004", "windows"]
7+
bazel: [6.x, 7.x]
8+
tasks:
9+
run_tests:
10+
name: "Run test module"
11+
platform: ${{ platform }}
12+
bazel: ${{ bazel }}
13+
test_targets:
14+
- "//..."

.bcr/source.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "",
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
5+
}

.gitignore

Lines changed: 6 additions & 0 deletions
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

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
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.16",
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 module
36+
# resolution, 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, "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+
scalafmt = True,
104+
scalatest = True,
105+
junit = True,
106+
specs2 = True,
107+
twitter_scrooge = True,
108+
)
109+
110+
use_repo(
111+
dev_deps,
112+
"scala_proto_rules_scalapb_compilerplugin",
113+
"scala_proto_rules_scalapb_protoc_bridge",
114+
"scalafmt_default",
115+
)
116+
117+
# Default versions of version specific repos needed by some of our tests. Tests
118+
# that set `--repo_env=SCALA_VERSION=...` break without using the default here,
119+
# because version specific repos for other versions won't be available.
120+
use_repo(
121+
dev_deps,
122+
"io_bazel_rules_scala_guava",
123+
"io_bazel_rules_scala_junit_junit",
124+
"io_bazel_rules_scala_scala_compiler",
125+
"io_bazel_rules_scala_scala_library",
126+
)
127+
128+
[
129+
[
130+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
131+
for dep in [
132+
"io_bazel_rules_scala_junit_junit",
133+
"io_bazel_rules_scala_scala_compiler",
134+
"io_bazel_rules_scala_scala_library",
135+
] + (
136+
# We can remove this condition once we drop support for Scala 2.11.
137+
["scala_proto_rules_scalapb_protoc_gen"]
138+
if not scala_version.startswith("2.11.") else []
139+
)
140+
]
141+
for scala_version in SCALA_VERSIONS
142+
]
143+
144+
[
145+
[
146+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
147+
for dep in [
148+
"io_bazel_rules_scala_scala_reflect",
149+
]
150+
]
151+
for scala_version in SCALA_2_VERSIONS
152+
]
153+
154+
[
155+
[
156+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
157+
for dep in [
158+
"io_bazel_rules_scala_scala_compiler_2",
159+
"io_bazel_rules_scala_scala_library_2",
160+
"io_bazel_rules_scala_scala_reflect_2",
161+
]
162+
]
163+
for scala_version in SCALA_3_VERSIONS
164+
]
165+
166+
internal_dev_deps = use_extension(
167+
"//scala/private/extensions:dev_deps.bzl",
168+
"dev_deps",
169+
dev_dependency = True,
170+
)
171+
172+
# See //scala/private:extensions/dev_deps.bzl for notes on some of these repos.
173+
use_repo(
174+
internal_dev_deps,
175+
"com_github_bazelbuild_buildtools",
176+
"com_github_jnr_jffi_native",
177+
"com_google_guava_guava_21_0",
178+
"com_google_guava_guava_21_0_with_file",
179+
"com_twitter__scalding_date",
180+
"org_apache_commons_commons_lang_3_5",
181+
"org_apache_commons_commons_lang_3_5_without_file",
182+
"org_springframework_spring_core",
183+
"org_springframework_spring_tx",
184+
"org_typelevel__cats_core",
185+
"org_typelevel_kind_projector",
186+
)
187+
188+
java_toolchains = use_extension(
189+
"@rules_java//java:extensions.bzl",
190+
"toolchains",
191+
dev_dependency = True,
192+
)
193+
194+
use_repo(
195+
java_toolchains,
196+
# //test/toolchains:java21_toolchain
197+
"remotejdk21_linux",
198+
"remotejdk21_macos",
199+
"remotejdk21_win",
200+
# //test/jmh:test_jmh_jdk8
201+
"remote_jdk8_linux",
202+
"remote_jdk8_macos",
203+
"remote_jdk8_windows",
204+
)
205+
206+
[
207+
(
208+
bazel_dep(name = name, dev_dependency = True),
209+
local_path_override(module_name = name, path = path)
210+
)
211+
for name, path in [
212+
(
213+
"proto_cross_repo_boundary",
214+
"test/proto_cross_repo_boundary/repo",
215+
),
216+
(
217+
"test_new_local_repo",
218+
"third_party/test/new_local_repo",
219+
),
220+
(
221+
"example_external_workspace",
222+
"third_party/test/example_external_workspace",
223+
),
224+
]
225+
]
226+
227+
bazel_dep(
228+
name = "platforms",
229+
version = "0.0.11",
230+
dev_dependency = True,
231+
)
232+
bazel_dep(
233+
name = "bazel_ci_rules",
234+
version = "1.0.0",
235+
dev_dependency = True,
236+
repo_name = "bazelci_rules",
237+
)
238+
bazel_dep(
239+
name = "rules_go",
240+
version = "0.53.0",
241+
dev_dependency = True,
242+
repo_name = "io_bazel_rules_go", # for com_github_bazelbuild_buildtools
243+
)
244+
bazel_dep(name = "gazelle", version = "0.42.0", dev_dependency = True)
245+
246+
go_sdk = use_extension(
247+
"@io_bazel_rules_go//go:extensions.bzl",
248+
"go_sdk",
249+
dev_dependency = True,
250+
)
251+
go_sdk.download(version = "1.24.0")
252+
253+
go_deps = use_extension(
254+
"@gazelle//:extensions.bzl",
255+
"go_deps",
256+
dev_dependency = True,
257+
)
258+
259+
# The go_deps.module calls are inspired by the following to get the
260+
# com_github_bazelbuild_buildtools repo to work:
261+
#
262+
# - https://github.com/bazelbuild/bazel-central-registry/blob/main/modules/gazelle/0.39.1/MODULE.bazel#L31-L57
263+
#
264+
# To get the latest version and hashes for each per:
265+
#
266+
# - https://go.dev/ref/mod#go-list-m
267+
# - https://go.dev/ref/mod#checksum-database
268+
#
269+
# go list -m golang.org/x/tools@latest
270+
# curl https://sum.golang.org/lookup/golang.org/x/[email protected]
271+
go_deps.module(
272+
path = "golang.org/x/tools",
273+
sum = "h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=",
274+
version = "v0.30.0",
275+
)
276+
277+
go_deps.module(
278+
path = "github.com/golang/protobuf",
279+
sum = "h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=",
280+
version = "v1.5.4",
281+
)
282+
use_repo(
283+
go_deps,
284+
"com_github_golang_protobuf",
285+
"org_golang_x_tools",
286+
)
287+
288+
bazel_dep(name = "rules_python", version = "0.38.0", dev_dependency = True)

0 commit comments

Comments
 (0)