protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

allow to pass file level options as parameters to protoc

Open Hendrik-H opened this issue 4 years ago • 1 comments

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.

Hendrik-H avatar Jan 22 '21 15:01 Hendrik-H

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.

lipnitsk avatar Mar 24 '21 01:03 lipnitsk

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.

fowles avatar Sep 01 '22 18:09 fowles

Hi @fowles , what's the feature you were referring to in your last statement? Was that released by now?

Hendrik-H avatar Feb 26 '24 11:02 Hendrik-H

https://protobuf.dev/editions/overview/ and 26.0 should contain this in the next month or so!

fowles avatar Feb 26 '24 13:02 fowles

@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?

Hendrik-H avatar Mar 18 '24 11:03 Hendrik-H

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.

fowles avatar Mar 18 '24 15:03 fowles