Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Protobuf Editions #4555

Open
deepakm37 opened this issue Jul 25, 2024 · 7 comments
Open

Support Protobuf Editions #4555

deepakm37 opened this issue Jul 25, 2024 · 7 comments

Comments

@deepakm37
Copy link

🚀 Feature

Protobuf is replacing the current syntax proto2 & proto3 with Editions. All future releases will be new Editions. Edition 2023 is already released as well.

The proto plugin for grpc-gateway doesn't yet support Editions. It will be great to add this support as users switch to the new syntax.

@johanbrandhorst
Copy link
Collaborator

Hi, thanks for this issue. I agree that it is important that the gateway stays up to date with the protobuf ecosystem as it evolves. Have you tried using our generators with the new editions syntax? How does it fail, if at all? I was under the impression that editions are optional and may not require any changes to generators. Are there any new features you anticipate will affect the gateway?

@deepakm37
Copy link
Author

I have tried using the current plugin (in Bazel through rules_proto_grpc_gatway) and encountered failures. As plugin doesn't explicitly notify that it supports editions, proto compilations fails. Here is a sample error message from Bazel:

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
downloaded: invalid FileDescriptorProto "service.proto": proto: invalid syntax: "editions"
--plugin_out: protoc-gen-plugin: Plugin failed with status code 1.

You're right that adding editions may not require any changes from gateway perspective. I believe if the plugin can just notify that it supports editions, without any functional changes, it should be able to handle protos in the new syntax.

@johanbrandhorst
Copy link
Collaborator

Hm, I wonder if this is just a matter of updating our dependencies. In any case, thanks for the description. Would you be able to help contribute this?

@deepakm37
Copy link
Author

Sure thing. I will take a look at the gateway plugin source. I will get back to you when I have a PR. In the mean time, please share any details that may be helpful to me, given that this would be my first contribution here. Thanks!

@johanbrandhorst
Copy link
Collaborator

The logic is all in protoc-gen-openapiv2 and protoc-gen-grpc-gateway respectively, it shouldn't be too bad to dive into, hopefully!

@deepakm37
Copy link
Author

I took a look at the plugin and included EDITION 2023 in its supported features. Unfortunately that didn't work i.e. protoc didn't complain but the generated code was not valid. Up on digging deeper, it looks like the templating and template functions need to be updated to support field presence, among other things.

I also noticed that the code generator, as it is, didn't quite work for proto2 -- for instance, using syntax = "proto2" (and making all fields optional) in //examples/internal/proto/examplepb/echo_service.proto generated invalid code as observed when building //examples/internal/proto/examplepb:examplepb_go_proto.

Let me know if I'm understanding this incorrectly. I was wrong in underestimating the changes needed to add Editions support. I will revisit this later when I have more cycles.

@johanbrandhorst
Copy link
Collaborator

Thanks for taking a look. I'm surprised to hear that proto2 syntax is causing issues, I wouldn't expect that to be the case. This might be the right time for at least the protoc-gen-grpc-gateway generator to move to something like https://github.com/protocolbuffers/protobuf-go/tree/master/compiler/protogen, though I don't know how much work that would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants