Skip to content

Commit aadb0c6

Browse files
committed
Enable Bzlmod
All but finishes bazelbuild#1482, barring the release and publication to the Bazel Central Registry. Closes bazelbuild#1625. New `MODULE.bazel` files mirroring existing `WORKSPACE` configurations and copies of the `protobuf` toolchainization patch comprise the bulk of the commit. The empty `WORKSPACE.bzlmod` files ensure that Bzlmod won't evaluate the existing `WORKSPACE` files. Reenables the `last_green` Bazel build in CI. Other than that, these new files comprise the most significant part of the change: - `.bazelignore` - `.bcr/*` - `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. These new test 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. --- This change enables Bazel 7 and 8 users to migrate their `rules_scala` dependency from `WORKSPACE` to `MODULE.bazel` whenever they're ready. Once the Publish to BCR GitHub app is ready, we can use it to publish a new version to https://registry.bazel.build/. At that point, we can close bazelbuild#1482.
1 parent 1921bdc commit aadb0c6

File tree

78 files changed

+3531
-27
lines changed

Some content is hidden

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

78 files changed

+3531
-27
lines changed

.bazelci/presubmit.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ tasks:
2929
# Install xmllint
3030
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
3131
- "./test_rules_scala.sh"
32-
# Switch `last_rc` to `last_green` once Bzlmod lands.
33-
# https://github.com/bazelbuild/rules_scala/issues/1482
34-
test_rules_scala_linux_last_rc:
35-
name: "./test_rules_scala (last_rc Bazel)"
32+
test_rules_scala_linux_last_green:
33+
name: "./test_rules_scala (last_green Bazel)"
3634
platform: ubuntu2004
37-
bazel: last_rc
35+
bazel: last_green
3836
shell_commands:
3937
# Install xmllint
4038
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
4139
- echo "build --enable_workspace" >> .bazelrc
42-
- "./test_rules_scala.sh || buildkite-agent annotate --style 'warning' \"Optional build with last_rc Bazel version failed, [see here](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) (It is not mandatory but worth checking)\""
40+
- "./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)\""
4341
test_rules_scala_macos:
4442
name: "./test_rules_scala"
4543
platform: macos

.bazelignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
dt_patches/compiler_sources
6+
dt_patches/test_dt_patches
7+
dt_patches/test_dt_patches_user_srcjar
8+
examples/crossbuild
9+
examples/overridden_artifacts
10+
examples/scala3
11+
examples/semanticdb
12+
examples/testing/multi_frameworks_toolchain
13+
examples/testing/scalatest_repositories
14+
examples/testing/specs2_junit_repositories
15+
test/proto_cross_repo_boundary/repo
16+
test_cross_build
17+
third_party/test/example_external_workspace
18+
third_party/test/new_local_repo
19+
third_party/test/proto

.bazelrc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Switch to --noenable_workspace when Bzlmod lands.
2-
# https://github.com/bazelbuild/rules_scala/issues/1482
3-
common --enable_workspace --noenable_bzlmod
1+
# Remove once Bazel 8 becomes the default supported version.
2+
common --noenable_workspace
43

54
# Remove once proto toolchainization becomes the default
65
# - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution

.bcr/config.yml

Whitespace-only changes.

.bcr/metadata.template.json

+20
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

+14
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

+5
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

+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

