From 7dca1c382c2096ac1324b001cea53c39052843da Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 8 Jul 2023 23:11:03 -0400 Subject: [PATCH 1/6] configure.ac: Remove `proto3_supported`, `BUILD_PROTO3` Since we require protobuf >= 3.0.0 now, the proto3 syntax is always supported. --- configure.ac | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 586ac3c..f03198a 100644 --- a/configure.ac +++ b/configure.ac @@ -69,14 +69,12 @@ if test -n "$PKG_CONFIG"; then fi fi -proto3_supported="no" - AC_ARG_ENABLE([protoc], AS_HELP_STRING([--disable-protoc], [Disable building protoc_c (also disables tests)])) if test "x$enable_protoc" != "xno"; then AC_LANG_PUSH([C++]) 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" CPPFLAGS="$save_CPPFLAGS $protobuf_CFLAGS" @@ -99,11 +97,8 @@ else fi 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_COND_IF([BUILD_PROTO3], [AC_DEFINE([HAVE_PROTO3], [1], [Support proto3 syntax])]) - gl_LD_VERSION_SCRIPT gl_VALGRIND_TESTS From 5c4be20f1bf59f1abad41d69ec3c80596d346a7f Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 8 Jul 2023 23:11:54 -0400 Subject: [PATCH 2/6] Makefile.am: Remove conditional BUILD_PROTO3 rules Now that we require protobuf >= 3.0.0, we are always building with proto3 syntax support. Note that the test-generated-code3 test keeps `-DPROTO3` which is separate from the HAVE_PROTO3 identifier. This test is building built from the same source file as test-generated-code but the source file supports proto2 and proto3 syntax depending on how it's compiled. --- Makefile.am | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/Makefile.am b/Makefile.am index 86864a7..ff12664 100644 --- a/Makefile.am +++ b/Makefile.am @@ -139,11 +139,13 @@ LOG_COMPILER = $(VALGRIND) check_PROGRAMS += \ t/generated-code/test-generated-code \ t/generated-code2/test-generated-code2 \ + t/generated-code3/test-generated-code3 \ t/version/version TESTS += \ t/generated-code/test-generated-code \ t/generated-code2/test-generated-code2 \ + t/generated-code3/test-generated-code3 \ t/version/version 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 = \ 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 += \ 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 $(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) $(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-optimized.pb-c.c t/test-optimized.pb-c.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 -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.c t_version_version_LDADD = \ @@ -278,7 +268,6 @@ EXTRA_DIST += \ t/issue251/issue251.proto # Issue #330 -if BUILD_PROTO3 check_PROGRAMS += \ t/issue330/issue330 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 BUILT_SOURCES += \ t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h +EXTRA_DIST += \ + t/issue330/issue330.proto t_issue330_issue330_SOURCES += \ 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 EXTRA_DIST += \ t/issue440/issue440.proto -endif # BUILD_PROTO3 -EXTRA_DIST += \ - t/issue330/issue330.proto # Issue #375 check_PROGRAMS += \ From 7ed03a715bce3eab94eb77b66378c984bf7e633a Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 8 Jul 2023 23:13:59 -0400 Subject: [PATCH 3/6] protoc-c/c_file.cc: Remove HAVE_PROTO3 conditional --- protoc-c/c_file.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/protoc-c/c_file.cc b/protoc-c/c_file.cc index d211a3d..ca0ad34 100644 --- a/protoc-c/c_file.cc +++ b/protoc-c/c_file.cc @@ -118,15 +118,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { std::string filename_identifier = FilenameIdentifier(file_->name()); 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) { -# else +#else if (file_->syntax() == FileDescriptor::SYNTAX_PROTO3) { #endif min_header_version = 1003000; } -#endif // Generate top of header. printer->Print( From e08fe625655dca6e095b103869e030b79e5d0df2 Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 8 Jul 2023 23:14:23 -0400 Subject: [PATCH 4/6] protoc-c/c_helpers.h: Remove HAVE_PROTO3 conditional --- protoc-c/c_helpers.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/protoc-c/c_helpers.h b/protoc-c/c_helpers.h index 055528b..062d330 100644 --- a/protoc-c/c_helpers.h +++ b/protoc-c/c_helpers.h @@ -175,14 +175,10 @@ 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) { -#ifdef HAVE_PROTO3 -# if GOOGLE_PROTOBUF_VERSION >= 4023000 +#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 #else - return 2; + return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? 3 : 2; #endif } From 824a7fed75e15b9a4cb5961593bcc46e45a79559 Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 8 Jul 2023 23:15:14 -0400 Subject: [PATCH 5/6] cmake: Remove BUILD_PROTO3, HAVE_PROTO3 --- build-cmake/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index 379dd1a..6dbf193 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -9,7 +9,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) PROJECT(protobuf-c) #options -option(BUILD_PROTO3 "BUILD_PROTO3" ON) option(BUILD_PROTOC "Build protoc-gen-c" ON) if(CMAKE_BUILD_TYPE MATCHES Debug) option(BUILD_TESTS "Build tests" ON) @@ -73,9 +72,6 @@ endif (MSVC AND NOT BUILD_SHARED_LIBS) FIND_PACKAGE(Protobuf REQUIRED) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) -if (BUILD_PROTO3) - ADD_DEFINITIONS(-DHAVE_PROTO3) -endif() ENDIF() if (MSVC AND NOT BUILD_SHARED_LIBS) From 20d45b117948e6ba94052584e082f5f5f7556495 Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Sat, 8 Jul 2023 23:19:16 -0400 Subject: [PATCH 6/6] t/: Add `syntax = "proto2";` where necessary to silence protoc Since we now require protobuf >= 3.0.0, we don't have to support older protobuf versions that don't recognize the `syntax` syntax, so we can put `syntax = "proto2";` on these proto files to silence the protoc compiler's diagnostic "No syntax specified for the proto file". --- t/issue204/issue204.proto | 2 ++ t/issue220/issue220.proto | 2 ++ t/issue251/issue251.proto | 2 ++ t/test-full.proto | 2 ++ t/test-optimized.proto | 2 ++ t/test.proto | 2 ++ 6 files changed, 12 insertions(+) diff --git a/t/issue204/issue204.proto b/t/issue204/issue204.proto index 6934570..6aa34b2 100644 --- a/t/issue204/issue204.proto +++ b/t/issue204/issue204.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import "protobuf-c/protobuf-c.proto"; option (pb_c_file).use_oneof_field_name = true; diff --git a/t/issue220/issue220.proto b/t/issue220/issue220.proto index a23d79a..ebaa4e5 100644 --- a/t/issue220/issue220.proto +++ b/t/issue220/issue220.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message TopLevel { oneof submessages { MessageType1 type1 = 1; diff --git a/t/issue251/issue251.proto b/t/issue251/issue251.proto index a451894..1c5bf0f 100644 --- a/t/issue251/issue251.proto +++ b/t/issue251/issue251.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message two_oneofs { oneof first_oneof { bool a = 10; diff --git a/t/test-full.proto b/t/test-full.proto index e723200..8c35bc5 100644 --- a/t/test-full.proto +++ b/t/test-full.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package foo; import "protobuf-c/protobuf-c.proto"; diff --git a/t/test-optimized.proto b/t/test-optimized.proto index d126881..1a090e5 100644 --- a/t/test-optimized.proto +++ b/t/test-optimized.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package foo; option optimize_for = CODE_SIZE; diff --git a/t/test.proto b/t/test.proto index 884993c..c3099db 100644 --- a/t/test.proto +++ b/t/test.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package foo; import "protobuf-c/protobuf-c.proto";