Upgrade protobuf to 27.1 and modernize codegen using new APIs (e.g. has_presence()) (#1445)

Fixes https://github.com/grpc/grpc-web/issues/1437.
This commit is contained in:
Benjamin Peterson 2024-06-24 20:58:54 -07:00 committed by GitHub
parent 8ab32b945c
commit 2c39859be8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 19 deletions

1
.bazelrc Normal file
View File

@ -0,0 +1 @@
build --copt=-Wno-error=deprecated-declarations --host_copt=-Wno-error=deprecated-declarations

View File

@ -13,10 +13,10 @@ http_archive(
http_archive( http_archive(
name = "com_google_protobuf", name = "com_google_protobuf",
sha256 = "7beed9c511d632cff7c22ac0094dd7720e550153039d5da7e059bcceb488474a", sha256 = "6fbe2e6f703bcd3a246529c2cab586ca12a98c4e641f5f71d51fde09eb48e9e7",
strip_prefix = "protobuf-25.0", strip_prefix = "protobuf-27.1",
urls = [ 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",
], ],
) )

View File

@ -841,13 +841,11 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
"set$js_field_name$(value?: $js_field_type$): " "set$js_field_name$(value?: $js_field_type$): "
"$class_name$;\n"); "$class_name$;\n");
} }
if (field->has_optional_keyword() || if (field->has_presence()) {
(field->type() == FieldDescriptor::TYPE_MESSAGE &&
!field->is_repeated() && !field->is_map())) {
printer->Print(vars, "has$js_field_name$(): boolean;\n"); printer->Print(vars, "has$js_field_name$(): boolean;\n");
} }
if (field->type() == FieldDescriptor::TYPE_MESSAGE || field->has_optional_keyword() || if (field->type() == FieldDescriptor::TYPE_MESSAGE ||
field->is_repeated() || field->is_map()) { field->has_presence() || field->is_repeated() || field->is_map()) {
printer->Print(vars, "clear$js_field_name$(): $class_name$;\n"); printer->Print(vars, "clear$js_field_name$(): $class_name$;\n");
} }
if (field->is_repeated() && !field->is_map()) { if (field->is_repeated() && !field->is_map()) {
@ -867,15 +865,13 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
printer->Print("\n"); printer->Print("\n");
} }
for (int i = 0; i < desc->oneof_decl_count(); i++) { for (int i = 0; i < desc->real_oneof_decl_count(); i++) {
const OneofDescriptor* oneof = desc->oneof_decl(i); const OneofDescriptor *oneof = desc->real_oneof_decl(i);
if (!oneof->is_synthetic()) {
vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name())); vars["js_oneof_name"] = ToUpperCamel(ParseLowerUnderscore(oneof->name()));
printer->Print( printer->Print(
vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n"); vars, "get$js_oneof_name$Case(): $class_name$.$js_oneof_name$Case;\n");
printer->Print("\n"); printer->Print("\n");
} }
}
printer->Print( printer->Print(
vars, vars,
@ -904,8 +900,7 @@ void PrintProtoDtsMessage(Printer* printer, const Descriptor* desc,
} }
vars["js_field_name"] = js_field_name; vars["js_field_name"] = js_field_name;
vars["js_field_type"] = AsObjectFieldType(field, file); vars["js_field_type"] = AsObjectFieldType(field, file);
if ((field->type() != FieldDescriptor::TYPE_MESSAGE && !field->has_optional_keyword()) || if (!field->has_presence()) {
field->is_repeated()) {
printer->Print(vars, "$js_field_name$: $js_field_type$,\n"); printer->Print(vars, "$js_field_name$: $js_field_type$,\n");
} else { } else {
printer->Print(vars, "$js_field_name$?: $js_field_type$,\n"); printer->Print(vars, "$js_field_name$?: $js_field_type$,\n");

View File

@ -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 # 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. # are rarely updated compared with the javascript files.
COPY ./WORKSPACE ./WORKSPACE COPY ./WORKSPACE ./WORKSPACE
COPY ./.bazelrc ./.bazelrc
COPY ./javascript/net/grpc/web/generator javascript/net/grpc/web/generator COPY ./javascript/net/grpc/web/generator javascript/net/grpc/web/generator
RUN bazel build javascript/net/grpc/web/generator:protoc-gen-grpc-web && \ RUN bazel build javascript/net/grpc/web/generator:protoc-gen-grpc-web && \

@ -1 +1 @@
Subproject commit 6aa539bf0195f188ff86efe6fb8bfa2b676cdd46 Subproject commit 3d9f7c430a5ae1385512908801492d4421c3cdb7