Skip to content

Commit 2c39859

Browse files
authored
Upgrade protobuf to 27.1 and modernize codegen using new APIs (e.g. has_presence()) (#1445)
Fixes #1437.
1 parent 8ab32b9 commit 2c39859

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build --copt=-Wno-error=deprecated-declarations --host_copt=-Wno-error=deprecated-declarations

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ http_archive(
1313

1414
http_archive(
1515
name = "com_google_protobuf",
16-
sha256 = "7beed9c511d632cff7c22ac0094dd7720e550153039d5da7e059bcceb488474a",
17-
strip_prefix = "protobuf-25.0",
16+
sha256 = "6fbe2e6f703bcd3a246529c2cab586ca12a98c4e641f5f71d51fde09eb48e9e7",
17+
strip_prefix = "protobuf-27.1",
1818
urls = [
19-
"https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz",
19+
"https://github.com/protocolbuffers/protobuf/releases/download/v27.1/protobuf-27.1.tar.gz",
2020
],
2121
)
2222

javascript/net/grpc/web/generator/grpc_generator.cc

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,11 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
841841
"set$js_field_name$(value?: $js_field_type$): "
842842
"$class_name$;\n");
843843
}
844-
if (field->has_optional_keyword() ||
845-
(field->type() == FieldDescriptor::TYPE_MESSAGE &&
846-
!field->is_repeated() && !field->is_map())) {
844+
if (field->has_presence()) {
847845
printer->Print(vars, "has$js_field_name$(): boolean;\n");
848846
}
849-
if (field->type() == FieldDescriptor::TYPE_MESSAGE || field->has_optional_keyword() ||
850-
field->is_repeated() || field->is_map()) {
847+
if (field->type() == FieldDescriptor::TYPE_MESSAGE ||
848+
field->has_presence() || field->is_repeated() || field->is_map()) {
851849
printer->Print(vars, "clear$js_field_name$(): $class_name$;\n");
852850
}
853851
if (field->is_repeated() && !field->is_map()) {
@@ -867,14 +865,12 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
867865
printer->Print("\n");
868866
}
869867

870-
for (int i = 0; i < desc->oneof_decl_count(); i++) {
871-
const OneofDescriptor* oneof = desc->oneof_decl(i);
872-
if (!oneof->is_synthetic()) {
873-
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name()));
874-
printer->Print(
875-
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n");
876-
printer->Print("\n");
877-
}
868+
for (int i = 0; i < desc->real_oneof_decl_count(); i++) {
869+
const OneofDescriptor *oneof = desc->real_oneof_decl(i);
870+
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name()));
871+
printer->Print(
872+
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n");
873+
printer->Print("\n");
878874
}
879875

880876
printer->Print(
@@ -904,8 +900,7 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
904900
}
905901
vars["js_field_name"] = js_field_name;
906902
vars["js_field_type"] = AsObjectFieldType(field, file);
907-
if ((field->type() != FieldDescriptor::TYPE_MESSAGE && !field->has_optional_keyword()) ||
908-
field->is_repeated()) {
903+
if (!field->has_presence()) {
909904
printer->Print(vars, "$js_field_name$: $js_field_type$,\n");
910905
} else {
911906
printer->Print(vars, "$js_field_name$?: $js_field_type$,\n");

net/grpc/gateway/docker/prereqs/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ WORKDIR /github/grpc-web
7575
# Copy only files necessary to build the protoc-gen-grpc-web first as an optimization because they
7676
# are rarely updated compared with the javascript files.
7777
COPY ./WORKSPACE ./WORKSPACE
78+
COPY ./.bazelrc ./.bazelrc
7879
COPY ./javascript/net/grpc/web/generator javascript/net/grpc/web/generator
7980

8081
RUN bazel build javascript/net/grpc/web/generator:protoc-gen-grpc-web && \

third_party/protobuf

Submodule protobuf updated 3720 files

0 commit comments

Comments
 (0)