Skip to content

Commit a939c89

Browse files
committed
Support Protobuf 33.4 w/ prebuilt protoc toolchain
Replaces the `rules_scala` prebuilt `protoc` toolchain everywhere except in a few `test_dependency_versions.sh` test cases. Updates `README.md` to recommend using the `protobuf` prebuilt `protoc` toolchain, and refactors and adds test cases to `test_dependency_versions.sh`. Note that legacy `WORKSPACE` builds continue to use the `rules_scala` prebuilt `protoc` toolchain, since the `protobuf` implementation only supports Bzlmod. After removing `protobuf.patch` files, updating `MODULE.bazel{,.lock}` files, and updating Maven dependencies, the most significant changes for supporting `protobuf` v33.4 are: - `protoc/private/protoc_toolchains.bzl`, `scala/toolchains_repo.bzl`: Moves `proto_lang_toolchain` from `@rules_scala_protoc_toolchains` to `@rules_scala_toolchains//scala_proto`. This can break users using `rules_proto` < 7.0.0 and `protobuf` < v28.2, but `README.md` contains a patch for such users. - `protoc/private/toolchain_impl.bzl`: Applies changes from the final state of protocolbuffers/protobuf#19679 and updates the prebuilt `protoc` toolchain resolution check and error message. - `test_dependency_versions.sh`, `deps/test/MODULE.bazel.template`, `deps/test/protoc_toolchains.template`: Adds Bazel 9 and `protobuf` prebuilt `protoc` toolchain test cases. Updates `do_build_and_test` to support both toolchains. Extracts the `protoc_toolchains.template` to include it only in test cases using the `rules_scala` toolchain. Other key components of this change include: - `protoc/BUILD`: Aliases `@protobuf//bazel/toolchains:prefer_prebuilt_protoc` as `@rules_scala//protoc:prefer_prebuilt_protoc`. - `.bazelrc`, `tools/bazel.rc.buildkite`: Adds `common --@rules_scala//protoc:prefer_prebuilt_protoc`. - `.bazelci/presubmit.yml`, `.bcr/presubmit.yml`: Adds `9.x` to the `bcr_bazel` matrix . Also applies whitespace and quoting format changes to `.bazelci/presubmit.yml`. Also contains these small, but important changes to fix continuous integration breakages and `last_green` Bazel compatibility: - `.github/workflows/release_prep.sh`: Excludes `.bazelversion` symlinks, since per bazelbuild/bazel-worker-api#21, these break Bazel as of bazelbuild/bazel@f942a70. - `MODULE.bazel`, `scala/private/macros/workspace_compat.bzl`: Bumps `bazelbuild/bazel-worker-api` to v0.0.9 (though we need v0.0.10 to fix `last_green` builds per bazelbuild/bazel-worker-api#22). - `test/shell/test_runner.sh`, `test/shell/test_bzlmod_macros.sh`: Replaces `relative_path_to_parent` with `convert_msys2_path` for bazelbuild/continuous-integration#2445, bazelbuild/bazel#28406. Other minor changes include: - `MODULE.bazel`: Removes the `version` parameter from the `module` declaration. The Publish to BCR GitHub Actions workflow patches this parameter anyway. See: - https://bazel.build/external/faq#module-versioning-best-practices - https://github.com/bazel-contrib/publish-to-bcr/blob/v1.1.0/src/domain/create-entry.ts#L176-L216 - https://bazelbuild.slack.com/archives/C014RARENH0/p1767892286188219 - Replaces `precompiled` with `prebuilt` in every reference to the prebuilt `protoc` toolchain. - `scala/toolchains_repo.bzl`: Replaces `@@{rules_scala_repo}` references with plain `@rules_scala` references, allowing repo mapping to do its thing. - `test_dependency_version.sh`: Skips non-prebuilt `protoc` prebuilt toolchain test cases from for macOS on continuous integration. This test suite was taking a disproportionately long time to run before adding the new test cases, which Linux builds will continue to cover. A summary of these changes excluding `README.md`, `protobuf.patch`, `MODULE.bazel{,.lock}` files, and Maven dependency updates: ```txt $ git diff --stat HEAD^ ':!README.md' ':!**MODULE.bazel*' \ ':!**protobuf.patch' ':!third_party/repositories/scala_*' .bazelci/presubmit.yml | 66 ++++++++++++++++++++... .bazelrc | 9 +++++-- .bcr/presubmit.yml | 2 +- .github/workflows/release_prep.sh | 7 +++++- WORKSPACE | 15 ++++++----- deps/test/protoc_toolchains.template | 12 +++++++++ protoc/BUILD | 8 ++++++ protoc/private/protoc_integrity.bzl | 10 ++++++++ protoc/private/protoc_toolchains.bzl | 19 +++----------- protoc/private/toolchain_impl.bzl | 30 ++++++++++++++-------- protoc/toolchains.bzl | 2 +- scala/extensions/protoc.bzl | 8 +++--- scala/latest_deps.bzl | 8 +++--- scala/private/macros/workspace_compat.bzl | 6 ++--- scala/toolchains_repo.bzl | 37 ++++++++++++++++----... scala_proto/scala_proto_toolchain.bzl | 2 ++ scripts/create_repository.py | 2 +- scripts/update_protoc_integrity.py | 6 +++-- test/shell/test_bzlmod_macros.sh | 3 ++- test/shell/test_runner.sh | 28 ++++++++++----------- test_dependency_versions.sh | 151 ++++++++++++++++++++... test_version.sh | 2 -- tools/bazel.rc.buildkite | 9 +++++-- 23 files changed, 288 insertions(+), 154 deletions(-) ``` --- The following Bazel Slack thread pointed out the apparent incompatibility with the new Bazel 9.0.0 release: - https://bazelbuild.slack.com/archives/CDCKJ2KFZ/p1768383285232129 - https://github.com/bazelbuild/bazel/releases/tag/9.0.0 This happened because Bazel 9 now sets `--incompatible_enable_proto_toolchain_resolution` by default: - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution Since the `scala_proto` implementation depends on this flag, this broke projects that didn't configure the `rules_scala` prebuilt `protoc` toolchain. This change fixes that problem while ensuring seamless compatibility with the `protobuf` v33.4 prebuilt protoc toolchain. We will likely release v7.2.0 as soon as this change lands. After that, we can bump other dependency versions in a patch level release, including `bazel-worker-api` as soon as v0.0.10 appears.
1 parent 175f4f4 commit a939c89

