-
Notifications
You must be signed in to change notification settings - Fork 143
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
mix protobuf.generate
#316
Comments
TL;DRHow about this shell script? Put it in the PATH as #!/bin/sh -e
(
mix deps.compile
) 1>&2 </dev/null
exec mix eval --no-compile 'Application.ensure_all_started(:protobuf) ; Protobuf.Protoc.CLI.main(System.argv())' "$@" All you need for this to work is to have done For your specific use-case, you might need to throw in a transformer module. If you bundle that in The Long VersionApologies if this comes across as kind of severe, but... it really goes against the grain of the Consider the examples for all of the supported languages. None of them have any preprocessing or wrapping like this to provide extensions to code generation so far as I can tell. The process is pretty much identical everywhere: About the only thing different between any of them is the output location. In those cases it's just to conform to the strict directory structure requirements the languages have. And in every case, consuming options for the custom extension is similarly consistent. Everyone who has already used protocol buffers in other languages is just going to wonder why Elixir is making things weird. And some kind of arbitrary rule for abstract gain, there are very real benefits to doing it that way. Check out the Buf project. Note their plugins It seems the core problem here is distributing it as an Given the assumption that you'll be running There's a bit of a chicken-and-egg thing if you need something from your app itself (like, say, a transformer module). For the people that really want that, I chose above to at least compile dependencies. That way you can, in a pinch, you can put your module in a dependency package and call it a day. |
mix protobuf.generate
For context: elixir-grpc/grpc#274
I'm working on http/json transcoding for grpc and basically want to populate
MethodDescriptors
options with an extension during compilation.The recommended approach is to install the escript globaly and use the executable from
protoc
it's hard to see a way to provide extensions that needs to be loaded during compilation in order to to populate__pb_extensions__
correctly without creating a newprotoc
plugin.Having a complementary
mix task
that callsprotoc
usingdescriptor_set_out
would allow compilation to be executed in the context the local project instead of through a global executable. This is the approach taken in protox.I would think that most projects already contains some script which calls
protoc
to compile their.proto
files. This would remove this indirection and at the same time enable:Extensions in the current project would be picked up automatically by
Protobuf.load_extensions()
(or could be provided as an argument toprotobuf.generate
).No potential version difference between
protobuf
installed in the project and the escript installed globally.Allow easier integration into the codgen. Generators could be modules provided to
protobuf
instead of require that they are defined inprotobuf
.Proposal
Which generate a
protoc
call like:This would output a
FileDescriptorSet
into a temporary file.Combined with the parameters provided through
protobuf.generate
it's enough to create aCodeGeneratorRequest
and perform the same logic as is done inProtobuf.Protoc.CLI
. The resultingCodeGeneratorResponse
is used to write files to disk.What do you think? I you think it sounds reasonable I can send a PR :).
The text was updated successfully, but these errors were encountered: