Distribute as librairie/package

64 views
Skip to first unread message

Louis Letourneau

unread,
May 27, 2022, 12:39:32 PM5/27/22
to Protocol Buffers
I can't seem to wrap my head around a way to distribute protobuf generated code.
I have 2 projects, A and B
B imports project As proto definition

A and B have python and C++ generated code.
For python it seems to all work well (had issues with protoc not generating the righ import package path, but I seem to have solved this)

In C++ it get's complicated

Say I build a .so from project A and I bundle the header with the librairy (protobuf 3.17 was used).

If The person working on B had a different version of protobuf installed, he can't use the header or he'll get the 'error: #error This file was generated by an older version of protoc which is' message

So for C++ I can't bundle a library with headers, I need to share the proto and let the users generate the code in their own build system... This seems wrong.

In the same line of thought, should the _pb2.py be disitributed or should the client installing the lib locally generate (say have instructions in setup.py) the code

Thanks

Deanna Garcia

unread,
Aug 1, 2022, 2:12:14 PM8/1/22
to Protocol Buffers
In general we recommend that you distribute the .proto file itself and not the generated code. As you pointed out, distributing generated code doesn't allow any user to use a different runtime. The wire format is always compatible so it doesn't matter that you are using a different version of protobuf than your users. This also lets them use your proto in any language, giving them more flexibility. 

Louis Letourneau

unread,
Aug 1, 2022, 3:31:51 PM8/1/22
to Deanna Garcia, Protocol Buffers
This is what I ended up doing in the end.
Thanks
> --
> You received this message because you are subscribed to a topic in the Google Groups "Protocol Buffers" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/protobuf/ib5YQH-MXF4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to protobuf+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/9c6a68f0-be63-457f-ac3b-402f87076771n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages