Skip to content

Commit 3a78fcc

Browse files
authored
Merge pull request #18820 from comius/prepare-for-bazel-8
Cherry-picks for Bazel 8
2 parents 72d2975 + 111584f commit 3a78fcc

19 files changed

+166
-31
lines changed

.github/workflows/test_cpp.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ jobs:
4545
cache_key: Bazel7
4646
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:7.1.2-cf84e92285ca133b9c8104ad7b14d70e953cbb8e"
4747
targets: "//src/... //third_party/utf8_range/..."
48-
- config: { name: "Bazel7 with Bzlmod", flags: --enable_bzlmod --enable_workspace }
48+
# TODO: remove -Wno-unreachable-code" when dropping C++14
49+
- config: { name: "Bazel7 with Bzlmod", flags: --enable_bzlmod --enable_workspace --per_file_copt=.*/absl/strings/string_view.h@-Wno-unreachable-code --cxxopt="-Wno-self-assign-overloaded" }
4950
cache_key: Bazel7bzlmod
5051
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:7.1.2-cf84e92285ca133b9c8104ad7b14d70e953cbb8e"
5152
targets: "//src/... //third_party/utf8_range/..."

MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bazel_dep(
3030

3131
bazel_dep(
3232
name = "rules_cc",
33-
version = "0.0.9",
33+
version = "0.0.13",
3434
)
3535

3636
bazel_dep(
@@ -84,6 +84,11 @@ bazel_dep(
8484
repo_name = "proto_bazel_features",
8585
)
8686

87+
bazel_dep(
88+
name = "rules_shell",
89+
version = "0.2.0"
90+
)
91+
8792
# Proto toolchains
8893
register_toolchains("//bazel/private/toolchains:all")
8994

bazel/BUILD.bazel

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,31 @@ bzl_library(
1313
name = "proto_library_bzl",
1414
srcs = ["proto_library.bzl"],
1515
visibility = ["//visibility:public"],
16+
deps = [
17+
"//bazel/private:bazel_proto_library_rule_bzl",
18+
"@proto_bazel_features//:features",
19+
],
1620
)
1721

1822
bzl_library(
1923
name = "cc_proto_library_bzl",
2024
srcs = ["cc_proto_library.bzl"],
2125
visibility = ["//visibility:public"],
26+
deps = ["//bazel/private:bazel_cc_proto_library_bzl"],
2227
)
2328

2429
bzl_library(
2530
name = "java_proto_library_bzl",
2631
srcs = ["java_proto_library.bzl"],
2732
visibility = ["//visibility:public"],
33+
deps = ["//bazel/private:bazel_java_proto_library_rule_bzl"],
2834
)
2935

3036
bzl_library(
3137
name = "java_lite_proto_library_bzl",
3238
srcs = ["java_lite_proto_library.bzl"],
3339
visibility = ["//visibility:public"],
40+
deps = ["//bazel/private:java_lite_proto_library_bzl"],
3441
)
3542

3643
bzl_library(
@@ -56,3 +63,19 @@ bzl_library(
5663
visibility = ["//visibility:public"],
5764
deps = ["//bazel/private:upb_proto_library_internal_bzl"],
5865
)
66+
67+
# The data in this target is exposed in //bazel/private:for_bazel_tests
68+
filegroup(
69+
name = "for_bazel_tests",
70+
testonly = True,
71+
srcs = [
72+
"BUILD.bazel",
73+
":cc_proto_library_bzl",
74+
":java_lite_proto_library_bzl",
75+
":proto_library_bzl",
76+
":py_proto_library_bzl",
77+
"//bazel/common:for_bazel_tests",
78+
"//bazel/toolchains:for_bazel_tests",
79+
],
80+
visibility = ["//bazel/private:__pkg__"],
81+
)

bazel/common/BUILD

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bzl_library(
1010
visibility = ["//visibility:public"],
1111
deps = [
1212
":proto_lang_toolchain_info_bzl",
13+
"//bazel/private:native_bzl",
1314
"//bazel/private:toolchain_helpers_bzl",
1415
"@proto_bazel_features//:features",
1516
],
@@ -38,9 +39,13 @@ bzl_library(
3839
)
3940

4041
filegroup(
41-
name = "bazel_osx_p4deps",
42-
srcs = glob(["**"]) + ["@proto_bazel_features//:features"],
43-
visibility = [
44-
"//bazel:__pkg__",
42+
name = "for_bazel_tests",
43+
testonly = True,
44+
srcs = [
45+
"BUILD",
46+
"proto_common_bzl",
47+
"proto_info_bzl",
48+
"proto_lang_toolchain_info_bzl",
4549
],
50+
visibility = ["//bazel:__pkg__"],
4651
)

bazel/private/BUILD

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2-
load("//bazel/private:native_bool_flag.bzl", "native_bool_flag")
2+
load(":native_bool_flag.bzl", "native_bool_flag")
33

44
package(default_applicable_licenses = ["//:license"])
55

@@ -52,32 +52,84 @@ bzl_library(
5252
visibility = ["//bazel:__subpackages__"],
5353
)
5454

55+
bzl_library(
56+
name = "proto_info_bzl",
57+
srcs = ["proto_info.bzl"],
58+
visibility = ["//bazel:__subpackages__"],
59+
)
60+
5561
bzl_library(
5662
name = "bazel_proto_library_rule_bzl",
5763
srcs = [
5864
"bazel_proto_library_rule.bzl",
5965
],
6066
visibility = ["//bazel:__subpackages__"],
6167
deps = [
68+
":toolchain_helpers_bzl",
6269
"//bazel/common:proto_common_bzl",
6370
"//bazel/common:proto_info_bzl",
64-
"//bazel/private:toolchain_helpers_bzl",
6571
"@bazel_skylib//lib:paths",
6672
"@bazel_skylib//rules:common_settings",
6773
"@proto_bazel_features//:features",
6874
],
6975
)
7076

77+
bzl_library(
78+
name = "bazel_java_proto_library_rule_bzl",
79+
srcs = [
80+
"bazel_java_proto_library_rule.bzl",
81+
"java_proto_support.bzl",
82+
],
83+
visibility = ["//bazel:__subpackages__"],
84+
deps = [
85+
":toolchain_helpers_bzl",
86+
"//bazel/common:proto_common_bzl",
87+
"//bazel/common:proto_info_bzl",
88+
"@rules_java//java/common",
89+
],
90+
)
91+
92+
bzl_library(
93+
name = "java_lite_proto_library_bzl",
94+
srcs = [
95+
"java_lite_proto_library.bzl",
96+
"java_proto_support.bzl",
97+
],
98+
visibility = ["//bazel:__subpackages__"],
99+
deps = [
100+
":toolchain_helpers_bzl",
101+
"//bazel/common:proto_common_bzl",
102+
"//bazel/common:proto_info_bzl",
103+
"@rules_java//java/common",
104+
],
105+
)
106+
107+
bzl_library(
108+
name = "bazel_cc_proto_library_bzl",
109+
srcs = [
110+
"bazel_cc_proto_library.bzl",
111+
"cc_proto_support.bzl",
112+
],
113+
visibility = ["//bazel:__subpackages__"],
114+
deps = [
115+
":toolchain_helpers_bzl",
116+
"//bazel/common:proto_common_bzl",
117+
"//bazel/common:proto_info_bzl",
118+
"@proto_bazel_features//:features",
119+
"@rules_cc//cc:find_cc_toolchain_bzl",
120+
],
121+
)
122+
71123
bzl_library(
72124
name = "proto_toolchain_rule_bzl",
73125
srcs = [
74126
"proto_toolchain_rule.bzl",
75127
],
76128
visibility = ["//bazel:__subpackages__"],
77129
deps = [
130+
":toolchain_helpers_bzl",
78131
"//bazel/common:proto_common_bzl",
79132
"//bazel/common:proto_lang_toolchain_info_bzl",
80-
"//bazel/private:toolchain_helpers_bzl",
81133
],
82134
)
83135

@@ -131,10 +183,21 @@ native_bool_flag(
131183
visibility = ["//bazel:__subpackages__"],
132184
)
133185

186+
bzl_library(
187+
name = "native_bool_flag_bzl",
188+
srcs = ["native_bool_flag.bzl"],
189+
visibility = ["//visibility:private"],
190+
deps = ["@bazel_skylib//rules:common_settings"],
191+
)
192+
134193
filegroup(
135-
name = "bazel_osx_p4deps",
136-
srcs = glob(["**"]),
137-
visibility = [
138-
"//bazel:__pkg__",
194+
name = "for_bazel_tests",
195+
testonly = True,
196+
srcs = [
197+
"BUILD",
198+
":native_bool_flag_bzl",
199+
"//bazel:for_bazel_tests",
200+
"//bazel/private/toolchains:for_bazel_tests",
139201
],
202+
visibility = ["//visibility:public"],
140203
)

bazel/private/bazel_cc_proto_library.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
"""Bazel's implementation of cc_proto_library"""
99

1010
load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
11+
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
1112
load("//bazel/common:proto_common.bzl", "proto_common")
1213
load("//bazel/common:proto_info.bzl", "ProtoInfo")
1314
load("//bazel/private:cc_proto_support.bzl", "cc_proto_compile_and_link")
1415
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
1516

16-
_CC_PROTO_TOOLCHAIN = "//bazel/private:cc_toolchain_type"
17+
_CC_PROTO_TOOLCHAIN = Label("//bazel/private:cc_toolchain_type")
1718

1819
_ProtoCcFilesInfo = provider(fields = ["files"], doc = "Provide cc proto files.")
1920
_ProtoCcHeaderInfo = provider(fields = ["headers"], doc = "Provide cc proto headers.")

bazel/private/bazel_java_proto_library_rule.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ load("//bazel/common:proto_info.bzl", "ProtoInfo")
1212
load("//bazel/private:java_proto_support.bzl", "JavaProtoAspectInfo", "java_compile_for_protos", "java_info_merge_for_protos")
1313
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
1414

15-
_JAVA_PROTO_TOOLCHAIN = "//bazel/private:java_toolchain_type"
15+
_JAVA_PROTO_TOOLCHAIN = Label("//bazel/private:java_toolchain_type")
1616

1717
def _filter_provider(provider, *attrs):
1818
return [dep[provider] for attr in attrs for dep in attr if provider in dep]

bazel/private/cc_proto_support.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
load("@proto_bazel_features//:features.bzl", "bazel_features")
1111
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
12+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
13+
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
1214

1315
def get_feature_configuration(ctx, has_sources, extra_requested_features = []):
1416
"""Returns C++ feature configuration for compiling and linking generated C++ files.

bazel/private/java_lite_proto_library.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("//bazel/private:toolchain_helpers.bzl", "toolchains")
1616

1717
_PROTO_TOOLCHAIN_ATTR = "_aspect_proto_toolchain_for_javalite"
1818

19-
_JAVA_LITE_PROTO_TOOLCHAIN = "//bazel/private:javalite_toolchain_type"
19+
_JAVA_LITE_PROTO_TOOLCHAIN = Label("//bazel/private:javalite_toolchain_type")
2020

2121
def _aspect_impl(target, ctx):
2222
"""Generates and compiles Java code for a proto_library dependency graph.

bazel/private/toolchain_helpers.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ toolchains = struct(
4545
find_toolchain = _find_toolchain,
4646
if_legacy_toolchain = _if_legacy_toolchain,
4747
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = _incompatible_toolchain_resolution,
48-
PROTO_TOOLCHAIN = "//bazel/private:proto_toolchain_type",
48+
PROTO_TOOLCHAIN = Label("//bazel/private:proto_toolchain_type"),
4949
)

bazel/private/toolchains/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ toolchain(
7272
toolchain = "//java/lite:toolchain",
7373
toolchain_type = "@rules_java//java/proto:lite_toolchain_type",
7474
)
75+
76+
filegroup(
77+
name = "for_bazel_tests",
78+
testonly = True,
79+
srcs = [
80+
"BUILD.bazel",
81+
],
82+
visibility = [
83+
"//bazel/private:__pkg__",
84+
],
85+
)

bazel/toolchains/BUILD

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ bzl_library(
2828
)
2929

3030
filegroup(
31-
name = "bazel_osx_p4deps",
32-
srcs = glob(["**"]),
31+
name = "for_bazel_tests",
32+
testonly = True,
33+
srcs = [
34+
"BUILD",
35+
"proto_lang_toolchain_bzl",
36+
"proto_toolchain_bzl",
37+
],
3338
visibility = [
3439
"//bazel:__pkg__",
3540
],

build_defs/internal_shell.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Internal tools to migrate shell commands to Bazel as an intermediate step
33
to wider Bazelification.
44
"""
55

6+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
7+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
8+
69
def inline_sh_binary(
710
name,
811
srcs = [],
@@ -41,7 +44,7 @@ def inline_sh_binary(
4144
testonly = kwargs["testonly"] if "testonly" in kwargs else None,
4245
)
4346

44-
native.sh_binary(
47+
sh_binary(
4548
name = name,
4649
srcs = [name + "_genrule"],
4750
data = srcs + tools + deps,
@@ -86,7 +89,7 @@ def inline_sh_test(
8689
testonly = kwargs["testonly"] if "testonly" in kwargs else None,
8790
)
8891

89-
native.sh_test(
92+
sh_test(
9093
name = name,
9194
srcs = [name + "_genrule"],
9295
data = srcs + tools + deps,

conformance/defs.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE.
44
"""
55

6+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
7+
68
def conformance_test(
79
name,
810
testee,
@@ -31,7 +33,7 @@ def conformance_test(
3133
if maximum_edition:
3234
args = args + ["--maximum_edition %s" % maximum_edition]
3335

34-
native.sh_test(
36+
sh_test(
3537
name = name,
3638
srcs = ["//conformance:bazel_conformance_test_runner.sh"],
3739
data = [testee] + failure_lists + [

protobuf_deps.bzl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def protobuf_deps():
9090
)
9191

9292
if not native.existing_rule("rules_cc"):
93-
_github_archive(
93+
http_archive(
9494
name = "rules_cc",
95-
repo = "https://github.com/bazelbuild/rules_cc",
96-
commit = "c8c38f8c710cbbf834283e4777916b68261b359c", # 0.0.9
97-
sha256 = "5f862a44bbd032e1b48ed53c9c211ba2a1da60e10c5baa01c97369c249299ecb",
95+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
96+
sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
97+
strip_prefix = "rules_cc-0.0.13",
9898
)
9999

100100
if not native.existing_rule("rules_java"):
@@ -104,6 +104,14 @@ def protobuf_deps():
104104
sha256 = "6f3ce0e9fba979a844faba2d60467843fbf5191d8ca61fa3d2ea17655b56bb8c",
105105
)
106106

107+
if not native.existing_rule("rules_shell"):
108+
http_archive(
109+
name = "rules_shell",
110+
sha256 = "410e8ff32e018b9efd2743507e7595c26e2628567c42224411ff533b57d27c28",
111+
strip_prefix = "rules_shell-0.2.0",
112+
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.2.0/rules_shell-v0.2.0.tar.gz",
113+
)
114+
107115
if not native.existing_rule("proto_bazel_features"):
108116
proto_bazel_features(name = "proto_bazel_features")
109117

0 commit comments

Comments
 (0)