Skip to content

Commit f08d703

Browse files
keithcopybara-github
authored andcommitted
Add support for bazel 9.x (#26201)
This doesn't flip the default bazel version, but instead makes this repo compatible with the current version and bazel 9.x. The primary changes for 9.x support are adding new load statements for things that were previously built in. This cascaded into a few dep updates to pull in their missing load statement fixes. Closes #26201 COPYBARA_INTEGRATE_REVIEW=#26201 from keith:ks/add-support-for-bazel-9.x e8192d8 PiperOrigin-RevId: 878654773
1 parent 71a03be commit f08d703

17 files changed

Lines changed: 405 additions & 34 deletions

File tree

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ build --features=layering_check
3737

3838
common --enable_platform_specific_config
3939

40+
common --incompatible_check_testonly_for_output_files
41+
4042
# Use clang-cl by default on Windows (see https://github.com/protocolbuffers/protobuf/issues/20085).
4143
build:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl --extra_execution_platforms=//build_defs:x64_windows-clang-cl --host_platform=//build_defs:x64_windows-clang-cl

.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
44
matrix:
55
platform: ["debian10", "macos", "macos_arm64", "ubuntu2004", "windows"]
6-
bazel: [8.x]
6+
bazel: [8.x, 9.x]
77

88
tasks:
99
verify_targets:

.github/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
load("@build_bazel_apple_support//xcode:xcode_config.bzl", "xcode_config")
2+
load("@build_bazel_apple_support//xcode:xcode_version.bzl", "xcode_version")
3+
14
# This information is extracted from the MacOS runner specs located at:
25
# https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md
36
#

MODULE.bazel

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ module(
1313
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
1414
# Thus the highest version in their module graph is resolved.
1515

16-
bazel_dep(name = "apple_support", version = "1.15.1", repo_name = "build_bazel_apple_support")
16+
bazel_dep(name = "apple_support", version = "1.16.0", repo_name = "build_bazel_apple_support")
1717

18-
# Keep apple_support on 1.15.1 for now to avoid this issue:
19-
# https://github.com/bazelbuild/apple_support/issues/316
20-
single_version_override(
21-
module_name = "apple_support",
22-
version = "1.15.1",
23-
)
18+
# Unused but must be pinned to avoid old broken versions
19+
bazel_dep(name = "rules_proto", version = "7.1.0")
2420

2521
#ifndef PROTO2_OPENSOURCE
2622
# LINT.IfChange
@@ -36,16 +32,16 @@ bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
3632
# other dependencies
3733
bazel_dep(name = "bazel_features", version = "1.33.0", repo_name = "proto_bazel_features")
3834
bazel_dep(name = "bazel_skylib", version = "1.9.0")
39-
bazel_dep(name = "jsoncpp", version = "1.9.6")
35+
bazel_dep(name = "jsoncpp", version = "1.9.6.bcr.1")
4036
bazel_dep(name = "rules_java", version = "8.6.1")
4137
bazel_dep(name = "rules_jvm_external", version = "6.7")
42-
bazel_dep(name = "rules_kotlin", version = "1.9.6")
38+
bazel_dep(name = "rules_kotlin", version = "2.2.2")
4339
bazel_dep(name = "rules_license", version = "1.0.0")
4440
bazel_dep(name = "rules_pkg", version = "1.0.1")
4541
bazel_dep(name = "rules_python", version = "1.6.0")
4642
bazel_dep(name = "rules_rust", version = "0.63.0")
4743

48-
bazel_dep(name = "rules_ruby", version = "0.17.3", dev_dependency = True)
44+
bazel_dep(name = "rules_ruby", version = "0.20.1", dev_dependency = True)
4945

5046
# Workaround for https://github.com/bazelbuild/bazel-central-registry/issues/4230
5147
# rules_fuzzing 0.5.3 is not yet available in BCR.
@@ -65,12 +61,11 @@ single_version_override(
6561
patch_strip = 1,
6662
patches = [
6763
"@com_google_protobuf//:Disable_bundle_install.patch",
68-
"@com_google_protobuf//:Neverlink_jruby_jars.patch",
6964
],
70-
version = "0.17.3",
7165
)
7266

73-
bazel_dep(name = "rules_shell", version = "0.2.0")
67+
bazel_dep(name = "aspect_bazel_lib", version = "2.22.5")
68+
bazel_dep(name = "rules_shell", version = "0.6.1")
7469
bazel_dep(name = "platforms", version = "0.0.11")
7570

7671
# Ruby toolchains
@@ -267,7 +262,7 @@ protobuf_maven_dev.install(
267262
)
268263
use_repo(protobuf_maven_dev, "protobuf_maven_dev")
269264

270-
bazel_dep(name = "googletest", version = "1.15.2", dev_dependency = True)
265+
bazel_dep(name = "googletest", version = "1.17.0.bcr.2", dev_dependency = True)
271266
bazel_dep(name = "rules_buf", version = "0.3.0", dev_dependency = True)
272267
bazel_dep(name = "rules_testing", version = "0.9.0", dev_dependency = True)
273268
bazel_dep(
@@ -302,6 +297,7 @@ archive_override(
302297
"@com_google_protobuf//:patches/protobuf_v25/0005-Make-rules_ruby-a-dev-only-dependency.patch",
303298
"@com_google_protobuf//:patches/protobuf_v25/0006-Add-repo_name.patch",
304299
"@com_google_protobuf//:patches/protobuf_v25/0007-Java-bazel8.patch",
300+
"@com_google_protobuf//:patches/protobuf_v25/0008-bazel9.patch",
305301
],
306302
strip_prefix = "protobuf-25.0",
307303
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz"],
@@ -314,6 +310,7 @@ archive_override(
314310
patch_strip = 1,
315311
patches = [
316312
"@com_google_protobuf//:patches/protobuf_v29/0001-Update-module-name.patch",
313+
"@com_google_protobuf//:patches/protobuf_v29/0002-bazel9.patch",
317314
],
318315
strip_prefix = "protobuf-29.0",
319316
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v29.0/protobuf-29.0.tar.gz"],

Neverlink_jruby_jars.patch

Lines changed: 0 additions & 16 deletions
This file was deleted.

bazel/private/file_concat/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
2+
13
cc_binary(
24
name = "file_concat",
35
srcs = [

bazel/tests/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
23
load("//bazel:proto_descriptor_set.bzl", "proto_descriptor_set")
34
load("//bazel:proto_library.bzl", "proto_library")
45
load(":bazel_proto_library_tests.bzl", "bazel_proto_library_test_suite")

bazel/tests/bazel_proto_library_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def _test_experimental_proto_descriptor_sets_include_source_info(name):
649649
name = name,
650650
target = name + "_a_proto",
651651
impl = _test_experimental_proto_descriptor_sets_include_source_info_impl,
652-
config_settings = {"//bazel/flags:experimental_proto_descriptor_sets_include_source_info": True},
652+
config_settings = {"@@//bazel/flags:experimental_proto_descriptor_sets_include_source_info": True},
653653
)
654654

655655
def _test_experimental_proto_descriptor_sets_include_source_info_impl(env, target):

cmake/dependencies_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import print_function
1919

2020
import os
21+
import re
2122
import sys
2223
import textwrap
2324

@@ -70,6 +71,9 @@ def module(self, *args, **kwargs):
7071
pass
7172

7273
def bazel_dep(self, name, version, **kwargs):
74+
# Strip BCR-specific version suffixes (e.g. 1.17.0.bcr.2 -> 1.17.0)
75+
# since they don't correspond to upstream git tags.
76+
version = re.sub(r"\.bcr\.\d+", "", version)
7377
self.converter.toplevel += textwrap.dedent(
7478
"""\
7579
set(%(name)s-version "%(version)s")

editions/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ cc_binary(
117117

118118
cc_library(
119119
name = "defaults_test_embedded",
120+
testonly = True,
120121
hdrs = [
121122
"defaults_test_embedded.h",
122123
"defaults_test_embedded_base64.h",

0 commit comments

Comments
 (0)