fix: make GRPC.Stub generation opt-out for server-only protoc runs#553
Conversation
|
I will take a look but how this is compatible with protobuf_generate hex package? We support both |
|
Good question. The change is entirely inside GRPC.Protoc.CLI (the protoc-gen-elixir plugin), and it's fully backward compatible: gen_stubs defaults to true, so the .Stub module is only omitted when someone explicitly passes gen_stubs=false. Nothing changes for existing users of either path. gen_stubs is a standard protoc plugin parameter, so it flows through anywhere protoc-gen-elixir is invoked with plugin params - direct protoc, Buf, etc. For protobuf_generate specifically: it depends on whether protobuf_generate forwards arbitrary plugin options through to the elixir plugin. I wasn't able to confirm its opt-forwarding from the docs - if it doesn't pass extra plugin params today, then gen_stubs=false wouldn't be reachable via protobuf_generate until that's added, but the default (stubs generated) is unaffected either way. You know that package better than I do - if you can point me at how it forwards plugin opts, I'm happy to add a protobuf_generate example/integration test so both paths are covered. |
|
Okay, I believe it will work; we just need to test it. In any case, it doesn't seem like an obstacle to us moving forward. |
|
Appreciate the merge, @sleipnir - server-only proto builds can opt out of stub generation now. |
Thank you for your contribution. |
Summary
protoc-gen-elixir(the gRPC generator) now supports opting out ofGRPC.Stubclient generation for server-only runs. A newgen_stubs=falseoption skips emitting the client stub module while still generating the service module, so projects that only implement servers no longer carry unused client stubs.Why this matters
Issue #549 asks for a way to generate server code without the client
Stub. Today the generator always emits both the service behaviour and aGRPC.Stubclient module; a server-only project ends up with a client stub it never uses, which is dead surface area and can clash with a separately generated or hand-written client. There was no switch to turn it off.This adds a
gen_stubsplugin option, defaulting totrueso existing behavior is unchanged. Passing--elixir_out=gen_stubs=false:...(parsed inGrpc.Protoc.CLI) threads the flag into the service generator, and theservice.ex.eextemplate conditionally omits the stub module. Default output is byte-identical to before.Testing
mix test test/grpc/protoc/generator/service_test.exs— 4 tests pass, covering default generation (stub present) andgen_stubs: false(stub omitted, service retained).mix format --check-formattedclean on the changed source files.Fixes #549