Merge pull request #676 from protobuf-c/edmonds/protobuf2-removal

Remove protobuf 2.x support
This commit is contained in:
Robert Edmonds 2023-07-08 23:59:41 -04:00 committed by GitHub
commit 94d8a28db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 50 deletions

View File

@ -139,11 +139,13 @@ LOG_COMPILER = $(VALGRIND)
check_PROGRAMS += \ check_PROGRAMS += \
t/generated-code/test-generated-code \ t/generated-code/test-generated-code \
t/generated-code2/test-generated-code2 \ t/generated-code2/test-generated-code2 \
t/generated-code3/test-generated-code3 \
t/version/version t/version/version
TESTS += \ TESTS += \
t/generated-code/test-generated-code \ t/generated-code/test-generated-code \
t/generated-code2/test-generated-code2 \ t/generated-code2/test-generated-code2 \
t/generated-code3/test-generated-code3 \
t/version/version t/version/version
t_generated_code_test_generated_code_SOURCES = \ t_generated_code_test_generated_code_SOURCES = \
@ -159,6 +161,16 @@ t_generated_code2_test_generated_code2_SOURCES = \
t_generated_code2_test_generated_code2_LDADD = \ t_generated_code2_test_generated_code2_LDADD = \
protobuf-c/libprotobuf-c.la protobuf-c/libprotobuf-c.la
t_generated_code3_test_generated_code3_CPPFLAGS = \
-DPROTO3
t_generated_code3_test_generated_code3_SOURCES = \
t/generated-code/test-generated-code.c \
t/test-proto3.pb-c.c
t_generated_code3_test_generated_code3_LDADD = \
protobuf-c/libprotobuf-c.la
noinst_PROGRAMS += \ noinst_PROGRAMS += \
t/generated-code2/cxx-generate-packed-data t/generated-code2/cxx-generate-packed-data
@ -185,6 +197,9 @@ t/test-full.pb-c.c t/test-full.pb-c.h: $(top_builddir)/protoc-c/protoc-gen-c$(EX
t/test-full.pb.cc t/test-full.pb.h: @PROTOC@ $(top_srcdir)/t/test-full.proto t/test-full.pb.cc t/test-full.pb.h: @PROTOC@ $(top_srcdir)/t/test-full.proto
$(AM_V_GEN)@PROTOC@ -I$(top_srcdir) --cpp_out=$(top_builddir) $(top_srcdir)/t/test-full.proto $(AM_V_GEN)@PROTOC@ -I$(top_srcdir) --cpp_out=$(top_builddir) $(top_srcdir)/t/test-full.proto
t/test-proto3.pb-c.c t/test-proto3.pb-c.h: $(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) $(top_srcdir)/t/test-proto3.proto
$(AM_V_GEN)@PROTOC@ --plugin=protoc-gen-c=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/test-proto3.proto
t/generated-code2/test-full-cxx-output.inc: t/generated-code2/cxx-generate-packed-data$(EXEEXT) t/generated-code2/test-full-cxx-output.inc: t/generated-code2/cxx-generate-packed-data$(EXEEXT)
$(AM_V_GEN)$(top_builddir)/t/generated-code2/cxx-generate-packed-data$(EXEEXT) > $(top_builddir)/t/generated-code2/test-full-cxx-output.inc $(AM_V_GEN)$(top_builddir)/t/generated-code2/cxx-generate-packed-data$(EXEEXT) > $(top_builddir)/t/generated-code2/test-full-cxx-output.inc
@ -193,34 +208,9 @@ BUILT_SOURCES += \
t/test-full.pb-c.c t/test-full.pb-c.h \ t/test-full.pb-c.c t/test-full.pb-c.h \
t/test-optimized.pb-c.c t/test-optimized.pb-c.h \ t/test-optimized.pb-c.c t/test-optimized.pb-c.h \
t/test-full.pb.cc t/test-full.pb.h \ t/test-full.pb.cc t/test-full.pb.h \
t/test-proto3.pb-c.c t/test-proto3.pb-c.h \
t/generated-code2/test-full-cxx-output.inc t/generated-code2/test-full-cxx-output.inc
if BUILD_PROTO3
check_PROGRAMS += \
t/generated-code3/test-generated-code3
TESTS += \
t/generated-code3/test-generated-code3
t_generated_code3_test_generated_code3_CPPFLAGS = \
-DPROTO3
t_generated_code3_test_generated_code3_LDADD = \
protobuf-c/libprotobuf-c.la
t_generated_code3_test_generated_code3_SOURCES = \
t/generated-code/test-generated-code.c \
t/test-proto3.pb-c.c
t/test-proto3.pb-c.c t/test-proto3.pb-c.h: $(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) $(top_srcdir)/t/test-proto3.proto
$(AM_V_GEN)@PROTOC@ --plugin=protoc-gen-c=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/test-proto3.proto
BUILT_SOURCES += \
t/test-proto3.pb-c.c t/test-proto3.pb-c.h
endif # BUILD_PROTO3
t_version_version_SOURCES = \ t_version_version_SOURCES = \
t/version/version.c t/version/version.c
t_version_version_LDADD = \ t_version_version_LDADD = \
@ -278,7 +268,6 @@ EXTRA_DIST += \
t/issue251/issue251.proto t/issue251/issue251.proto
# Issue #330 # Issue #330
if BUILD_PROTO3
check_PROGRAMS += \ check_PROGRAMS += \
t/issue330/issue330 t/issue330/issue330
TESTS += \ TESTS += \
@ -292,6 +281,8 @@ t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h: $(top_builddir)/protoc-c/
$(AM_V_GEN)@PROTOC@ --plugin=protoc-gen-c=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/issue330/issue330.proto $(AM_V_GEN)@PROTOC@ --plugin=protoc-gen-c=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/issue330/issue330.proto
BUILT_SOURCES += \ BUILT_SOURCES += \
t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h
EXTRA_DIST += \
t/issue330/issue330.proto
t_issue330_issue330_SOURCES += \ t_issue330_issue330_SOURCES += \
t/issue389/issue389.pb-c.c # Tack onto issue330 since there is no need for a separate binary here t/issue389/issue389.pb-c.c # Tack onto issue330 since there is no need for a separate binary here
@ -317,9 +308,6 @@ BUILT_SOURCES += \
t/issue440/issue440.pb-c.c t/issue440/issue440.pb-c.h t/issue440/issue440.pb-c.c t/issue440/issue440.pb-c.h
EXTRA_DIST += \ EXTRA_DIST += \
t/issue440/issue440.proto t/issue440/issue440.proto
endif # BUILD_PROTO3
EXTRA_DIST += \
t/issue330/issue330.proto
# Issue #375 # Issue #375
check_PROGRAMS += \ check_PROGRAMS += \

View File

@ -9,7 +9,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
PROJECT(protobuf-c) PROJECT(protobuf-c)
#options #options
option(BUILD_PROTO3 "BUILD_PROTO3" ON)
option(BUILD_PROTOC "Build protoc-gen-c" ON) option(BUILD_PROTOC "Build protoc-gen-c" ON)
if(CMAKE_BUILD_TYPE MATCHES Debug) if(CMAKE_BUILD_TYPE MATCHES Debug)
option(BUILD_TESTS "Build tests" ON) option(BUILD_TESTS "Build tests" ON)
@ -73,9 +72,6 @@ endif (MSVC AND NOT BUILD_SHARED_LIBS)
FIND_PACKAGE(Protobuf REQUIRED) FIND_PACKAGE(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
if (BUILD_PROTO3)
ADD_DEFINITIONS(-DHAVE_PROTO3)
endif()
ENDIF() ENDIF()
if (MSVC AND NOT BUILD_SHARED_LIBS) if (MSVC AND NOT BUILD_SHARED_LIBS)

View File

@ -69,14 +69,12 @@ if test -n "$PKG_CONFIG"; then
fi fi
fi fi
proto3_supported="no"
AC_ARG_ENABLE([protoc], 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(17, noext, mandatory)
PKG_CHECK_MODULES([protobuf], [protobuf >= 3.0.0], [proto3_supported=yes]) PKG_CHECK_MODULES([protobuf], [protobuf >= 3.0.0])
save_CPPFLAGS="$CPPFLAGS" save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$save_CPPFLAGS $protobuf_CFLAGS" CPPFLAGS="$save_CPPFLAGS $protobuf_CFLAGS"
@ -99,11 +97,8 @@ else
fi fi
AM_CONDITIONAL([BUILD_COMPILER], [test "x$enable_protoc" != "xno"]) AM_CONDITIONAL([BUILD_COMPILER], [test "x$enable_protoc" != "xno"])
AM_CONDITIONAL([BUILD_PROTO3], [test "x$proto3_supported" != "xno"])
AM_CONDITIONAL([CROSS_COMPILING], [test "x$cross_compiling" != "xno"]) AM_CONDITIONAL([CROSS_COMPILING], [test "x$cross_compiling" != "xno"])
AM_COND_IF([BUILD_PROTO3], [AC_DEFINE([HAVE_PROTO3], [1], [Support proto3 syntax])])
gl_LD_VERSION_SCRIPT gl_LD_VERSION_SCRIPT
gl_VALGRIND_TESTS gl_VALGRIND_TESTS

View File

@ -118,15 +118,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
std::string filename_identifier = FilenameIdentifier(file_->name()); std::string filename_identifier = FilenameIdentifier(file_->name());
int min_header_version = 1000000; int min_header_version = 1000000;
#if defined(HAVE_PROTO3) #if GOOGLE_PROTOBUF_VERSION >= 4023000
# if GOOGLE_PROTOBUF_VERSION >= 4023000
if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) { if (FileDescriptorLegacy(file_).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3) {
# else #else
if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) { if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) {
#endif #endif
min_header_version = 1003000; min_header_version = 1003000;
} }
#endif
// Generate top of header. // Generate top of header.
printer->Print( printer->Print(

View File

@ -175,14 +175,10 @@ int compare_name_indices_by_name(const void*, const void*);
// Return the syntax version of the file containing the field. // Return the syntax version of the file containing the field.
// 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 #if GOOGLE_PROTOBUF_VERSION >= 4023000
# if GOOGLE_PROTOBUF_VERSION >= 4023000
return FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3 ? 3 : 2; return FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::SYNTAX_PROTO3 ? 3 : 2;
# else
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2;
# endif
#else #else
return 2; return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2;
#endif #endif
} }

View File

@ -1,3 +1,5 @@
syntax = "proto2";
import "protobuf-c/protobuf-c.proto"; import "protobuf-c/protobuf-c.proto";
option (pb_c_file).use_oneof_field_name = true; option (pb_c_file).use_oneof_field_name = true;

View File

@ -1,3 +1,5 @@
syntax = "proto2";
message TopLevel { message TopLevel {
oneof submessages { oneof submessages {
MessageType1 type1 = 1; MessageType1 type1 = 1;

View File

@ -1,3 +1,5 @@
syntax = "proto2";
message two_oneofs { message two_oneofs {
oneof first_oneof { oneof first_oneof {
bool a = 10; bool a = 10;

View File

@ -1,3 +1,5 @@
syntax = "proto2";
package foo; package foo;
import "protobuf-c/protobuf-c.proto"; import "protobuf-c/protobuf-c.proto";

View File

@ -1,3 +1,5 @@
syntax = "proto2";
package foo; package foo;
option optimize_for = CODE_SIZE; option optimize_for = CODE_SIZE;

View File

@ -1,3 +1,5 @@
syntax = "proto2";
package foo; package foo;
import "protobuf-c/protobuf-c.proto"; import "protobuf-c/protobuf-c.proto";