File tree

82 files changed

+1438
-814
lines changed

Some content is hidden

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

82 files changed

+1438
-814
lines changed

.bazelci/presubmit.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,62 @@ validate_config: 1
33

44
matrix:
55
bcr_platform: ["debian10", "macos", "ubuntu2004", "windows"]
6-
bcr_bazel: [7.x, 8.x, rolling, last_green]
6+
bcr_bazel: [7.x, 8.x, 9.x, rolling, last_green]
77

88
tasks:
99
ubuntu2004:
1010
name: "bazel test //test/..."
1111
platform: ubuntu2004
1212
shell_commands:
13-
- mv tools/bazel.rc.buildkite tools/bazel.rc
14-
- echo "import %workspace%/tools/bazel.rc" > .bazelrc
13+
- mv tools/bazel.rc.buildkite tools/bazel.rc
14+
- echo "import %workspace%/tools/bazel.rc" > .bazelrc
1515
build_targets:
16-
- "//test/..."
16+
- "//test/..."
1717
test_targets:
18-
- "//test/..."
18+
- "//test/..."
1919
macos:
2020
name: "bazel test //test/..."
2121
platform: macos
2222
shell_commands:
23-
# Disable local disk caching on CI.
24-
- mv tools/bazel.rc.buildkite tools/bazel.rc
25-
- echo "import %workspace%/tools/bazel.rc" > .bazelrc
23+
# Disable local disk caching on CI.
24+
- mv tools/bazel.rc.buildkite tools/bazel.rc
25+
- echo "import %workspace%/tools/bazel.rc" > .bazelrc
2626
build_targets:
27-
- "//test/..."
27+
- "//test/..."
2828
test_targets:
29-
- "//test/..."
29+
- "//test/..."
3030
test_rules_scala_linux:
3131
name: "./test_rules_scala"
3232
platform: ubuntu2004
3333
shell_commands:
34-
# Install xmllint
35-
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
36-
- "./test_rules_scala.sh"
34+
# Install xmllint
35+
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
36+
- "./test_rules_scala.sh"
3737
test_rules_scala_linux_last_green:
3838
name: "./test_rules_scala (last_green Bazel)"
3939
platform: ubuntu2004
4040
bazel: last_green
4141
shell_commands:
42-
# Install xmllint
43-
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
44-
- echo "common --lockfile_mode=update" >>.bazelrc
45-
- "./test_rules_scala.sh"
42+
# Install xmllint
43+
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
44+
- echo "common --lockfile_mode=update" >>.bazelrc
45+
- "./test_rules_scala.sh"
4646
soft_fail:
4747
- exit_status: "*"
4848
test_rules_scala_macos:
4949
name: "./test_rules_scala"
5050
platform: macos
5151
shell_commands:
52-
- "./test_rules_scala.sh"
52+
- "./test_rules_scala.sh"
5353
test_rules_scala_win:
5454
name: "./test_rules_scala"
5555
platform: windows
5656
environment:
5757
MSYS2_ARG_CONV_EXCL: "*"
5858
batch_commands:
59-
- "set PATH=/usr/bin;%PATH%" #Make sure bash uses msys commands over windows commands. (i.e. find).
60-
- "bash -lc \"pacman --noconfirm --needed -S libxml2\"" #tests require xmllint
61-
- "bash test_rules_scala.sh"
59+
- "set PATH=/usr/bin;%PATH%" #Make sure bash uses msys commands over windows commands. (i.e. find).
60+
- 'bash -lc "pacman --noconfirm --needed -S libxml2"' #tests require xmllint
61+
- "bash test_rules_scala.sh"
6262
test_coverage_linux:
6363
name: "./test_coverage"
6464
platform: ubuntu2004
@@ -73,27 +73,27 @@ tasks:
7373
name: "./test_reproducibility.sh"
7474
platform: ubuntu1804
7575
shell_commands:
76-
- "./test_reproducibility.sh"
76+
- "./test_reproducibility.sh"
7777
test_reproducibility_macos:
7878
name: "./test_reproducibility.sh"
7979
platform: macos
8080
shell_commands:
81-
- "./test_reproducibility.sh"
81+
- "./test_reproducibility.sh"
8282
versions_linux:
8383
name: "./test_version.sh"
8484
platform: ubuntu2004
8585
shell_commands:
86-
- "./test_version.sh"
86+
- "./test_version.sh"
8787
versions_macos:
8888
name: "./test_version.sh"
8989
platform: macos
9090
shell_commands:
91-
- "./test_version.sh"
91+
- "./test_version.sh"
9292
thirdparty_version_linux:
9393
name: "./test_thirdparty_version.sh"
9494
platform: ubuntu2204_java17
9595
shell_commands:
96-
- "./test_thirdparty_version.sh"
96+
- "./test_thirdparty_version.sh"
9797
examples_linux:
9898
name: "./test_examples"
9999
platform: ubuntu2004
@@ -108,7 +108,7 @@ tasks:
108108
name: "./test_lint.sh"
109109
platform: ubuntu2004
110110
shell_commands:
111-
- "./test_lint.sh"
111+
- "./test_lint.sh"
112112
test_rules_scala_jdk21:
113113
name: "./test_rules_scala with jdk21"
114114
platform: ubuntu2004
@@ -125,26 +125,26 @@ tasks:
125125
name: "dt_patches/dt_patch_test"
126126
platform: ubuntu2004
127127
shell_commands:
128-
- "dt_patches/dt_patch_test.sh"
128+
- "dt_patches/dt_patch_test.sh"
129129
dependency_versions_linux:
130130
name: "./test_dependency_versions"
131131
platform: ubuntu2004
132132
shell_commands:
133-
- "./test_dependency_versions.sh"
133+
- "./test_dependency_versions.sh"
134134
dependency_versions_macos:
135135
name: "./test_dependency_versions"
136136
platform: macos
137137
shell_commands:
138-
- "./test_dependency_versions.sh"
138+
- "./test_dependency_versions.sh"
139139
dependency_versions_windows:
140140
name: "./test_dependency_versions"
141141
platform: windows
142142
environment:
143143
MSYS2_ARG_CONV_EXCL: "*"
144144
batch_commands:
145-
- "set PATH=/usr/bin;%PATH%" #Make sure bash uses msys commands over windows commands. (i.e. find).
146-
- "bash -lc \"pacman --noconfirm --needed -S libxml2\"" #tests require xmllint
147-
- "bash ./test_dependency_versions.sh" # script removes ./ from BASH_SOURCE
145+
- "set PATH=/usr/bin;%PATH%" #Make sure bash uses msys commands over windows commands. (i.e. find).
146+
- 'bash -lc "pacman --noconfirm --needed -S libxml2"' #tests require xmllint
147+
- "bash ./test_dependency_versions.sh" # script removes ./ from BASH_SOURCE
148148
bcr_presubmit:
149149
# Keep in sync with .bcr/presubmit.yml.
150150
name: "BCR {bcr_bazel}"

.bazelrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ common --lockfile_mode=error
1515
# https://github.com/bazelbuild/rules_java/releases/tag/8.12.0
1616
#common --repositories_without_autoloads=bazel_features_version,bazel_features_globals
1717

18-
# Remove if protocol compiler toolchainization ever becomes the default.
18+
# Remove once Bazel 9 becomes the default.
1919
# - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
20-
# - https://docs.google.com/document/d/1CE6wJHNfKbUPBr7-mmk_0Yo3a4TaqcTPE0OWNuQkhPs/edit
20+
# - https://github.com/bazelbuild/bazel/releases/tag/9.0.0
21+
# - https://blog.bazel.build/2026/01/20/bazel-9.html#prebuilt-protobuf-compiler
2122
common --incompatible_enable_proto_toolchain_resolution
2223

24+
# Remove once protobuf 34 becomes the default.
25+
# - https://protobuf.dev/news/2026-01-16/
26+
common --@rules_scala//protoc:prefer_prebuilt_protoc
27+
2328
build --enable_platform_specific_config
2429

2530
#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.

.bcr/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ bcr_test_module:
33
module_path: "examples/crossbuild"
44
matrix:
55
platform: ["debian10", "macos", "ubuntu2004", "windows"]
6-
bazel: [7.x, 8.x, rolling, last_green]
6+
bazel: [7.x, 8.x, 9.x, rolling, last_green]
77
tasks:
88
run_tests:
99
name: "Build and test the example module"

.github/workflows/release_prep.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ TAG="$1"
77
VERSION="${TAG#v}"
88
PREFIX="rules_scala-${VERSION}"
99
ARCHIVE="rules_scala-$TAG.tar.gz"
10-
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
10+
11+
# Don't archive .bazelversion symlinks, as they break Bazel as of
12+
# bazelbuild/bazel@f942a706a39f9803e5611b1973172ece361197ac.
13+
# See: https://github.com/bazelbuild/bazel-worker-api/issues/21
14+
git archive --format=tar --prefix=${PREFIX}/ ${TAG} ':!:**.bazelversion' |
15+
gzip > $ARCHIVE
1116
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
1217

1318
cat << EOF

MODULE.bazel

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
module(
44
name = "rules_scala",
5-
version = "7.1.6",
65
bazel_compatibility = [">=7.1.0"],
76
compatibility_level = 7,
87
)
@@ -45,8 +44,9 @@ single_version_override(
4544
version = "9.3.0",
4645
)
4746

48-
# TODO: remove this dep, the repo is deprecated and archived.
49-
# All public API symbols are aliased to @protobuf
47+
# TODO: Remove this dep once protobuf 33.4 becomes the minimum supported
48+
# version. The repo is deprecated and archived and all public API symbols are
49+
# aliased to @protobuf.
5050
bazel_dep(name = "rules_proto", version = "7.1.0")
5151
bazel_dep(
5252
name = "protobuf",
@@ -58,20 +58,11 @@ bazel_dep(
5858
# protocolbuffers/protobuf#19679 appears in a published release.
5959
single_version_override(
6060
module_name = "protobuf",
61-
patch_strip = 1,
62-
patches = ["//protoc:0001-protobuf-19679-rm-protoc-dep.patch"],
63-
version = "33.1",
61+
version = "33.4",
6462
)
6563

6664
# See //src/java/io/bazel/rulesscala/worker:worker_protocol_java_proto.
67-
bazel_dep(name = "bazel_worker_api", version = "0.0.6")
68-
69-
scala_protoc = use_extension(
70-
"//scala/extensions:protoc.bzl",
71-
"scala_protoc",
72-
dev_dependency = True,
73-
)
74-
use_repo(scala_protoc, "rules_scala_protoc_toolchains")
65+
bazel_dep(name = "bazel_worker_api", version = "0.0.9")
7566

7667
scala_config = use_extension(
7768
"//scala/extensions:config.bzl",
@@ -99,11 +90,6 @@ use_repo(
9990

10091
# Register some of our testing toolchains first when building our repo.
10192
register_toolchains(
102-
# This is optional, but still safe to include even when not using
103-
# `--incompatible_enable_proto_toolchain_resolution`. Requires invoking the
104-
# `scala_protoc_toolchains` repo rule. Register this toolchain before any
105-
# others.
106-
"@rules_scala_protoc_toolchains//...:all",
10793
"//scala:unused_dependency_checker_error_toolchain",
10894
"//test/proto:scalapb_toolchain",
10995
"//test/toolchains:java21_toolchain_definition",

MODULE.bazel.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)