protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Is there a list of all the `--go_opt` and `--go-grpc_opt` options

Open Clement-Jean opened this issue 3 years ago • 5 comments

i'm working on a tool which provide shell suggestion for protoc and I would like to know if there is a list of all the options for the two flags.

I've use module in the past, such as:

protoc -I. --go_out=. --grpc_out=. --go_opt=module=...  --go-grpc_opt=module=... *.proto

And I cannot seem to find where these options are defined and handled. Could you please guide me ?

Clement-Jean avatar Apr 06 '22 00:04 Clement-Jean

2 years and no answer. Excellent 😂

geekysaurabh001 avatar May 06 '24 09:05 geekysaurabh001

I forgot to follow up but I found the list of default options for --go_opt. It can be found in the here (the New function in protobuf-go/compiler/protogen/protogen.go).

Here is the list:

  • module or M followed by the go module path.
  • paths that can take "import" or "source_relative" as value.
  • annotate_code that can take true or false as value.

As for --go-grpc_opt I'm not sure yet but I'll try to keep this issue updated.

Clement-Jean avatar May 06 '24 12:05 Clement-Jean

https://protobuf.dev/reference/go/go-generated/#invocation documents Go code generator flags.

(I don't think the annotate_code option is documented, but it's also incredibly specialized and you almost certainly don't care about it unless you're trying to write an LSP implementation for protobufs or something.)

The gRPC generator should accept the same flags, in addition to any gRPC-specific ones. I'm not sure where the gRPC generator documentation is.

neild avatar May 06 '24 16:05 neild

Is annotate_code emitting SourceCodeInfo or something like this? I'm actually working on some libraries that are meant to build an LSP, so I'm still interested 😊

Clement-Jean avatar May 06 '24 19:05 Clement-Jean

annotate_code emits a .meta file alongside each .pb.go containing a GeneratedCodeInfo. (See descriptor.proto for the definition.) Where SourceCodeInfo is created by protoc and describes the relationship between a .proto source file and the descriptors in it, GeneratedCodeInfo describes the relationship between the generated code and the .proto source.

neild avatar May 06 '24 20:05 neild