-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proposal: protoc-gen-go: provide first-class support for plugins? #547
Comments
I think the path forward should not focus on providing a way to extend We can put plugins into two categories:
For the first type of plugins, a way to modify For the second type (which is also the common case), they can generate separate go files with the same package name with additional methods in it. Therefore they can run separately from Either way, a framework for writing go protoc plugin would be awesome. |
Plugins were instrumental in allowing us to use protobufs at Square to create our own Sake-alike and to add GRPC support. For instance, we had the ability to query service descriptors for years before GRPC added it as a supported function, and generated the requisite serialized descriptors using a plugin. In the past, almost all suggestions, pull request, feature requests, etc. related to making plugins play more easily with each other were fobbed off with the response that it was an internal-only, unsupported thing. So we wound up doing it anyway, except with far more pain. I believe it is a false dichotomy. It doesn't need to be be fully supported, with a backwards compatibility guarantee against breaking changes OR completely unsupported and completely immune to all improvements and making the interfaces more humane. Why not have an as-decent-as-possible plugin architecture, with no stability guarantees? Right now we have a set of ugly forks, kludgy workarounds, and general hackiness, with no stability guarantee. |
The question to answer is what sorts of operations we can support in plugins. I don't think we can support modification of the generated types in any meaningful fashion. Either the modifications we allow are so constrained as to be useless, or impossible to make any meaningful compatibility guarantee about. I'd be interested to hear specific counterexamples if there are any. What we do (sort of) support is generating additional code. This actually doesn't need to be done as a protoc-gen-go plugin at all--you can write a program which runs as a protoc plugin (the same way protoc-gen-go does), parses the CodeGeneratorRequest, and produces whatever output it desires. Arguably this is what we should have done for grpc. Under this approach, the generated grpc (or whatever) service definitions end up in a different file (possibly in the same Go package, possibly not), but I don't see that as a negative. |
That is a good point. You can always generate more code to add functionality. There are also places where support for interception/modification of existing functionality would be helpful, but I have work to do before submitting a particular proposal. |
Also, p.s. I see all the work and activity closing out the backlog of issues, and I deeply appreciate it. |
After having given this some thought, I'm cautiously optimistic that our relab/gorums plugin could be rewritten to work without running as a plugin, but as a standalone command that could generate our auxiliary code in a separate |
Suppose there was a hypothetical package (let's call it
You could imagine that Would you be able to implement |
I don't think the bullets would be enough for us. We currently use |
What does the protobuf team think of protoc-gen-star? It seems to provide a lot of useful, standardized, functionality for protoc plugins. |
@achew22, the protobuf team operates out of github.com/protocolbuffers. This repository is maintained by a portion of the Go team for the Go implementation of protocol buffers. That said, I'm not an expert on One of the goals for a hypothetical |
The It has been released as part of |
What are the recommendations for protoc plugins that are written in Go, but do not emit golang? Is there a similarly supported package for that? |
You can either use |
There are number of issues filed in this repo that are related to meta-users asking for expanded and more stable support for plugins in
protoc-gen-go
via thegenerator.RegisterPlugin
API.For some background, the
RegisterPlugin
function and API was originally added to support gRPC. Given that was the original intended use-case, it was not well-thought out how it would be used by other projects in the open-source world.The current amount of support for plugins is practically zero. The README states:
Given the number of issues filed related to plugin support, it may be worth considering whether a stable API and documented restrictions should be provided to make plugins better supported.
I don't deny that there are benefits to the ecosystem of plugins that sprouted up. However, they also do carry serious maintenance burdens on the development of
protoc-gen-go
as it is easy forprotoc-gen-go
to make a change that breaks various plugin. For example, if we start generating anUnmarshal
method, plugins that were previously generating that would suddenly break due to a duplicate method.The alternatives to dropping plugin support are:
generator
logic to bolt-on the logic themselves. However, this does make it difficult to compose the functionality of two plugins together..pb.go
file. They take the.pb.go
file as input (and possibly the descriptor) and modify the input source or emit a separate file that exists side-by-side with that file. For example, a number of plugins exists that simply to add new methods could place the new methods in a separate file.The text was updated successfully, but these errors were encountered: