From 14404e5fbc6a54c10f9d9318cbddf21401d82bcf Mon Sep 17 00:00:00 2001 From: Tony Liao Date: Sun, 19 Apr 2026 14:17:09 -0700 Subject: [PATCH] Add Edition 2026 to protoc as a "known edition". Notably, this does not yet enable protoc users to compile Edition 2026 files on their own. EDITION_2026 needs to be added to protoc first as a "known edition" to enable internal testing builds before it is released to users. PiperOrigin-RevId: 902280590 --- editions/BUILD | 13 ++++++++++ .../test_editions_2026_default_features.proto | 24 +++++++++++++++++++ src/google/protobuf/compiler/code_generator.h | 2 +- .../compiler/code_generator_unittest.cc | 16 ++++++++++++- .../command_line_interface_unittest.cc | 4 ++-- .../protobuf/compiler/java/java_features.pb.h | 2 +- src/google/protobuf/cpp_features.pb.h | 2 +- 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 editions/input/test_editions_2026_default_features.proto diff --git a/editions/BUILD b/editions/BUILD index 85fd1fc2e6293..fcb5ce83ef0c3 100644 --- a/editions/BUILD +++ b/editions/BUILD @@ -401,11 +401,24 @@ cc_proto_library( deps = [":test_editions_2024_default_features_proto"], ) +proto_library( + name = "test_editions_2026_default_features_proto", + testonly = True, + srcs = ["input/test_editions_2026_default_features.proto"], +) + +cc_proto_library( + name = "test_editions_2026_default_features_cc_proto", + testonly = True, + deps = [":test_editions_2026_default_features_proto"], +) + cc_test( name = "generated_files_test", srcs = ["generated_files_test.cc"], deps = [ ":test_editions_2024_default_features_cc_proto", + ":test_editions_2026_default_features_cc_proto", ":test_editions_default_features_cc_proto", ":test_messages_proto2_editions_cc_proto", ":test_messages_proto3_editions_cc_proto", diff --git a/editions/input/test_editions_2026_default_features.proto b/editions/input/test_editions_2026_default_features.proto new file mode 100644 index 0000000000000..bcb18ae21f0cc --- /dev/null +++ b/editions/input/test_editions_2026_default_features.proto @@ -0,0 +1,24 @@ +edition = "2026"; + +package protobuf_editions_test; + +// This file tests the default Edition2024 features in the absence of any +// dependencies. + +enum Editions2026DefaultEnum { + EDITIONS2026_DEFAULT_ENUM_UNKNOWN = 0; + EDITIONS2026_DEFAULT_ENUM_VALUE1 = 1; +} + +message Editions2026DefaultMessage { + int32 int32_field = 1; + string string_field = 2; + Editions2026DefaultEnum enum_field = 3; + + repeated int32 repeated_int32_field = 4; + + message SubMessage { + int32 nested_int32_field = 1; + } + SubMessage sub_message_field = 6; +} diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index 6b2dff2fd8701..9d515da0179d4 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -184,7 +184,7 @@ constexpr auto ProtocMaximumEdition() { return Edition::EDITION_2024; } // The maximum edition known to protoc, which may or may not be officially // supported yet. During development of a new edition, this will typically be // set to that. -constexpr auto MaximumKnownEdition() { return Edition::EDITION_2024; } +constexpr auto MaximumKnownEdition() { return Edition::EDITION_2026; } // CodeGenerators generate one or more files in a given directory. This // abstract interface represents the directory to which the CodeGenerator is diff --git a/src/google/protobuf/compiler/code_generator_unittest.cc b/src/google/protobuf/compiler/code_generator_unittest.cc index 852fd7dd9ee5c..2b4299f7ab186 100644 --- a/src/google/protobuf/compiler/code_generator_unittest.cc +++ b/src/google/protobuf/compiler/code_generator_unittest.cc @@ -505,8 +505,22 @@ TEST_F(CodeGeneratorTest, BuildFeatureSetDefaults) { } fixed_features {} } + defaults { + edition: EDITION_UNSTABLE + overridable_features { + field_presence: EXPLICIT + enum_type: OPEN + repeated_field_encoding: PACKED + utf8_validation: VERIFY + message_encoding: LENGTH_PREFIXED + json_format: ALLOW + enforce_naming_style: STYLE2026 + default_symbol_visibility: EXPORT_TOP_LEVEL + } + fixed_features {} + } minimum_edition: EDITION_PROTO2 - maximum_edition: EDITION_2024 + maximum_edition: EDITION_2026 )pb"))); } diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 7a8f1c68e7e6d..c192510208f91 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -1977,7 +1977,7 @@ TEST_F(CommandLineInterfaceTest, Plugin_VersionSkewFuture) { ExpectErrorSubstring( "foo.proto:2:5: Edition 99997_TEST_ONLY is later than the maximum " - "supported edition 2024"); + "supported edition 2026"); } TEST_F(CommandLineInterfaceTest, Plugin_VersionSkewPast) { @@ -2318,7 +2318,7 @@ TEST_F(CommandLineInterfaceTest, ExpectErrorSubstring( absl::StrCat("Edition 99997_TEST_ONLY is later than the maximum " "supported edition ", - ProtocMaximumEdition())); + MaximumKnownEdition())); } TEST_F(CommandLineInterfaceTest, UnstableEditionWithFlag) { diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 43fe3254b3328..ebcbd296dcc41 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -89,7 +89,7 @@ internal::EnumTraitsT<::pb::JavaFeatures_Utf8Validation_internal_data_> namespace internal { template <> inline ::absl::string_view GetFeatureSetDefaultsData<::pb::JavaFeatures>() { - static constexpr char kDefaults[] = "CicYhAciA8o+ACodCAEQAhgCIAMoATACOAJAAco+CggBEAEYACABKAMKJxjnByIDyj4AKh0IAhABGAEgAigBMAE4AkAByj4KCAAQARgAIAEoAwonGOgHIhMIARABGAEgAigBMAHKPgQIABABKg04AkAByj4GGAAgASgDCicY6QciGwgBEAEYASACKAEwATgBQALKPggIABABGAAoASoFyj4CIAAg5gco6Qc="; + static constexpr char kDefaults[] = "CicYhAciA8o+ACodCAEQAhgCIAMoATACOAJAAco+CggBEAEYACABKAMKJxjnByIDyj4AKh0IAhABGAEgAigBMAE4AkAByj4KCAAQARgAIAEoAwonGOgHIhMIARABGAEgAigBMAHKPgQIABABKg04AkAByj4GGAAgASgDCicY6QciGwgBEAEYASACKAEwATgBQALKPggIABABGAAoASoFyj4CIAAKJxjqByIbCAEQARgBIAIoATABOANAAso+CAgAEAEYACgBKgXKPgIgACDmByjqBw=="; return kDefaults; } } // namespace internal diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index ab8f26be9ba06..196281461b349 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -80,7 +80,7 @@ internal::EnumTraitsT<::pb::CppFeatures_StringType_internal_data_> namespace internal { template <> inline ::absl::string_view GetFeatureSetDefaultsData<::pb::CppFeatures>() { - static constexpr char kDefaults[] = "CiUYhAciA8I+ACobCAEQAhgCIAMoATACOAJAAcI+CAgBEAMYACABCiUY5wciA8I+ACobCAIQARgBIAIoATABOAJAAcI+CAgAEAMYACABCiUY6AciEwgBEAEYASACKAEwAcI+BAgAEAMqCzgCQAHCPgQYACABCiUY6QciGQgBEAEYASACKAEwATgBQALCPgYIABABGAEqBcI+AiABCiUYj04iGwgBEAEYASACKAEwATgDQALCPggIABABGAEgASoDwj4AIOYHKOkH"; + static constexpr char kDefaults[] = "CiUYhAciA8I+ACobCAEQAhgCIAMoATACOAJAAcI+CAgBEAMYACABCiUY5wciA8I+ACobCAIQARgBIAIoATABOAJAAcI+CAgAEAMYACABCiUY6AciEwgBEAEYASACKAEwAcI+BAgAEAMqCzgCQAHCPgQYACABCiUY6QciGQgBEAEYASACKAEwATgBQALCPgYIABABGAEqBcI+AiABCiUY6gciGQgBEAEYASACKAEwATgDQALCPgYIABABGAEqBcI+AiABCiUYj04iGwgBEAEYASACKAEwATgDQALCPggIABABGAEgASoDwj4AIOYHKOoH"; return kDefaults; } } // namespace internal