protobuf
protobuf copied to clipboard
allow to pass file level options as parameters to protoc
What language does this apply to? If it's a proto syntax change, is it for proto2 or proto3? If it's about generated code change, what programming language? all languages
Describe the problem you are trying to solve.
In a proto file I can specify file level options like java_package
, go_package
or optimize_for
. These are all options that are about the code generation but not about the actual data that is being generate later on. When a project publishes an API as a proto file they currently have to make implementation choices for multiple languages, included those that have nothing to do with the project that published the proto file. This breaks the separation of concern and can cause problems for the user of an API if the producer is not adding the settings for the clients language. The other other option is to make a copy of the proto file and add the options in there, which also doesn't feel right.
Describe the solution you'd like I would like to be able to pass in file level options and have those override the option in case it was also set in the proto file.
Describe alternatives you've considered See above, basically make a copy of the proto file and add the options that I need in my private copy.
I think protoc should allow for defining options at all levels in separate files, not just the file-level options. See https://jpa.kapsi.fi/nanopb/docs/reference.html#defining-the-options-in-a-.options-file for a variety of ways it can be done for a custom plugin. I think this feature is beneficial upstream so all languages and plugins can utilize it.
We have some high level efforts that will enable features like this, but not quite this. We don't intend to add this feature as asked for, but hopefully we will release something next year that alleviates much of this.
Hi @fowles , what's the feature you were referring to in your last statement? Was that released by now?
https://protobuf.dev/editions/overview/ and 26.0 should contain this in the next month or so!
@fowles I can't find anything in 26.0 or in the editions docu that shows how I can now override the java_package
when using protoc. did I overlook something?
Sorry, I think I misread the initial bug. I was focused on defining things at all levels, not on the "external file" part of things. Prototiller will eventually provide an answer there, but it is slow going.