Better plugin support for cmake builds

149 views
Skip to first unread message

Li He

unread,
Feb 24, 2023, 1:25:43 PM2/24/23
to Protocol Buffers
Hi protobuf community members,

I had an idea about some improvements for the protobuf cmake file. It was discussed over a recent merge request. I agree with Brad King's comment about moving this to the upstream code base but before I send it out, just want to get a sense whether I am on the right track. Right now, the function generate_protobuf is intended to be used like this:

protobuf_generate(
  OUT_VAR helloworld_proto
  PROTOS helloworld.proto
  LANGUAGE cpp
)
protobuf_generate(
  OUT_VAR helloworld_grpc
  PROTOS helloworld.proto
  LANGUAGE grpc
  PLUGIN "protoc-gen-grpc=${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
)

It seems for each grpc proto file, we will need two calls, so I want to make it also support

protobuf_generate(
  OUT_VAR helloworld_proto
  PLUGIN_OUT_VAR helloworld_gprc
  PROTOS helloworld.proto
  LANGUAGE cpp
  PLUGIN "protoc-gen-grpc=${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  GENERATE_EXTENSIONS .pb.h .pb.cc .grpc.pb.h .grpc.pb.cc
)

Let me know if this would be a good change to make and I am happy to send out a pull request.

Adam Cozzette

unread,
Mar 2, 2023, 2:30:47 PM3/2/23
to Li He, Protocol Buffers
Thanks for the suggestion and sorry for taking so long to reply. It's an interesting idea but I guess I'm skeptical of whether it's worth the effort to avoid an extra protoc invocation, since in my experience protoc invocations are not usually the bottleneck in build performance. I would also be nervous about adding a special case for gRPC, since that is just one of many plugins that one might want to use.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/9d44ccc8-3dd4-42bb-b5bd-f71217c7ba57n%40googlegroups.com.

Li He

unread,
Mar 2, 2023, 7:12:07 PM3/2/23
to Adam Cozzette, Protocol Buffers
Well, it's very simple to add to the existing implementation and is not limited to grpc (which I am just using as an example). According to 


We just need to extract the plugin name from PLUGIN using regex and try to append something for the plugin output if the LANGUAGE value isn't the plugin name.

--
Best regards,

HE, Li

Reply all
Reply to author
Forward
0 new messages