From b3c1bb1762fceefe9520ae0e442fdd2cce0fca31 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 8 Sep 2024 11:58:54 +0200 Subject: [PATCH] protobufc: fix compatibility with new protobuf --- .../libraries/protobufc/default.nix | 6 ++ .../protobufc/recent_protobuf_compat.patch | 80 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 pkgs/development/libraries/protobufc/recent_protobuf_compat.patch diff --git a/pkgs/development/libraries/protobufc/default.nix b/pkgs/development/libraries/protobufc/default.nix index 5a3972527550..73c2d7fba157 100644 --- a/pkgs/development/libraries/protobufc/default.nix +++ b/pkgs/development/libraries/protobufc/default.nix @@ -19,6 +19,12 @@ stdenv.mkDerivation rec { hash = "sha256-Dkpcc7ZfvAIVY91trRiHuiRFcUGUbQxbheYKTBcq80I="; }; + patches = [ + # https://github.com/protobuf-c/protobuf-c/issues/709 + # https://github.com/protobuf-c/protobuf-c/pull/711 + ./recent_protobuf_compat.patch + ]; + outputs = [ "out" "dev" "lib" ]; nativeBuildInputs = [ autoreconfHook pkg-config ]; diff --git a/pkgs/development/libraries/protobufc/recent_protobuf_compat.patch b/pkgs/development/libraries/protobufc/recent_protobuf_compat.patch new file mode 100644 index 000000000000..c2d340e1a7f6 --- /dev/null +++ b/pkgs/development/libraries/protobufc/recent_protobuf_compat.patch @@ -0,0 +1,80 @@ +diff --git a/protoc-c/c_file.cc b/protoc-c/c_file.cc +index ca0ad34..c6d8a24 100644 +--- a/protoc-c/c_file.cc ++++ b/protoc-c/c_file.cc +@@ -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 --git a/protoc-c/c_generator.h b/protoc-c/c_generator.h +index b8b44aa..4aeb579 100644 +--- a/protoc-c/c_generator.h ++++ b/protoc-c/c_generator.h +@@ -93,6 +93,12 @@ class PROTOC_C_EXPORT CGenerator : public CodeGenerator { + 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 --git a/protoc-c/c_helpers.h b/protoc-c/c_helpers.h +index 062d330..be28b60 100644 +--- a/protoc-c/c_helpers.h ++++ b/protoc-c/c_helpers.h +@@ -70,10 +70,6 @@ + #include + #include + +-#if GOOGLE_PROTOBUF_VERSION >= 4023000 +-# include +-#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