Skip to content

Commit e44d421

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Enable edition 2024 in upb generators
PiperOrigin-RevId: 825760735
1 parent fe46538 commit e44d421

File tree

9 files changed

+92
-4
lines changed

9 files changed

+92
-4
lines changed

upb/test/BUILD

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ proto_library(
9090
name = "editions_test_proto",
9191
testonly = 1,
9292
srcs = ["editions_test.proto"],
93+
option_deps = [
94+
":custom_options_proto",
95+
":custom_options_unlinked_proto",
96+
],
9397
)
9498

9599
upb_c_proto_library(
@@ -192,11 +196,18 @@ cc_test(
192196
srcs = ["editions_test.cc"],
193197
copts = UPB_DEFAULT_CPPOPTS,
194198
deps = [
199+
":custom_options_upb_c_proto",
200+
":custom_options_upb_minitable_proto",
201+
":custom_options_upb_proto_reflection",
195202
":editions_test_upb_c_proto",
196203
":editions_test_upb_proto_reflection",
197204
"//upb/base",
198205
"//upb/mem",
206+
"//upb/message",
207+
"//upb/mini_table",
208+
"//upb/port",
199209
"//upb/reflection",
210+
"//upb/reflection:descriptor_upb_proto",
200211
"@googletest//:gtest",
201212
"@googletest//:gtest_main",
202213
],
@@ -305,6 +316,38 @@ proto_library(
305316
deps = [":empty_srcs_3_proto"],
306317
)
307318

319+
proto_library(
320+
name = "custom_options_unlinked_proto",
321+
testonly = 1,
322+
srcs = ["custom_options_unlinked.proto"],
323+
deps = ["//:descriptor_proto"],
324+
)
325+
326+
proto_library(
327+
name = "custom_options_proto",
328+
testonly = 1,
329+
srcs = ["custom_options.proto"],
330+
deps = ["//:descriptor_proto"],
331+
)
332+
333+
upb_c_proto_library(
334+
name = "custom_options_upb_c_proto",
335+
testonly = 1,
336+
deps = [":custom_options_proto"],
337+
)
338+
339+
upb_minitable_proto_library(
340+
name = "custom_options_upb_minitable_proto",
341+
testonly = 1,
342+
deps = [":custom_options_proto"],
343+
)
344+
345+
upb_proto_reflection_library(
346+
name = "custom_options_upb_proto_reflection",
347+
testonly = 1,
348+
deps = [":custom_options_proto"],
349+
)
350+
308351
upb_minitable_proto_library(
309352
name = "test_import_empty_srcs_upb_minitable_proto",
310353
testonly = 1,

upb/test/custom_options.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
edition = "2024";
2+
3+
package upb;
4+
5+
import "google/protobuf/descriptor.proto";
6+
7+
extend google.protobuf.MessageOptions {
8+
int32 message_opt = 7739036;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
edition = "2024";
2+
3+
package upb;
4+
5+
import "google/protobuf/descriptor.proto";
6+
7+
extend google.protobuf.MessageOptions {
8+
int32 message_opt_unlinked = 7739037;
9+
}

upb/test/editions_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
// license that can be found in the LICENSE file or at
66
// https://developers.google.com/open-source/licenses/bsd
77

8+
#include <stdint.h>
9+
810
#include <gtest/gtest.h>
911
#include "upb/base/descriptor_constants.h"
12+
#include "upb/base/upcast.h"
1013
#include "upb/mem/arena.hpp"
14+
#include "upb/message/message.h"
15+
#include "upb/port/def.inc"
1116
#include "upb/reflection/def.hpp"
17+
#include "upb/reflection/descriptor_bootstrap.h"
1218
#include "upb/test/editions_test.upb.h"
1319
#include "upb/test/editions_test.upbdefs.h"
1420

@@ -54,6 +60,18 @@ TEST(EditionsTest, PackedField) {
5460
ASSERT_FALSE(f.packed());
5561
}
5662

63+
TEST(EditionsTest, ImportOptionUnlinked) {
64+
// Test that unlinked option dependencies show up in unknown fields. These
65+
// are optional dependencies that may or may not be present in the binary.
66+
67+
upb::Arena arena;
68+
upb::DefPool defpool;
69+
upb::MessageDefPtr md(upb_test_2023_EditionsMessage_getmsgdef(defpool.ptr()));
70+
const google_protobuf_MessageOptions* options = md.options();
71+
72+
EXPECT_TRUE(upb_Message_HasUnknown(UPB_UPCAST(options)));
73+
}
74+
5775
TEST(EditionsTest, ConstructProto) {
5876
// Doesn't do anything except construct the proto. This just verifies that
5977
// the generated code compiles successfully.

upb/test/editions_test.proto

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
// license that can be found in the LICENSE file or at
66
// https://developers.google.com/open-source/licenses/bsd
77

8-
edition = "2023";
8+
edition = "2024";
99

1010
package upb.test_2023;
1111

12+
import option "upb/test/custom_options.proto";
13+
import option "upb/test/custom_options_unlinked.proto";
14+
15+
option features.enforce_naming_style = STYLE_LEGACY;
16+
1217
message EditionsMessage {
18+
option (upb.message_opt) = 87;
19+
option (upb.message_opt_unlinked) = 9;
20+
1321
int32 plain_field = 1;
1422
int32 implicit_presence_field = 2 [features.field_presence = IMPLICIT];
1523
int32 required_field = 3 [features.field_presence = LEGACY_REQUIRED];

upb_generator/bootstrap_compiler.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _bootstrap_visibility = [
2828
"//third_party/upb/github:__pkg__",
2929
"//upb_generator:__subpackages__",
3030
"//upb/reflection:__pkg__",
31+
"//upb/test:__pkg__",
3132
"//upb:__pkg__", # For the amalgamations.
3233
"//python/dist:__pkg__", # For the Python source package.
3334
"//:__pkg__", # For protoc

upb_generator/c/generator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ class CGenerator : public google::protobuf::compiler::CodeGenerator {
13571357
return google::protobuf::Edition::EDITION_PROTO2;
13581358
}
13591359
google::protobuf::Edition GetMaximumEdition() const override {
1360-
return google::protobuf::Edition::EDITION_2023;
1360+
return google::protobuf::Edition::EDITION_2024;
13611361
}
13621362
};
13631363

upb_generator/minitable/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class MiniTableGenerator : public google::protobuf::compiler::CodeGenerator {
115115
return google::protobuf::Edition::EDITION_PROTO2;
116116
}
117117
google::protobuf::Edition GetMaximumEdition() const override {
118-
return google::protobuf::Edition::EDITION_2023;
118+
return google::protobuf::Edition::EDITION_2024;
119119
}
120120
};
121121

upb_generator/reflection/generator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ReflectionGenerator : public google::protobuf::compiler::CodeGenerator {
8484
return google::protobuf::Edition::EDITION_PROTO2;
8585
}
8686
google::protobuf::Edition GetMaximumEdition() const override {
87-
return google::protobuf::Edition::EDITION_2023;
87+
return google::protobuf::Edition::EDITION_2024;
8888
}
8989
};
9090

0 commit comments

Comments
 (0)