Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions bazel-registry/modules/protobuf/33.4.envoy/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/protocolbuffers/protobuf/issues/14313

module(
name = "protobuf",
version = "33.4.envoy",
compatibility_level = 1,
repo_name = "com_google_protobuf",
)

# LOWER BOUND dependency versions.
# Bzlmod follows MVS:
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
# Thus the highest version in their module graph is resolved.

# These dependencies must be declared before the other rules dependencies.
bazel_dep(name = "rules_apple", version = "3.16.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "apple_support", version = "1.15.1", repo_name = "build_bazel_apple_support")

# Keep apple_support on 1.15.1 for now to avoid this issue:
# https://github.com/bazelbuild/apple_support/issues/316
single_version_override(
module_name = "apple_support",
version = "1.15.1",
)

#ifndef PROTO2_OPENSOURCE
# LINT.IfChange
#endif // PROTO2_OPENSOURCE
# protoc dependencies
bazel_dep(name = "abseil-cpp", version = "20250512.1")
bazel_dep(name = "rules_cc", version = "0.0.17")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
#ifndef PROTO2_OPENSOURCE
# LINT.ThenChange(//depot/google3/third_party/protobuf/compiler/notices.h)
#endif // PROTO2_OPENSOURCE

# other dependencies
bazel_dep(name = "bazel_features", version = "1.33.0", repo_name = "proto_bazel_features")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "jsoncpp", version = "1.9.6")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_jvm_external", version = "6.7")
bazel_dep(name = "rules_kotlin", version = "1.9.6")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_python", version = "1.6.0")

# Pin to rules_proto to 7.1.0 to avoid toolchain incompatibilities when
# --incompatible_enable_proto_toolchain_resolution=true in Bazel 7.
# rules_proto 7.0.2 from deps incorrectly rules_proto's toolchain_type but protobuf's toolchain, but
# 7.1.0 uses protobuf's toolchain and toolchain_type.
bazel_dep(name = "rules_proto", version = "7.1.0")

bazel_dep(name = "rules_shell", version = "0.2.0")
bazel_dep(name = "platforms", version = "0.0.11")

# Define toolchains that use pre-built protoc binaries.
prebuilt_protoc = use_extension("//bazel/private:prebuilt_protoc_extension.bzl", "protoc")
use_repo(
prebuilt_protoc,
"prebuilt_protoc.linux_aarch_64",
"prebuilt_protoc.osx_aarch_64",
"prebuilt_protoc.linux_ppcle_64",
"prebuilt_protoc.linux_s390_64",
"prebuilt_protoc.linux_x86_32",
"prebuilt_protoc.linux_x86_64",
"prebuilt_protoc.osx_x86_64",
"prebuilt_protoc.win32",
"prebuilt_protoc.win64",
)

# However this registration only matters if the config_setting for prefer_prebuilt_protoc is true,
# using --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
register_toolchains("//bazel/private/toolchains/prebuilt:all")

# From-source protobuf toolchains
# Fallback if nothing is already registered
register_toolchains("//bazel/private/toolchains:all")

# Keep this list minimal; these dependencies will be part of the common `maven` install and could affect end-user projects.
PROTOBUF_MAVEN_ARTIFACTS = [
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.5.1",
"com.google.j2objc:j2objc-annotations:2.8",
"com.google.guava:guava:32.0.1-jre",
]

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
artifacts = PROTOBUF_MAVEN_ARTIFACTS,
lock_file = "//:maven_install.json",
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
],
)

# Use the default "maven" namespace because protobuf java targets are exposed to users
# See https://github.com/protocolbuffers/protobuf/issues/21177
use_repo(maven, "maven")

# Temporarily pin transitive dependency for https://github.com/bazelbuild/bazel/issues/24426
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")

# For clang-cl configuration
cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc")
203 changes: 203 additions & 0 deletions bazel-registry/modules/protobuf/33.4.envoy/patches/envoy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
diff --git a/BUILD.bazel b/BUILD.bazel
index 9e76da895..8d5f4f46a 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -28,6 +28,12 @@ exports_files(
visibility = ["//cmake:__pkg__"],
)

+label_flag(
+ name = "zlib",
+ build_setting_default = "@zlib",
+ visibility = ["//visibility:public"],
+)
+
################################################################################
# Well Known Types Proto Library Rules
#
@@ -354,13 +360,83 @@ alias(
)

cc_binary(
- name = "protoc",
+ name = "compiled_protoc",
copts = COPTS,
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib_stage1"],
)

