Skip to content

Commit

Permalink
Upgrade protobuf to 27.1 and modernize codegen using new APIs (e.g. h…
Browse files Browse the repository at this point in the history
…as_presence()) (#1445)

Fixes #1437.
  • Loading branch information
benjaminp authored Jun 25, 2024
1 parent 8ab32b9 commit 2c39859
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --copt=-Wno-error=deprecated-declarations --host_copt=-Wno-error=deprecated-declarations
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ http_archive(

http_archive(
name = "com_google_protobuf",
sha256 = "7beed9c511d632cff7c22ac0094dd7720e550153039d5da7e059bcceb488474a",
strip_prefix = "protobuf-25.0",
sha256 = "6fbe2e6f703bcd3a246529c2cab586ca12a98c4e641f5f71d51fde09eb48e9e7",
strip_prefix = "protobuf-27.1",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz",
"https://github.com/protocolbuffers/protobuf/releases/download/v27.1/protobuf-27.1.tar.gz",
],
)

Expand Down
25 changes: 10 additions & 15 deletions javascript/net/grpc/web/generator/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,11 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
"set$js_field_name$(value?: $js_field_type$): "
"$class_name$;\n");
}
if (field->has_optional_keyword() ||
(field->type() == FieldDescriptor::TYPE_MESSAGE &&
!field->is_repeated() && !field->is_map())) {
if (field->has_presence()) {
printer->Print(vars, "has$js_field_name$(): boolean;\n");
}
if (field->type() == FieldDescriptor::TYPE_MESSAGE || field->has_optional_keyword() ||
field->is_repeated() || field->is_map()) {
if (field->type() == FieldDescriptor::TYPE_MESSAGE ||
field->has_presence() || field->is_repeated() || field->is_map()) {
printer->Print(vars, "clear$js_field_name$(): $class_name$;\n");
}
if (field->is_repeated() && !field->is_map()) {
Expand All @@ -867,14 +865,12 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
printer->Print("\n");
}

for (int i = 0; i < desc->oneof_decl_count(); i++) {
const OneofDescriptor* oneof = desc->oneof_decl(i);
if (!oneof->is_synthetic()) {
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name()));
printer->Print(
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n");
printer->Print("\n");
}
for (int i = 0; i < desc->real_oneof_decl_count(); i++) {
const OneofDescriptor *oneof = desc->real_oneof_decl(i);
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name()));
printer->Print(
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n");
printer->Print("\n");
}

printer->Print(
Expand Down Expand Up @@ -904,8 +900,7 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
}
vars["js_field_name"] = js_field_name;
vars["js_field_type"] = AsObjectFieldType(field, file);
if ((field->type() != FieldDescriptor::TYPE_MESSAGE && !field->has_optional_keyword()) ||
field->is_repeated()) {
if (!field->has_presence()) {
printer->Print(vars, "$js_field_name$: $js_field_type$,\n");
} else {
printer->Print(vars, "$js_field_name$?: $js_field_type$,\n");
Expand Down
1 change: 1 addition & 0 deletions net/grpc/gateway/docker/prereqs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ WORKDIR /github/grpc-web
# Copy only files necessary to build the protoc-gen-grpc-web first as an optimization because they
# are rarely updated compared with the javascript files.
COPY ./WORKSPACE ./WORKSPACE
COPY ./.bazelrc ./.bazelrc
COPY ./javascript/net/grpc/web/generator javascript/net/grpc/web/generator

RUN bazel build javascript/net/grpc/web/generator:protoc-gen-grpc-web && \
Expand Down
2 changes: 1 addition & 1 deletion third_party/protobuf
Submodule protobuf updated 3720 files

0 comments on commit 2c39859

Please sign in to comment.