Cherry-pick grpc to support compiling protobufs with "editions".
Tested: bitbake grpc grpc-native
Fusion-Link: https://fusion2.corp.google.com/1e1f8ad1-a4d5-3726-9fc5-7f05fb7ba4e6
Google-Bug-Id: 327421478
Change-Id: Ic9ae92755dcddae109cd0bd9337b15361c28a4c5
Signed-off-by: Bojun Wang <bojunw@google.com>
diff --git a/recipes-devtools/grpc/grpc/0001-Mark-grpc-generators-for-editions-support.patch b/recipes-devtools/grpc/grpc/0001-Mark-grpc-generators-for-editions-support.patch
new file mode 100644
index 0000000..6615571
--- /dev/null
+++ b/recipes-devtools/grpc/grpc/0001-Mark-grpc-generators-for-editions-support.patch
@@ -0,0 +1,231 @@
+From cebb1c67ca10166e0db889ee27e2d4bdd077dc39 Mon Sep 17 00:00:00 2001
+From: Mike Kruskal <mkruskal@google.com>
+Date: Thu, 14 Mar 2024 10:49:31 -0700
+Subject: Mark grpc generators for editions support.
+
+Edition 2023 makes no changes to method/service descriptors, so these should be unaffected and already supported.
+
+PiperOrigin-RevId: 615832918
+---
+ include/grpcpp/impl/codegen/config_protobuf.h | 9 +++++++++
+ src/compiler/cpp_plugin.h | 14 +++++++++++++-
+ src/compiler/csharp_plugin.cc | 15 ++++++++++++++-
+ src/compiler/objective_c_plugin.cc | 15 ++++++++++++++-
+ src/compiler/php_plugin.cc | 15 ++++++++++++++-
+ src/compiler/python_generator.cc | 4 ----
+ src/compiler/python_generator.h | 17 ++++++++++++++++-
+ src/compiler/ruby_plugin.cc | 15 ++++++++++++++-
+ 8 files changed, 94 insertions(+), 10 deletions(-)
+
+diff --git a/include/grpcpp/impl/codegen/config_protobuf.h b/include/grpcpp/impl/codegen/config_protobuf.h
+index aa189215d4..06561cf121 100644
+--- a/include/grpcpp/impl/codegen/config_protobuf.h
++++ b/include/grpcpp/impl/codegen/config_protobuf.h
+@@ -40,8 +40,14 @@
+ #ifndef GRPC_CUSTOM_DESCRIPTOR
+ #include <google/protobuf/descriptor.h>
+ #include <google/protobuf/descriptor.pb.h>
++#if GOOGLE_PROTOBUF_VERSION >= 4025000
++#define GRPC_PROTOBUF_EDITION_SUPPORT
++#endif
+ #define GRPC_CUSTOM_DESCRIPTOR ::google::protobuf::Descriptor
+ #define GRPC_CUSTOM_DESCRIPTORPOOL ::google::protobuf::DescriptorPool
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++#define GRPC_CUSTOM_EDITION ::google::protobuf::Edition
++#endif
+ #define GRPC_CUSTOM_FIELDDESCRIPTOR ::google::protobuf::FieldDescriptor
+ #define GRPC_CUSTOM_FILEDESCRIPTOR ::google::protobuf::FileDescriptor
+ #define GRPC_CUSTOM_FILEDESCRIPTORPROTO ::google::protobuf::FileDescriptorProto
+@@ -85,6 +91,9 @@ typedef GRPC_CUSTOM_MESSAGELITE MessageLite;
+ typedef GRPC_CUSTOM_DESCRIPTOR Descriptor;
+ typedef GRPC_CUSTOM_DESCRIPTORPOOL DescriptorPool;
+ typedef GRPC_CUSTOM_DESCRIPTORDATABASE DescriptorDatabase;
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++typedef GRPC_CUSTOM_EDITION Edition;
++#endif
+ typedef GRPC_CUSTOM_FIELDDESCRIPTOR FieldDescriptor;
+ typedef GRPC_CUSTOM_FILEDESCRIPTOR FileDescriptor;
+ typedef GRPC_CUSTOM_FILEDESCRIPTORPROTO FileDescriptorProto;
+diff --git a/src/compiler/cpp_plugin.h b/src/compiler/cpp_plugin.h
+index 3d6f19e44c..9c8c4bd247 100644
+--- a/src/compiler/cpp_plugin.h
++++ b/src/compiler/cpp_plugin.h
+@@ -34,8 +34,20 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ virtual ~CppGrpcGenerator() {}
+
+ uint64_t GetSupportedFeatures() const override {
+- return FEATURE_PROTO3_OPTIONAL;
++ return FEATURE_PROTO3_OPTIONAL
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ | FEATURE_SUPPORTS_EDITIONS
++#endif
++ ;
+ }
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ grpc::protobuf::Edition GetMinimumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_PROTO2;
++ }
++ grpc::protobuf::Edition GetMaximumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_2023;
++ }
++#endif
+
+ virtual bool Generate(const grpc::protobuf::FileDescriptor* file,
+ const std::string& parameter,
+diff --git a/src/compiler/csharp_plugin.cc b/src/compiler/csharp_plugin.cc
+index b4fdb39c35..a7a2e74deb 100644
+--- a/src/compiler/csharp_plugin.cc
++++ b/src/compiler/csharp_plugin.cc
+@@ -30,9 +30,22 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ ~CSharpGrpcGenerator() {}
+
+ uint64_t GetSupportedFeatures() const override {
+- return FEATURE_PROTO3_OPTIONAL;
++ return FEATURE_PROTO3_OPTIONAL
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ | FEATURE_SUPPORTS_EDITIONS
++#endif
++ ;
+ }
+
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ grpc::protobuf::Edition GetMinimumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_PROTO2;
++ }
++ grpc::protobuf::Edition GetMaximumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_2023;
++ }
++#endif
++
+ bool Generate(const grpc::protobuf::FileDescriptor* file,
+ const std::string& parameter,
+ grpc::protobuf::compiler::GeneratorContext* context,
+diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc
+index e13693227f..4b0f296421 100644
+--- a/src/compiler/objective_c_plugin.cc
++++ b/src/compiler/objective_c_plugin.cc
+@@ -81,8 +81,21 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+
+ public:
+ uint64_t GetSupportedFeatures() const override {
+- return FEATURE_PROTO3_OPTIONAL;
++ return FEATURE_PROTO3_OPTIONAL
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ | FEATURE_SUPPORTS_EDITIONS
++#endif
++ ;
++ }
++
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ grpc::protobuf::Edition GetMinimumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_PROTO2;
+ }
++ grpc::protobuf::Edition GetMaximumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_2023;
++ }
++#endif
+
+ virtual bool Generate(const grpc::protobuf::FileDescriptor* file,
+ const ::std::string& parameter,
+diff --git a/src/compiler/php_plugin.cc b/src/compiler/php_plugin.cc
+index 7d4e4ce32c..9fafe52678 100644
+--- a/src/compiler/php_plugin.cc
++++ b/src/compiler/php_plugin.cc
+@@ -34,9 +34,22 @@ class PHPGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ ~PHPGrpcGenerator() {}
+
+ uint64_t GetSupportedFeatures() const override {
+- return FEATURE_PROTO3_OPTIONAL;
++ return FEATURE_PROTO3_OPTIONAL
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ | FEATURE_SUPPORTS_EDITIONS
++#endif
++ ;
+ }
+
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ grpc::protobuf::Edition GetMinimumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_PROTO2;
++ }
++ grpc::protobuf::Edition GetMaximumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_2023;
++ }
++#endif
++
+ bool Generate(const grpc::protobuf::FileDescriptor* file,
+ const std::string& parameter,
+ grpc::protobuf::compiler::GeneratorContext* context,
+diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc
+index 753fe1c888..ee81f71984 100644
+--- a/src/compiler/python_generator.cc
++++ b/src/compiler/python_generator.cc
+@@ -879,10 +879,6 @@ static bool ParseParameters(const std::string& parameter,
+ return true;
+ }
+
+-uint64_t PythonGrpcGenerator::GetSupportedFeatures() const {
+- return FEATURE_PROTO3_OPTIONAL;
+-}
+-
+ bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
+ const std::string& parameter,
+ GeneratorContext* context,
+diff --git a/src/compiler/python_generator.h b/src/compiler/python_generator.h
+index 12343ccde1..bbf8e923d0 100644
+--- a/src/compiler/python_generator.h
++++ b/src/compiler/python_generator.h
+@@ -44,7 +44,22 @@ class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ PythonGrpcGenerator(const GeneratorConfiguration& config);
+ ~PythonGrpcGenerator();
+
+- uint64_t GetSupportedFeatures() const override;
++ uint64_t GetSupportedFeatures() const override {
++ return FEATURE_PROTO3_OPTIONAL
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ | FEATURE_SUPPORTS_EDITIONS
++#endif
++ ;
++ }
++
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ grpc::protobuf::Edition GetMinimumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_PROTO2;
++ }
++ grpc::protobuf::Edition GetMaximumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_2023;
++ }
++#endif
+
+ bool Generate(const grpc::protobuf::FileDescriptor* file,
+ const std::string& parameter,
+diff --git a/src/compiler/ruby_plugin.cc b/src/compiler/ruby_plugin.cc
+index 8821e613ba..c70206c6b3 100644
+--- a/src/compiler/ruby_plugin.cc
++++ b/src/compiler/ruby_plugin.cc
+@@ -30,9 +30,22 @@ class RubyGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ ~RubyGrpcGenerator() {}
+
+ uint64_t GetSupportedFeatures() const override {
+- return FEATURE_PROTO3_OPTIONAL;
++ return FEATURE_PROTO3_OPTIONAL
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ | FEATURE_SUPPORTS_EDITIONS
++#endif
++ ;
+ }
+
++#ifdef GRPC_PROTOBUF_EDITION_SUPPORT
++ grpc::protobuf::Edition GetMinimumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_PROTO2;
++ }
++ grpc::protobuf::Edition GetMaximumEdition() const override {
++ return grpc::protobuf::Edition::EDITION_2023;
++ }
++#endif
++
+ bool Generate(const grpc::protobuf::FileDescriptor* file,
+ const std::string& /*parameter*/,
+ grpc::protobuf::compiler::GeneratorContext* context,
+--
+2.46.0.76.ge559c4bf1a-goog
+
diff --git a/recipes-devtools/grpc/grpc_%.bbappend b/recipes-devtools/grpc/grpc_%.bbappend
index cc51acd..c6f0bb6 100644
--- a/recipes-devtools/grpc/grpc_%.bbappend
+++ b/recipes-devtools/grpc/grpc_%.bbappend
@@ -3,4 +3,5 @@
SRC_URI:append:gbmc = " \
file://DOWNSTREAM_0001-core-tsi-Silence-SSL_get_servername-errors.patch \
file://0001-gRPC-Add-grpc_authorization_provider-to-CMake.patch \
+ file://0001-Mark-grpc-generators-for-editions-support.patch \
"