+# Lifted from `rules_proto`
+config_setting(
+ name = "linux-aarch_64",
+ constraint_values = [
+ "@platforms//os:linux",
+ "@platforms//cpu:aarch64",
+ ],
+)
+
+config_setting(
+ name = "linux-x86_64",
+ constraint_values = [
+ "@platforms//os:linux",
+ "@platforms//cpu:x86_64",
+ ],
+)
+
+config_setting(
+ name = "linux-ppcle_64",
+ constraint_values = [
+ "@platforms//os:linux",
+ "@platforms//cpu:ppc64le",
+ ],
+)
+
+config_setting(
+ name = "osx-aarch_64",
+ constraint_values = [
+ "@platforms//os:osx",
+ "@platforms//cpu:aarch64",
+ ],
+)
+
+config_setting(
+ name = "osx-x86_64",
+ constraint_values = [
+ "@platforms//os:osx",
+ "@platforms//cpu:x86_64",
+ ],
+)
+
+config_setting(
+ name = "win64",
+ constraint_values = [
+ "@platforms//os:windows",
+ "@platforms//cpu:x86_64",
+ ],
+)
+
+# Use precompiled binaries where possible.
+alias(
+ name = "protoc",
+ actual = select({
+ ":linux-aarch_64": "@prebuilt_protoc.linux_aarch_64//:protoc",
+ ":linux-x86_64": "@prebuilt_protoc.linux_x86_64//:protoc",
+ ":linux-ppcle_64": "@prebuilt_protoc.linux_ppcle_64//:protoc",
+ ":osx-aarch_64": "@prebuilt_protoc.osx_aarch_64//:protoc",
+ ":osx-x86_64": "@prebuilt_protoc.osx_x86_64//:protoc",
+ ":win64": "@prebuilt_protoc.win64//:protoc",
+ "//conditions:default": ":compiled_protoc",
+ }),
+ visibility = ["//visibility:public"],
+)
+
+alias(
+ name = "protobuf_python_genproto",
+ actual = "//python:well_known_types_py_pb2_genproto",
+ visibility = ["//visibility:public"],
+)
+
cc_binary(
name = "protoc_stage0",
copts = COPTS,
diff --git a/bazel/private/prebuilt_protoc_toolchain.bzl b/bazel/private/prebuilt_protoc_toolchain.bzl
index b583e35d6..75e7642c3 100644
--- a/bazel/private/prebuilt_protoc_toolchain.bzl
+++ b/bazel/private/prebuilt_protoc_toolchain.bzl
@@ -32,10 +32,24 @@ def _prebuilt_protoc_repo_impl(rctx):

rctx.file("BUILD.bazel", """\
# Generated by @protobuf//bazel/private:prebuilt_protoc_toolchain.bzl
+load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@com_google_protobuf//bazel/toolchains:proto_toolchain.bzl", "proto_toolchain")

package(default_visibility = ["//visibility:public"])

+# For rules that need single-file output
+filegroup(
+ name = "protoc",
+ srcs = ["{protoc_label}"],
+)
+
+# For `bazel run`
+native_binary(
+ name = "protoc_bin",
+ src = "{protoc_label}",
+ out = "protoc_runner",
+)
+
proto_toolchain(
name = "prebuilt_protoc_toolchain",
proto_compiler = "{protoc_label}",
diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl
index c0116bd76..5ce341c74 100644
--- a/build_defs/cpp_opts.bzl
+++ b/build_defs/cpp_opts.bzl
@@ -18,6 +18,7 @@ COPTS = select({
],
"//conditions:default": [
"-Wno-sign-compare",
+ "-Wno-deprecated-declarations",
],
})

diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel
index 475556bf5..ef434e99b 100644
--- a/src/google/protobuf/BUILD.bazel
+++ b/src/google/protobuf/BUILD.bazel
@@ -24,6 +24,23 @@ package(
],
)

+exports_files(
+ [
+ "any.proto",
+ "api.proto",
+ "descriptor.proto",
+ "duration.proto",
+ "empty.proto",
+ "field_mask.proto",
+ "source_context.proto",
+ "struct.proto",
+ "timestamp.proto",
+ "type.proto",
+ "wrappers.proto",
+ ],
+ visibility = ["//visibility:public"],
+)
+
proto_library(
name = "any_proto",
srcs = ["any.proto"],
diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel
index 55b22d675..ef5a0eb63 100644
--- a/src/google/protobuf/compiler/BUILD.bazel
+++ b/src/google/protobuf/compiler/BUILD.bazel
@@ -343,12 +343,8 @@ filegroup(
)

exports_files(
- srcs = ["plugin.proto"],
- visibility = [
- "//:__pkg__",
- "//python:__pkg__",
- "//ruby:__pkg__",
- ],
+ ["plugin.proto"],
+ visibility = ["//visibility:public"],
)

cc_library(
diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel
index bb00b0acc..51d79f534 100644
--- a/src/google/protobuf/io/BUILD.bazel
+++ b/src/google/protobuf/io/BUILD.bazel
@@ -160,7 +160,7 @@ cc_library(
"@abseil-cpp//absl/log:absl_log",
] + select({
"//build_defs:config_msvc": [],
- "//conditions:default": ["@zlib"],
+ "//conditions:default": ["//:zlib"],
}),
)

9 changes: 9 additions & 0 deletions bazel-registry/modules/protobuf/33.4.envoy/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"integrity": "sha256-aH6YpHGXO1xf1xF1DEC4uCwK3jP2Sdtl4AspDyk0Wis=",
"strip_prefix": "protobuf-33.4",
"url": "https://github.com/protocolbuffers/protobuf/releases/download/v33.4/protobuf-33.4.bazel.tar.gz",
"patches": {
"envoy.patch": "sha256-BQG7OKn+FoJcVs3UrKi9iVZXBCz8+KshDI3zJjoJ/XI="
},
"patch_strip": 1
}
11 changes: 11 additions & 0 deletions bazel-registry/modules/protobuf/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://github.com/protocolbuffers/protobuf",
"maintainers": [],
"repository": [
"github:protocolbuffers/protobuf"
],
"versions": [
"33.4.envoy"
],
"yanked_versions": {}
}