+279
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
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 = [">=7.5.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+
bazel_dep(name = "platforms", version = "0.0.11")
31+
bazel_dep(name = "rules_cc", version = "0.1.1")
32+
bazel_dep(name = "rules_java", version = "8.10.0")
33+
bazel_dep(name = "rules_proto", version = "7.1.0")
34+
35+
bazel_dep(
36+
name = "protobuf",
37+
version = "29.3",
38+
repo_name = "com_google_protobuf",
39+
)
40+
41+
# Temporarily required for `protoc` toolchainization until resolution of
42+
# protocolbuffers/protobuf#19679.
43+
single_version_override(
44+
module_name = "protobuf",
45+
version = "29.3",
46+
patches = ["//protoc:0001-protobuf-19679-rm-protoc-dep.patch"],
47+
patch_strip = 1,
48+
)
49+
50+
scala_config = use_extension(
51+
"//scala/extensions:config.bzl",
52+
"scala_config",
53+
)
54+
use_repo(scala_config, "rules_scala_config")
55+
56+
dev_config = use_extension(
57+
"//scala/extensions:config.bzl",
58+
"scala_config",
59+
dev_dependency = True,
60+
)
61+
dev_config.settings(
62+
enable_compiler_dependency_tracking = True,
63+
scala_version = SCALA_VERSION,
64+
scala_versions = SCALA_VERSIONS,
65+
)
66+
67+
scala_deps = use_extension("//scala/extensions:deps.bzl", "scala_deps")
68+
69+
# This is optional, but still safe to include even when not using
70+
# `--incompatible_enable_proto_toolchain_resolution`.
71+
register_toolchains("//protoc:all")
72+
73+
# Register some of our testing toolchains first when building our repo.
74+
register_toolchains(
75+
"//scala:unused_dependency_checker_error_toolchain",
76+
"//test/proto:scalapb_toolchain",
77+
"//test/toolchains:java21_toolchain_definition",
78+
dev_dependency = True,
79+
)
80+
81+
use_repo(
82+
scala_deps,
83+
"rules_scala_toolchains",
84+
"scala_compiler_sources",
85+
)
86+
87+
register_toolchains("@rules_scala_toolchains//...:all")
88+
89+
# Dev dependencies
90+
91+
dev_deps = use_extension(
92+
"//scala/extensions:deps.bzl",
93+
"scala_deps",
94+
dev_dependency = True,
95+
)
96+
dev_deps.toolchains(
97+
jmh = True,
98+
scala_proto = True,
99+
scalafmt = True,
100+
scalatest = True,
101+
junit = True,
102+
specs2 = True,
103+
twitter_scrooge = True,
104+
)
105+
106+
use_repo(
107+
dev_deps,
108+
"scala_proto_rules_scalapb_compilerplugin",
109+
"scala_proto_rules_scalapb_protoc_bridge",
110+
"scalafmt_default",
111+
)
112+
113+
# Default versions of version specific repos needed by some of our tests. Tests
114+
# that set `--repo_env=SCALA_VERSION=...` break without using the default here,
115+
# because version specific repos for other versions won't be available.
116+
use_repo(
117+
dev_deps,
118+
"io_bazel_rules_scala_guava",
119+
"io_bazel_rules_scala_junit_junit",
120+
"io_bazel_rules_scala_scala_compiler",
121+
"io_bazel_rules_scala_scala_library",
122+
)
123+
124+
[
125+
[
126+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
127+
for dep in [
128+
"io_bazel_rules_scala_junit_junit",
129+
"io_bazel_rules_scala_scala_compiler",
130+
"io_bazel_rules_scala_scala_library",
131+
] + (
132+
# We can remove this condition once we drop support for Scala 2.11.
133+
["scala_proto_rules_scalapb_protoc_gen"]
134+
if not scala_version.startswith("2.11.") else []
135+
)
136+
]
137+
for scala_version in SCALA_VERSIONS
138+
]
139+
140+
[
141+
[
142+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
143+
for dep in [
144+
"io_bazel_rules_scala_scala_reflect",
145+
]
146+
]
147+
for scala_version in SCALA_2_VERSIONS
148+
]
149+
150+
[
151+
[
152+
use_repo(dev_deps, dep + "_" + scala_version.replace(".", "_"))
153+
for dep in [
154+
"io_bazel_rules_scala_scala_compiler_2",
155+
"io_bazel_rules_scala_scala_library_2",
156+
"io_bazel_rules_scala_scala_reflect_2",
157+
]
158+
]
159+
for scala_version in SCALA_3_VERSIONS
160+
]
161+
162+
internal_dev_deps = use_extension(
163+
"//scala/private/extensions:dev_deps.bzl",
164+
"dev_deps",
165+
dev_dependency = True,
166+
)
167+
168+
# See //scala/private:extensions/dev_deps.bzl for notes on some of these repos.
169+
use_repo(
170+
internal_dev_deps,
171+
"com_github_bazelbuild_buildtools",
172+
"com_github_jnr_jffi_native",
173+
"com_google_guava_guava_21_0",
174+
"com_google_guava_guava_21_0_with_file",
175+
"com_twitter__scalding_date",
176+
"org_apache_commons_commons_lang_3_5",
177+
"org_apache_commons_commons_lang_3_5_without_file",
178+
"org_springframework_spring_core",
179+
"org_springframework_spring_tx",
180+
"org_typelevel__cats_core",
181+
"org_typelevel_kind_projector",
182+
)
183+
184+
java_toolchains = use_extension(
185+
"@rules_java//java:extensions.bzl",
186+
"toolchains",
187+
dev_dependency = True,
188+
)
189+
190+
use_repo(
191+
java_toolchains,
192+
# //test/toolchains:java21_toolchain
193+
"remotejdk21_linux",
194+
"remotejdk21_macos",
195+
"remotejdk21_win",
196+
# //test/jmh:test_jmh_jdk8
197+
"remote_jdk8_linux",
198+
"remote_jdk8_macos",
199+
"remote_jdk8_windows",
200+
)
201+
202+
[
203+
(
204+
bazel_dep(name = name, dev_dependency = True),
205+
local_path_override(module_name = name, path = path)
206+
)
207+
for name, path in [
208+
(
209+
"proto_cross_repo_boundary",
210+
"test/proto_cross_repo_boundary/repo",
211+
),
212+
(
213+
"test_new_local_repo",
214+
"third_party/test/new_local_repo",
215+
),
216+
(
217+
"example_external_workspace",
218+
"third_party/test/example_external_workspace",
219+
),
220+
]
221+
]
222+
223+
bazel_dep(
224+
name = "bazel_ci_rules",
225+
version = "1.0.0",
226+
dev_dependency = True,
227+
repo_name = "bazelci_rules",
228+
)
229+
bazel_dep(
230+
name = "rules_go",
231+
version = "0.53.0",
232+
dev_dependency = True,
233+
repo_name = "io_bazel_rules_go", # for com_github_bazelbuild_buildtools
234+
)
235+
bazel_dep(name = "gazelle", version = "0.42.0", dev_dependency = True)
236+
237+
go_sdk = use_extension(
238+
"@io_bazel_rules_go//go:extensions.bzl",
239+
"go_sdk",
240+
dev_dependency = True,
241+
)
242+
go_sdk.download(version = "1.24.1")
243+
244+
go_deps = use_extension(
245+
"@gazelle//:extensions.bzl",
246+
"go_deps",
247+
dev_dependency = True,
248+
)
249+
250+
# The go_deps.module calls are inspired by the following to get the
251+
# com_github_bazelbuild_buildtools repo to work:
252+
#
253+
# - https://github.com/bazelbuild/bazel-central-registry/blob/main/modules/gazelle/0.39.1/MODULE.bazel#L31-L57
254+
#
255+
# To get the latest version and hashes for each per:
256+
#
257+
# - https://go.dev/ref/mod#go-list-m
258+
# - https://go.dev/ref/mod#checksum-database
259+
#
260+
# go list -m golang.org/x/tools@latest
261+
# curl https://sum.golang.org/lookup/golang.org/x/[email protected]
262+
go_deps.module(
263+
path = "golang.org/x/tools",
264+
sum = "h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=",
265+
version = "v0.30.0",
266+
)
267+
268+
go_deps.module(
269+
path = "github.com/golang/protobuf",
270+
sum = "h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=",
271+
version = "v1.5.4",
272+
)
273+
use_repo(
274+
go_deps,
275+
"com_github_golang_protobuf",
276+
"org_golang_x_tools",
277+
)
278+
279+
bazel_dep(name = "rules_python", version = "1.2.0", dev_dependency = True)

0 commit comments

Comments
 (0)