diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 4539e5fcb88f9..0ef0e64d45c47 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -1375,21 +1375,14 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* p) { IncludeFile("third_party/protobuf/port_def.inc", p); p->Emit( { - {"min_version", PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC}, {"version", PROTOBUF_VERSION}, }, R"( - #if PROTOBUF_VERSION < $min_version$ - #error "This file was generated by a newer version of protoc which is" - #error "incompatible with your Protocol Buffer headers. Please update" - #error "your headers." - #endif // PROTOBUF_VERSION - - #if $version$ < PROTOBUF_MIN_PROTOC_VERSION - #error "This file was generated by an older version of protoc which is" - #error "incompatible with your Protocol Buffer headers. Please" - #error "regenerate this file with a newer version of protoc." - #endif // PROTOBUF_MIN_PROTOC_VERSION + #if PROTOBUF_VERSION != $version$ + #error "Protobuf C++ gencode is built with an incompatible version of" + #error "Protobuf C++ headers/runtime. See" + #error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" + #endif )"); IncludeFile("third_party/protobuf/port_undef.inc", p); } diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 17dbae00efe07..5794d1397e508 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -11,17 +11,11 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION - -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION +#if PROTOBUF_VERSION != 4026000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif #include "google/protobuf/port_undef.inc" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 80fc7fd4aa4b2..5175f3993134f 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -11,17 +11,11 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION - -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION +#if PROTOBUF_VERSION != 4026000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif #include "google/protobuf/port_undef.inc" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index bf0c77ff011e2..7f653c99b2170 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -11,17 +11,11 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION - -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION +#if PROTOBUF_VERSION != 4026000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif #include "google/protobuf/port_undef.inc" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 5df785680c382..2e0812323068a 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -11,17 +11,11 @@ #include #include "google/protobuf/port_def.inc" -#if PROTOBUF_VERSION < 4025000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION - -#if 4025000 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION +#if PROTOBUF_VERSION != 4026000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif #include "google/protobuf/port_undef.inc" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/arena.h" diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 42ffca6fd62c3..9320a0bb6cbfb 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -192,20 +192,12 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #endif +// Defines the Protobuf C++ Version for checking version compatibility at +// compilation time. #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 4025000 - -#ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC -#error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined -#endif -#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC 4025000 - -#ifdef PROTOBUF_MIN_PROTOC_VERSION -#error PROTOBUF_MIN_PROTOC_VERSION was previously defined -#endif -#define PROTOBUF_MIN_PROTOC_VERSION 4025000 +#define PROTOBUF_VERSION 4026000 #ifdef PROTOBUF_VERSION_SUFFIX #error PROTOBUF_VERSION_SUFFIX was previously defined @@ -319,10 +311,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #define PROTOBUF_IGNORE_DEPRECATION_STOP #endif -// The minimum library version which works with the current version of the -// headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 4025000 - #ifdef PROTOBUF_RTTI #error PROTOBUF_RTTI was previously defined #endif diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 3f20dfb0bab8e..04ddeaecf771d 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -40,8 +40,6 @@ #undef PROTOBUF_MINIMUM_EDITION #undef PROTOBUF_MAXIMUM_EDITION #undef PROTOBUF_FIELD_OFFSET -#undef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC -#undef PROTOBUF_MIN_PROTOC_VERSION #undef PROTOBUF_PREDICT_TRUE #undef PROTOBUF_PREDICT_FALSE #undef PROTOBUF_EXPORT diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index faff493a4e90f..3313150d15e53 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -41,38 +41,21 @@ namespace protobuf { namespace internal { -void VerifyVersion(int headerVersion, - int minLibraryVersion, - const char* filename) { - if (GOOGLE_PROTOBUF_VERSION < minLibraryVersion) { - // Library is too old for headers. +void VerifyVersion(int protobufVersionCompiledWith, const char* filename) { + // If the user's program is linked against a different version of Protobuf, + // GOOGLE_PROTOBUF_VERSION will have a different value. + if (GOOGLE_PROTOBUF_VERSION != protobufVersionCompiledWith) { ABSL_LOG(FATAL) - << "This program requires version " << VersionString(minLibraryVersion) - << " of the Protocol Buffer runtime library, but the installed version " - "is " + << "This program was compiled with Protobuf C++ version " + << VersionString(protobufVersionCompiledWith) + << ", but the linked version is " << VersionString(GOOGLE_PROTOBUF_VERSION) - << ". Please update " - "your library. If you compiled the program yourself, make sure " - "that " + << ". Please update your library. If you compiled the program " + "yourself, make sure that" "your headers are from the same version of Protocol Buffers as your " "link-time library. (Version verification failed in \"" << filename << "\".)"; } - if (headerVersion < kMinHeaderVersionForLibrary) { - // Headers are too old for library. - ABSL_LOG(FATAL) - << "This program was compiled against version " - << VersionString(headerVersion) - << " of the Protocol Buffer runtime " - "library, which is not compatible with the installed version (" - << VersionString(GOOGLE_PROTOBUF_VERSION) - << "). Contact the program " - "author for an update. If you compiled the program yourself, make " - "sure that your headers are from the same version of Protocol " - "Buffers " - "as your link-time library. (Version verification failed in \"" - << filename << "\".)"; - } } std::string VersionString(int version) { diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 2a95199d545a8..459bd15d16e2f 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -13,6 +13,7 @@ #define GOOGLE_PROTOBUF_COMMON_H__ #include +#include #include #include #include @@ -44,27 +45,14 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 4025000 +#define GOOGLE_PROTOBUF_VERSION 4026000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" -// The minimum header version which works with the current version of -// the library. This constant should only be used by protoc's C++ code -// generator. -static const int kMinHeaderVersionForLibrary = 4025000; - -// The minimum protoc version which works with the current version of the -// headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 4025000 - -// The minimum header version which works with the current version of -// protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 4025000; - -// Verifies that the headers and libraries are compatible. Use the macro -// below to call this. -void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, +// Verifies that the protobuf version a program was compiled with matches what +// it is linked/running with. Use the macro below to call this function. +void PROTOBUF_EXPORT VerifyVersion(int protobufVersionCompiledWith, const char* filename); // Converts a numeric version number to a string. @@ -81,9 +69,8 @@ ProtocVersionString(int version); // NOLINT(runtime/string) // to use the protobuf library) to verify that the version you link against // matches the headers you compiled against. If a version mismatch is // detected, the process will abort. -#define GOOGLE_PROTOBUF_VERIFY_VERSION \ - ::google::protobuf::internal::VerifyVersion( \ - GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, __FILE__) +#define GOOGLE_PROTOBUF_VERIFY_VERSION \ + ::google::protobuf::internal::VerifyVersion(GOOGLE_PROTOBUF_VERSION, __FILE__) // This lives in message_lite.h now, but we leave this here for any users that // #include common.h and not message_lite.h.