Submitted By:            Douglas R. Reno <renodr at linuxfromscratch dot org>
Date:                    2024-04-08
Initial Package Version: 1.5.0
Origin:                  Upstream (https://github.com/protobuf-c/protobuf-c/pull/711)
Upstream Status:         Opened (but not merged)
Description:             Fixes building protobuf-c against protobuf-26.1 by
                         adjusting to several changes made upstream. This
                         includes adjusting the code around methods that no
                         longer exist as well as preventing protobuf-c from
                         being invoked against the new 'editions' syntax.

diff -Naurp protobuf-c-1.5.0.orig/protoc-c/c_file.cc protobuf-c-1.5.0/protoc-c/c_file.cc
--- protobuf-c-1.5.0.orig/protoc-c/c_file.cc	2023-11-25 17:21:25.000000000 -0600
+++ protobuf-c-1.5.0/protoc-c/c_file.cc	2024-04-08 21:49:27.876308361 -0500
@@ -117,14 +117,7 @@ FileGenerator::~FileGenerator() {}
 void FileGenerator::GenerateHeader(io::Printer* printer) {
   std::string filename_identifier = FilenameIdentifier(file_->name());
 
-  int min_header_version = 1000000;
-#if GOOGLE_PROTOBUF_VERSION >= 4023000
-  if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) {
-#else
-  if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) {
-#endif
-    min_header_version = 1003000;
-  }
+  const int min_header_version = 1003000;
 
   // Generate top of header.
   printer->Print(
diff -Naurp protobuf-c-1.5.0.orig/protoc-c/c_generator.h protobuf-c-1.5.0/protoc-c/c_generator.h
--- protobuf-c-1.5.0.orig/protoc-c/c_generator.h	2023-11-25 17:21:25.000000000 -0600
+++ protobuf-c-1.5.0/protoc-c/c_generator.h	2024-04-08 21:49:27.876308361 -0500
@@ -93,6 +93,12 @@ class PROTOC_C_EXPORT CGenerator : publi
                 const std::string& parameter,
                 OutputDirectory* output_directory,
                 std::string* error) const;
+
+#if GOOGLE_PROTOBUF_VERSION >= 5026000
+  uint64_t GetSupportedFeatures() const { return CodeGenerator::FEATURE_SUPPORTS_EDITIONS; }
+  Edition GetMinimumEdition() const { return Edition::EDITION_PROTO2; }
+  Edition GetMaximumEdition() const { return Edition::EDITION_PROTO3; }
+#endif
 };
 
 }  // namespace c
diff -Naurp protobuf-c-1.5.0.orig/protoc-c/c_helpers.h protobuf-c-1.5.0/protoc-c/c_helpers.h
--- protobuf-c-1.5.0.orig/protoc-c/c_helpers.h	2023-11-25 17:21:25.000000000 -0600
+++ protobuf-c-1.5.0/protoc-c/c_helpers.h	2024-04-08 21:49:27.876308361 -0500
@@ -70,10 +70,6 @@
 #include <protobuf-c/protobuf-c.pb.h>
 #include <google/protobuf/io/printer.h>
 
-#if GOOGLE_PROTOBUF_VERSION >= 4023000
-# include <google/protobuf/descriptor_legacy.h>
-#endif
-
 namespace google {
 namespace protobuf {
 namespace compiler {
@@ -173,13 +169,21 @@ struct NameIndex
 int compare_name_indices_by_name(const void*, const void*);
 
 // Return the syntax version of the file containing the field.
-// This wrapper is needed to be able to compile against protobuf2.
 inline int FieldSyntax(const FieldDescriptor* field) {
-#if GOOGLE_PROTOBUF_VERSION >= 4023000
-  return FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3 ? 3 : 2;
-#else
-  return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2;
-#endif
+  auto proto = FileDescriptorProto();
+  field->file()->CopyTo(&proto);
+
+  if (proto.has_syntax()) {
+    auto syntax = proto.syntax();
+    assert(syntax == "proto2" || syntax == "proto3");
+    if (syntax == "proto2") {
+      return 2;
+    } else if (syntax == "proto3") {
+      return 3;
+    }
+  }
+
+  return 2;
 }
 
 // Work around changes in protobuf >= 22.x without breaking compilation against
