mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-26 21:04:23 +08:00
Merge pull request #673 from protobuf-c/edmonds/new-google-support
Support for new Google protobuf 22.x, 23.x releases
This commit is contained in:
commit
69fc2f13bb
@ -96,7 +96,7 @@ if (MSVC AND NOT BUILD_SHARED_LIBS)
|
|||||||
endif (MSVC AND NOT BUILD_SHARED_LIBS)
|
endif (MSVC AND NOT BUILD_SHARED_LIBS)
|
||||||
|
|
||||||
IF(BUILD_PROTOC)
|
IF(BUILD_PROTOC)
|
||||||
SET(CMAKE_CXX_STANDARD 11)
|
SET(CMAKE_CXX_STANDARD 17)
|
||||||
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
SET(CMAKE_CXX_EXTENSIONS OFF)
|
SET(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
ADD_CUSTOM_COMMAND(OUTPUT protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h
|
ADD_CUSTOM_COMMAND(OUTPUT protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h
|
||||||
|
@ -75,13 +75,8 @@ AC_ARG_ENABLE([protoc],
|
|||||||
AS_HELP_STRING([--disable-protoc], [Disable building protoc_c (also disables tests)]))
|
AS_HELP_STRING([--disable-protoc], [Disable building protoc_c (also disables tests)]))
|
||||||
if test "x$enable_protoc" != "xno"; then
|
if test "x$enable_protoc" != "xno"; then
|
||||||
AC_LANG_PUSH([C++])
|
AC_LANG_PUSH([C++])
|
||||||
|
AX_CXX_COMPILE_STDCXX(17, noext, mandatory)
|
||||||
AX_CXX_COMPILE_STDCXX(11, noext, mandatory)
|
PKG_CHECK_MODULES([protobuf], [protobuf >= 3.0.0], [proto3_supported=yes])
|
||||||
|
|
||||||
PKG_CHECK_MODULES([protobuf], [protobuf >= 3.0.0],
|
|
||||||
[proto3_supported=yes],
|
|
||||||
[PKG_CHECK_MODULES([protobuf], [protobuf >= 2.6.0])]
|
|
||||||
)
|
|
||||||
|
|
||||||
save_CPPFLAGS="$CPPFLAGS"
|
save_CPPFLAGS="$CPPFLAGS"
|
||||||
CPPFLAGS="$save_CPPFLAGS $protobuf_CFLAGS"
|
CPPFLAGS="$save_CPPFLAGS $protobuf_CFLAGS"
|
||||||
|
@ -87,8 +87,6 @@ class BytesFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> variables_;
|
std::map<std::string, std::string> variables_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(BytesFieldGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,8 +106,6 @@ class EnumGenerator {
|
|||||||
private:
|
private:
|
||||||
const EnumDescriptor* descriptor_;
|
const EnumDescriptor* descriptor_;
|
||||||
std::string dllexport_decl_;
|
std::string dllexport_decl_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -85,8 +85,6 @@ class EnumFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> variables_;
|
std::map<std::string, std::string> variables_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,8 +98,6 @@ class ExtensionGenerator {
|
|||||||
const FieldDescriptor* descriptor_;
|
const FieldDescriptor* descriptor_;
|
||||||
std::string type_traits_;
|
std::string type_traits_;
|
||||||
std::string dllexport_decl_;
|
std::string dllexport_decl_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -103,9 +103,6 @@ class FieldGenerator {
|
|||||||
const std::string &type_macro,
|
const std::string &type_macro,
|
||||||
const std::string &descriptor_addr) const;
|
const std::string &descriptor_addr) const;
|
||||||
const FieldDescriptor *descriptor_;
|
const FieldDescriptor *descriptor_;
|
||||||
|
|
||||||
private:
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convenience class which constructs FieldGenerators for a Descriptor.
|
// Convenience class which constructs FieldGenerators for a Descriptor.
|
||||||
@ -121,8 +118,6 @@ class FieldGeneratorMap {
|
|||||||
std::unique_ptr<std::unique_ptr<FieldGenerator>[]> field_generators_;
|
std::unique_ptr<std::unique_ptr<FieldGenerator>[]> field_generators_;
|
||||||
|
|
||||||
static FieldGenerator* MakeGenerator(const FieldDescriptor* field);
|
static FieldGenerator* MakeGenerator(const FieldDescriptor* field);
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -119,7 +119,11 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
|
|||||||
|
|
||||||
int min_header_version = 1000000;
|
int min_header_version = 1000000;
|
||||||
#if defined(HAVE_PROTO3)
|
#if defined(HAVE_PROTO3)
|
||||||
|
# if GOOGLE_PROTOBUF_VERSION >= 4023000
|
||||||
|
if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) {
|
||||||
|
# else
|
||||||
if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) {
|
if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) {
|
||||||
|
#endif
|
||||||
min_header_version = 1003000;
|
min_header_version = 1003000;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,8 +103,6 @@ class FileGenerator {
|
|||||||
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;
|
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;
|
||||||
std::unique_ptr<std::unique_ptr<ServiceGenerator>[]> service_generators_;
|
std::unique_ptr<std::unique_ptr<ServiceGenerator>[]> service_generators_;
|
||||||
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
|
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -93,9 +93,6 @@ class PROTOC_C_EXPORT CGenerator : public CodeGenerator {
|
|||||||
const std::string& parameter,
|
const std::string& parameter,
|
||||||
OutputDirectory* output_directory,
|
OutputDirectory* output_directory,
|
||||||
std::string* error) const;
|
std::string* error) const;
|
||||||
|
|
||||||
private:
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -70,6 +70,10 @@
|
|||||||
#include <protobuf-c/protobuf-c.pb.h>
|
#include <protobuf-c/protobuf-c.pb.h>
|
||||||
#include <google/protobuf/io/printer.h>
|
#include <google/protobuf/io/printer.h>
|
||||||
|
|
||||||
|
#if GOOGLE_PROTOBUF_VERSION >= 4023000
|
||||||
|
# include <google/protobuf/descriptor_legacy.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace google {
|
namespace google {
|
||||||
namespace protobuf {
|
namespace protobuf {
|
||||||
namespace compiler {
|
namespace compiler {
|
||||||
@ -172,12 +176,26 @@ int compare_name_indices_by_name(const void*, const void*);
|
|||||||
// This wrapper is needed to be able to compile against protobuf2.
|
// This wrapper is needed to be able to compile against protobuf2.
|
||||||
inline int FieldSyntax(const FieldDescriptor* field) {
|
inline int FieldSyntax(const FieldDescriptor* field) {
|
||||||
#ifdef HAVE_PROTO3
|
#ifdef HAVE_PROTO3
|
||||||
|
# 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;
|
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2;
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
return 2;
|
return 2;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Work around changes in protobuf >= 22.x without breaking compilation against
|
||||||
|
// older protobuf versions.
|
||||||
|
#if GOOGLE_PROTOBUF_VERSION >= 4022000
|
||||||
|
# define GOOGLE_ARRAYSIZE ABSL_ARRAYSIZE
|
||||||
|
# define GOOGLE_CHECK_EQ ABSL_CHECK_EQ
|
||||||
|
# define GOOGLE_CHECK_EQ ABSL_CHECK_EQ
|
||||||
|
# define GOOGLE_DCHECK_GE ABSL_DCHECK_GE
|
||||||
|
# define GOOGLE_LOG ABSL_LOG
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
} // namespace compiler
|
} // namespace compiler
|
||||||
} // namespace protobuf
|
} // namespace protobuf
|
||||||
|
@ -499,7 +499,7 @@ GenerateMessageDescriptor(io::Printer* printer, bool gen_init) {
|
|||||||
// NOTE: not supported by protobuf
|
// NOTE: not supported by protobuf
|
||||||
vars["maybe_static"] = "";
|
vars["maybe_static"] = "";
|
||||||
vars["field_dv_ctype"] = "{ ... }";
|
vars["field_dv_ctype"] = "{ ... }";
|
||||||
GOOGLE_LOG(DFATAL) << "Messages can't have default values!";
|
GOOGLE_LOG(FATAL) << "Messages can't have default values!";
|
||||||
break;
|
break;
|
||||||
case FieldDescriptor::CPPTYPE_STRING:
|
case FieldDescriptor::CPPTYPE_STRING:
|
||||||
if (fd->type() == FieldDescriptor::TYPE_BYTES || opt.string_as_bytes())
|
if (fd->type() == FieldDescriptor::TYPE_BYTES || opt.string_as_bytes())
|
||||||
@ -521,7 +521,7 @@ GenerateMessageDescriptor(io::Printer* printer, bool gen_init) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
GOOGLE_LOG(DFATAL) << "Unknown CPPTYPE";
|
GOOGLE_LOG(FATAL) << "Unknown CPPTYPE";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!already_defined)
|
if (!already_defined)
|
||||||
|
@ -136,8 +136,6 @@ class MessageGenerator {
|
|||||||
std::unique_ptr<std::unique_ptr<MessageGenerator>[]> nested_generators_;
|
std::unique_ptr<std::unique_ptr<MessageGenerator>[]> nested_generators_;
|
||||||
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;
|
std::unique_ptr<std::unique_ptr<EnumGenerator>[]> enum_generators_;
|
||||||
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
|
std::unique_ptr<std::unique_ptr<ExtensionGenerator>[]> extension_generators_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -82,10 +82,6 @@ class MessageFieldGenerator : public FieldGenerator {
|
|||||||
void GenerateDescriptorInitializer(io::Printer* printer) const;
|
void GenerateDescriptorInitializer(io::Printer* printer) const;
|
||||||
std::string GetDefaultValue(void) const;
|
std::string GetDefaultValue(void) const;
|
||||||
void GenerateStaticInit(io::Printer* printer) const;
|
void GenerateStaticInit(io::Printer* printer) const;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ std::string PrimitiveFieldGenerator::GetDefaultValue() const
|
|||||||
case FieldDescriptor::CPPTYPE_BOOL:
|
case FieldDescriptor::CPPTYPE_BOOL:
|
||||||
return descriptor_->default_value_bool() ? "1" : "0";
|
return descriptor_->default_value_bool() ? "1" : "0";
|
||||||
default:
|
default:
|
||||||
GOOGLE_LOG(DFATAL) << "unexpected CPPTYPE in c_primitive_field";
|
GOOGLE_LOG(FATAL) << "unexpected CPPTYPE in c_primitive_field";
|
||||||
return "UNEXPECTED_CPPTYPE";
|
return "UNEXPECTED_CPPTYPE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,6 @@ class PrimitiveFieldGenerator : public FieldGenerator {
|
|||||||
void GenerateDescriptorInitializer(io::Printer* printer) const;
|
void GenerateDescriptorInitializer(io::Printer* printer) const;
|
||||||
std::string GetDefaultValue(void) const;
|
std::string GetDefaultValue(void) const;
|
||||||
void GenerateStaticInit(io::Printer* printer) const;
|
void GenerateStaticInit(io::Printer* printer) const;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -100,8 +100,6 @@ class ServiceGenerator {
|
|||||||
|
|
||||||
const ServiceDescriptor* descriptor_;
|
const ServiceDescriptor* descriptor_;
|
||||||
std::map<std::string, std::string> vars_;
|
std::map<std::string, std::string> vars_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace c
|
} // namespace c
|
||||||
|
@ -87,8 +87,6 @@ class StringFieldGenerator : public FieldGenerator {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> variables_;
|
std::map<std::string, std::string> variables_;
|
||||||
|
|
||||||
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user