diff --git a/include/grpcpp/impl/codegen/config_protobuf.h b/include/grpcpp/impl/codegen/config_protobuf.h index aa189215d4f..06561cf1210 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 #include +#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 3d6f19e44cb..9c8c4bd2474 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 b4fdb39c353..a7a2e74deb9 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 e13693227fa..4b0f2964212 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 7d4e4ce32c5..9fafe52678c 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 53b6083c670..e968fedcbad 100644 --- a/src/compiler/python_generator.cc +++ b/src/compiler/python_generator.cc @@ -944,10 +944,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 d65f310f64d..1ea0e0a0968 100644 --- a/src/compiler/python_generator.h +++ b/src/compiler/python_generator.h @@ -46,7 +46,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 8821e613bae..c70206c6b37 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,