protocolbuffers / protobuf-javascript

BSD 3-Clause "New" or "Revised" License
375 stars 67 forks source link

Cannot build js generator with latest protobuf (v26.0+ not supported) #206

Closed kgreenek closed 5 months ago

kgreenek commented 5 months ago

Using the latest version of protobuf (v27.1), I see the following compiler errors when trying to compile the javascript generator:

external/com_google_protobuf_javascript/generator/js_generator.cc:457:7: error: 'OneofDescriptorLegacy' was not declared in this scope; did you mean 'FileDescriptorLegacy'?
  457 |   if (OneofDescriptorLegacy(oneof).is_synthetic()) return true;
      |       ^~~~~~~~~~~~~~~~~~~~~
      |       FileDescriptorLegacy
external/com_google_protobuf_javascript/generator/js_generator.cc: In function 'std::string google::protobuf::compiler::js::{anonymous}::JSOneofIndex(const google::protobuf::OneofDescriptor*)':
external/com_google_protobuf_javascript/generator/js_generator.cc:566:9: error: 'OneofDescriptorLegacy' was not declared in this scope; did you mean 'FileDescriptorLegacy'?
  566 |     if (OneofDescriptorLegacy(o).is_synthetic()) continue;
      |         ^~~~~~~~~~~~~~~~~~~~~
      |         FileDescriptorLegacy
external/com_google_protobuf_javascript/generator/js_generator.cc: In function 'bool google::protobuf::compiler::js::{anonymous}::InRealOneof(const google::protobuf::FieldDescriptor*)':
external/com_google_protobuf_javascript/generator/js_generator.cc:787:11: error: 'OneofDescriptorLegacy' was not declared in this scope; did you mean 'FileDescriptorLegacy'?
  787 |          !OneofDescriptorLegacy(field->containing_oneof()).is_synthetic();
      |           ^~~~~~~~~~~~~~~~~~~~~
      |           FileDescriptorLegacy
external/com_google_protobuf_javascript/generator/js_generator.cc: In function 'bool google::protobuf::compiler::js::{anonymous}::DeclaredReturnTypeIsNullable(const google::protobuf::compiler::js::GeneratorOptions&, const google::protobuf::FieldDescriptor*)':
external/com_google_protobuf_javascript/generator/js_generator.cc:987:43: error: 'class google::protobuf::FileDescriptorLegacy' has no member named 'syntax'
  987 |   if (FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
      |                                           ^~~~~~
external/com_google_protobuf_javascript/generator/js_generator.cc:987:77: error: 'google::protobuf::FileDescriptorLegacy::Syntax' has not been declared
  987 |   if (FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
      |                                                                             ^~~~~~
external/com_google_protobuf_javascript/generator/js_generator.cc: In member function 'void google::protobuf::compiler::js::Generator::GenerateClassFieldToObject(const google::protobuf::compiler::js::GeneratorOptions&, google::protobuf::io::Printer*, const google::protobuf::FieldDescriptor*) const':
external/com_google_protobuf_javascript/generator/js_generator.cc:2350:45: error: 'class google::protobuf::FileDescriptorLegacy' has no member named 'syntax'
 2350 |     if (FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
      |                                             ^~~~~~
external/com_google_protobuf_javascript/generator/js_generator.cc:2350:79: error: 'google::protobuf::FileDescriptorLegacy::Syntax' has not been declared
 2350 |     if (FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
      |                                                                               ^~~~~~
external/com_google_protobuf_javascript/generator/js_generator.cc: In member function 'void google::protobuf::compiler::js::Generator::GenerateClassField(const google::protobuf::compiler::js::GeneratorOptions&, google::protobuf::io::Printer*, const google::protobuf::FieldDescriptor*) const':
external/com_google_protobuf_javascript/generator/js_generator.cc:2758:45: error: 'class google::protobuf::FileDescriptorLegacy' has no member named 'syntax'
 2758 |     if (FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
      |                                             ^~~~~~
external/com_google_protobuf_javascript/generator/js_generator.cc:2758:79: error: 'google::protobuf::FileDescriptorLegacy::Syntax' has not been declared
 2758 |     if (FileDescriptorLegacy(field->file()).syntax() == FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 &&
      | 

It looks like perhaps the latest version might have removed some legacy classes.

dibenede commented 5 months ago

Thank you for reporting this. I think your assessment is correct and we are falling behind protobuf's developments.

kgreenek commented 5 months ago

Can confirm the syntax() method was removed in this commit, which was part of release v26.0 (https://github.com/protocolbuffers/protobuf/commit/cf2d6965dcb6e15490232041da8b7b6c8ec669eb#diff-faab3ee51729cba39d00c0691c6b9905ec3eca43da31dcd09af3e4ffd0d1a6a3L1860).

Relevant comment:

  // With the upcoming release of editions, syntax should not be used for
  // business logic.  Instead, the various feature helpers defined in this file
  // should be used to query more targeted behaviors.  For example:
  // has_presence, is_closed, requires_utf8_validation.

I think this PR removed the Legacy class used in js_generator.cc. That change was also was released in protobuf v26.0 (https://github.com/protocolbuffers/protobuf/pull/15709).