Skip to content

Commit 33842ce

Browse files
authored
bazel-registry: Add protobuf@33.4.envoy (#3665)
Signed-off-by: Ryan Northey <ryan@synca.io>
1 parent 140b964 commit 33842ce

File tree

4 files changed

+332
-0
lines changed

4 files changed

+332
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
2+
# https://github.com/protocolbuffers/protobuf/issues/14313
3+
4+
module(
5+
name = "protobuf",
6+
version = "33.4.envoy",
7+
compatibility_level = 1,
8+
repo_name = "com_google_protobuf",
9+
)
10+
11+
# LOWER BOUND dependency versions.
12+
# Bzlmod follows MVS:
13+
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
14+
# Thus the highest version in their module graph is resolved.
15+
16+
# These dependencies must be declared before the other rules dependencies.
17+
bazel_dep(name = "rules_apple", version = "3.16.0", repo_name = "build_bazel_rules_apple")
18+
bazel_dep(name = "apple_support", version = "1.15.1", repo_name = "build_bazel_apple_support")
19+
20+
# Keep apple_support on 1.15.1 for now to avoid this issue:
21+
# https://github.com/bazelbuild/apple_support/issues/316
22+
single_version_override(
23+
module_name = "apple_support",
24+
version = "1.15.1",
25+
)
26+
27+
#ifndef PROTO2_OPENSOURCE
28+
# LINT.IfChange
29+
#endif // PROTO2_OPENSOURCE
30+
# protoc dependencies
31+
bazel_dep(name = "abseil-cpp", version = "20250512.1")
32+
bazel_dep(name = "rules_cc", version = "0.0.17")
33+
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
34+
#ifndef PROTO2_OPENSOURCE
35+
# LINT.ThenChange(//depot/google3/third_party/protobuf/compiler/notices.h)
36+
#endif // PROTO2_OPENSOURCE
37+
38+
# other dependencies
39+
bazel_dep(name = "bazel_features", version = "1.33.0", repo_name = "proto_bazel_features")
40+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
41+
bazel_dep(name = "jsoncpp", version = "1.9.6")
42+
bazel_dep(name = "rules_java", version = "8.6.1")
43+
bazel_dep(name = "rules_jvm_external", version = "6.7")
44+
bazel_dep(name = "rules_kotlin", version = "1.9.6")
45+
bazel_dep(name = "rules_license", version = "1.0.0")
46+
bazel_dep(name = "rules_pkg", version = "1.0.1")
47+
bazel_dep(name = "rules_python", version = "1.6.0")
48+
49+
# Pin to rules_proto to 7.1.0 to avoid toolchain incompatibilities when
50+
# --incompatible_enable_proto_toolchain_resolution=true in Bazel 7.
51+
# rules_proto 7.0.2 from deps incorrectly rules_proto's toolchain_type but protobuf's toolchain, but
52+
# 7.1.0 uses protobuf's toolchain and toolchain_type.
53+
bazel_dep(name = "rules_proto", version = "7.1.0")
54+
55+
bazel_dep(name = "rules_shell", version = "0.2.0")
56+
bazel_dep(name = "platforms", version = "0.0.11")
57+
58+
# Define toolchains that use pre-built protoc binaries.
59+
prebuilt_protoc = use_extension("//bazel/private:prebuilt_protoc_extension.bzl", "protoc")
60+
use_repo(
61+
prebuilt_protoc,
62+
"prebuilt_protoc.linux_aarch_64",
63+
"prebuilt_protoc.osx_aarch_64",
64+
"prebuilt_protoc.linux_ppcle_64",
65+
"prebuilt_protoc.linux_s390_64",
66+
"prebuilt_protoc.linux_x86_32",
67+
"prebuilt_protoc.linux_x86_64",
68+
"prebuilt_protoc.osx_x86_64",
69+
"prebuilt_protoc.win32",
70+
"prebuilt_protoc.win64",
71+
)
72+
73+
# However this registration only matters if the config_setting for prefer_prebuilt_protoc is true,
74+
# using --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
75+
register_toolchains("//bazel/private/toolchains/prebuilt:all")
76+
77+
# From-source protobuf toolchains
78+
# Fallback if nothing is already registered
79+
register_toolchains("//bazel/private/toolchains:all")
80+
81+
# Keep this list minimal; these dependencies will be part of the common `maven` install and could affect end-user projects.
82+
PROTOBUF_MAVEN_ARTIFACTS = [
83+
"com.google.code.findbugs:jsr305:3.0.2",
84+
"com.google.code.gson:gson:2.8.9",
85+
"com.google.errorprone:error_prone_annotations:2.5.1",
86+
"com.google.j2objc:j2objc-annotations:2.8",
87+
"com.google.guava:guava:32.0.1-jre",
88+
]
89+
90+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
91+
maven.install(
92+
artifacts = PROTOBUF_MAVEN_ARTIFACTS,
93+
lock_file = "//:maven_install.json",
94+
repositories = [
95+
"https://repo1.maven.org/maven2",
96+
"https://repo.maven.apache.org/maven2",
97+
],
98+
)
99+
100+
# Use the default "maven" namespace because protobuf java targets are exposed to users
101+
# See https://github.com/protocolbuffers/protobuf/issues/21177
102+
use_repo(maven, "maven")
103+
104+
# Temporarily pin transitive dependency for https://github.com/bazelbuild/bazel/issues/24426
105+
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")
106+
107+
# For clang-cl configuration
108+
cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
109+
use_repo(cc_configure, "local_config_cc")
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
diff --git a/BUILD.bazel b/BUILD.bazel
2+
index 9e76da895..8d5f4f46a 100644
3+
--- a/BUILD.bazel
4+
+++ b/BUILD.bazel
5+
@@ -28,6 +28,12 @@ exports_files(
6+
visibility = ["//cmake:__pkg__"],
7+
)
8+
9+
+label_flag(
10+
+ name = "zlib",
11+
+ build_setting_default = "@zlib",
12+
+ visibility = ["//visibility:public"],
13+
+)
14+
+
15+
################################################################################
16+
# Well Known Types Proto Library Rules
17+
#
18+
@@ -354,13 +360,83 @@ alias(
19+
)
20+
21+
cc_binary(
22+
- name = "protoc",
23+
+ name = "compiled_protoc",
24+
copts = COPTS,
25+
linkopts = LINK_OPTS,
26+
visibility = ["//visibility:public"],
27+
deps = ["//src/google/protobuf/compiler:protoc_lib_stage1"],
28+
)
29+
30+
+# Lifted from `rules_proto`
31+
+config_setting(
32+
+ name = "linux-aarch_64",
33+
+ constraint_values = [
34+
+ "@platforms//os:linux",
35+
+ "@platforms//cpu:aarch64",
36+
+ ],
37+
+)
38+
+
39+
+config_setting(
40+
+ name = "linux-x86_64",
41+
+ constraint_values = [
42+
+ "@platforms//os:linux",
43+
+ "@platforms//cpu:x86_64",
44+
+ ],
45+
+)
46+
+
47+
+config_setting(
48+
+ name = "linux-ppcle_64",
49+
+ constraint_values = [
50+
+ "@platforms//os:linux",
51+
+ "@platforms//cpu:ppc64le",
52+
+ ],
53+
+)
54+
+
55+
+config_setting(
56+
+ name = "osx-aarch_64",
57+
+ constraint_values = [
58+
+ "@platforms//os:osx",
59+
+ "@platforms//cpu:aarch64",
60+
+ ],
61+
+)
62+
+
63+
+config_setting(
64+
+ name = "osx-x86_64",
65+
+ constraint_values = [
66+
+ "@platforms//os:osx",
67+
+ "@platforms//cpu:x86_64",
68+
+ ],
69+
+)
70+
+
71+
+config_setting(
72+
+ name = "win64",
73+
+ constraint_values = [
74+
+ "@platforms//os:windows",
75+
+ "@platforms//cpu:x86_64",
76+
+ ],
77+
+)
78+
+
79+
+# Use precompiled binaries where possible.
80+
+alias(
81+
+ name = "protoc",
82+
+ actual = select({
83+
+ ":linux-aarch_64": "@prebuilt_protoc.linux_aarch_64//:protoc",
84+
+ ":linux-x86_64": "@prebuilt_protoc.linux_x86_64//:protoc",
85+
+ ":linux-ppcle_64": "@prebuilt_protoc.linux_ppcle_64//:protoc",
86+
+ ":osx-aarch_64": "@prebuilt_protoc.osx_aarch_64//:protoc",
87+
+ ":osx-x86_64": "@prebuilt_protoc.osx_x86_64//:protoc",
88+
+ ":win64": "@prebuilt_protoc.win64//:protoc",
89+
+ "//conditions:default": ":compiled_protoc",
90+
+ }),
91+
+ visibility = ["//visibility:public"],
92+
+)
93+
+
94+
+alias(
95+
+ name = "protobuf_python_genproto",
96+
+ actual = "//python:well_known_types_py_pb2_genproto",
97+
+ visibility = ["//visibility:public"],
98+
+)
99+
+
100+
cc_binary(
101+
name = "protoc_stage0",
102+
copts = COPTS,
103+
diff --git a/bazel/private/prebuilt_protoc_toolchain.bzl b/bazel/private/prebuilt_protoc_toolchain.bzl
104+
index b583e35d6..75e7642c3 100644
105+
--- a/bazel/private/prebuilt_protoc_toolchain.bzl
106+
+++ b/bazel/private/prebuilt_protoc_toolchain.bzl
107+
@@ -32,10 +32,24 @@ def _prebuilt_protoc_repo_impl(rctx):
108+
109+
rctx.file("BUILD.bazel", """\
110+
# Generated by @protobuf//bazel/private:prebuilt_protoc_toolchain.bzl
111+
+load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
112+
load("@com_google_protobuf//bazel/toolchains:proto_toolchain.bzl", "proto_toolchain")
113+
114+
package(default_visibility = ["//visibility:public"])
115+
116+
+# For rules that need single-file output
117+
+filegroup(
118+
+ name = "protoc",
119+
+ srcs = ["{protoc_label}"],
120+
+)
121+
+
122+
+# For `bazel run`
123+
+native_binary(
124+
+ name = "protoc_bin",
125+
+ src = "{protoc_label}",
126+
+ out = "protoc_runner",
127+
+)
128+
+
129+
proto_toolchain(
130+
name = "prebuilt_protoc_toolchain",
131+
proto_compiler = "{protoc_label}",
132+
diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl
133+
index c0116bd76..5ce341c74 100644
134+
--- a/build_defs/cpp_opts.bzl
135+
+++ b/build_defs/cpp_opts.bzl
136+
@@ -18,6 +18,7 @@ COPTS = select({
137+
],
138+
"//conditions:default": [
139+
"-Wno-sign-compare",
140+
+ "-Wno-deprecated-declarations",
141+
],
142+
})
143+
144+
diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel
145+
index 475556bf5..ef434e99b 100644
146+
--- a/src/google/protobuf/BUILD.bazel
147+
+++ b/src/google/protobuf/BUILD.bazel
148+
@@ -24,6 +24,23 @@ package(
149+
],
150+
)
151+
152+
+exports_files(
153+
+ [
154+
+ "any.proto",
155+
+ "api.proto",
156+
+ "descriptor.proto",
157+
+ "duration.proto",
158+
+ "empty.proto",
159+
+ "field_mask.proto",
160+
+ "source_context.proto",
161+
+ "struct.proto",
162+
+ "timestamp.proto",
163+
+ "type.proto",
164+
+ "wrappers.proto",
165+
+ ],
166+
+ visibility = ["//visibility:public"],
167+
+)
168+
+
169+
proto_library(
170+
name = "any_proto",
171+
srcs = ["any.proto"],
172+
diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel
173+
index 55b22d675..ef5a0eb63 100644
174+
--- a/src/google/protobuf/compiler/BUILD.bazel
175+
+++ b/src/google/protobuf/compiler/BUILD.bazel
176+
@@ -343,12 +343,8 @@ filegroup(
177+
)
178+
179+
exports_files(
180+
- srcs = ["plugin.proto"],
181+
- visibility = [
182+
- "//:__pkg__",
183+
- "//python:__pkg__",
184+
- "//ruby:__pkg__",
185+
- ],
186+
+ ["plugin.proto"],
187+
+ visibility = ["//visibility:public"],
188+
)
189+
190+
cc_library(
191+
diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel
192+
index bb00b0acc..51d79f534 100644
193+
--- a/src/google/protobuf/io/BUILD.bazel
194+
+++ b/src/google/protobuf/io/BUILD.bazel
195+
@@ -160,7 +160,7 @@ cc_library(
196+
"@abseil-cpp//absl/log:absl_log",
197+
] + select({
198+
"//build_defs:config_msvc": [],
199+
- "//conditions:default": ["@zlib"],
200+
+ "//conditions:default": ["//:zlib"],
201+
}),
202+
)
203+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"integrity": "sha256-aH6YpHGXO1xf1xF1DEC4uCwK3jP2Sdtl4AspDyk0Wis=",
3+
"strip_prefix": "protobuf-33.4",
4+
"url": "https://github.com/protocolbuffers/protobuf/releases/download/v33.4/protobuf-33.4.bazel.tar.gz",
5+
"patches": {
6+
"envoy.patch": "sha256-BQG7OKn+FoJcVs3UrKi9iVZXBCz8+KshDI3zJjoJ/XI="
7+
},
8+
"patch_strip": 1
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"homepage": "https://github.com/protocolbuffers/protobuf",
3+
"maintainers": [],
4+
"repository": [
5+
"github:protocolbuffers/protobuf"
6+
],
7+
"versions": [
8+
"33.4.envoy"
9+
],
10+
"yanked_versions": {}
11+
}

0 commit comments

Comments
 (0)