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

implement a protoc plugin #750

Closed
henrikrudstrom opened this issue Aug 29, 2021 · 5 comments
Closed

implement a protoc plugin #750

henrikrudstrom opened this issue Aug 29, 2021 · 5 comments
Labels
C-enhancement Category: New feature or request E-hard Call for participation: Experience needed to fix: Hard / a lot E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@henrikrudstrom
Copy link

Feature Request

Would be very useful to be able to use tonic as a plugin for protoc. We are currently trying to coordinate our .proto files using a dedicated repo and use CI to generate the code. for our other languages we can use protoc (or actually buf/build which is a drop in replacement for protoc).
Having a protoc plugin would make it much easier to integrate tonic with other tooling.

I have made a naive attempt at creating a protoc-plugin by using tonic_build to generate files to a tmp directory and reading those.

Althoug a bit clunky it worked, but i dont think its an ideal solution

  • Generating files and reading them is a bit of a workaround (due to my lacking knowledge of rust and tonic)
  • It has several runtime dependencies that make the container very bloated (protoc is used under the hood for the prost part i believe)
  • rustfmt is a runtime dependency requiring the rust toolchain in the container.

I think tooling for generating and sharing protobuf/grpc implementations is getting more prevalent, so i think having a protoc-plugin would be valuable, and i would be happy to dig in and contribute to that, im curious if that is already somthing that is being considered and/or welcomed.

@davidpdrsn
Copy link
Member

I'm not very familiar with how protoc actually works. I've only ever used it in directly through prost. So not sure what you mean by "protoc plugin".

Regardless, this feels more like a prost issue than a tonic issue. Tonic doesn't actually do any protobuf compilation itself. For that it uses prost.

And the rustfmt dependency can be disabled with the cargo feature: tonic-build = { version = "0.5", default_features = false, features = ["transport", "prost"] }.

@cortopy
Copy link
Contributor

cortopy commented Sep 3, 2021

I was just going to create a request like this one!

@davidpdrsn A protoc plugin is defined here: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin

In short, a plugin is a binary which protoc can invoke when building proto files. The syntax is something like:

protoc --plugin=protoc-gen-NAME=path/to/mybinary --NAME_out=OUT_DIR

They often follow the convention protoc-gen-LANGUAGE_NAME.

There are plugins for many languages. For example:

Please note that these are not plugins to build proto files, but code generation tools. I may be wrong but this would be the equivalent of what tonic_build does with cargo. A plugin would make Rust code generation compatible with other tools and not just cargo

The biggest difference is that by having a plugin:

  • there is no need to have the proto files physically in the machine. The great Buf can generate server and client code from proto files hosted in a repo remotely
  • Rust is no longer a "special case" but follows the same patterns for generating code as other languages
  • no more copy/paste, git submodules, etc. to generate client code in other languages/repos

@LucioFranco LucioFranco added C-enhancement Category: New feature or request E-hard Call for participation: Experience needed to fix: Hard / a lot E-help-wanted Call for participation: Help is requested to fix this issue. labels Oct 13, 2021
@LucioFranco
Copy link
Member

We have a similar PR in prost to support this from the protobuf generation side tokio-rs/prost#492

@g0hl1n
Copy link
Contributor

g0hl1n commented Mar 31, 2022

just wanted to mention Tuetuopay/protoc-gen-tonic here as I came across the topic 😉

@ahollmann
Copy link

I guess this can be closed as a plugin was implemented and released:

https://github.com/neoeinstein/protoc-gen-prost
https://crates.io/crates/protoc-gen-prost
https://crates.io/crates/protoc-gen-tonic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: New feature or request E-hard Call for participation: Experience needed to fix: Hard / a lot E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

No branches or pull requests

6 participants