Feedback on the best way to invoke nanopb generator

471 views
Skip to first unread message

Petteri Aimonen

unread,
Sep 12, 2013, 7:49:06 AM9/12/13
to nan...@googlegroups.com
Hi,

So far, the standard way to use nanopb generator has been to first compile the .proto to .pb using Google's protoc, and then use nanopb_generator.py to convert that into .pb.c and .pb.h files. This works, and will remain supported for the foreseeable future, but it unnecessarily complicated.

Instead, it would be more reasonable to do the generation in one step. Either:

1) Make protoc use nanopb_generator.py as a plugin. This would be invoked as:
protoc --nanopb_out=. myproto.proto

2) Make nanopb_generator.py call protoc automatically when file name ends in .proto:
python nanopb_generator.py myproto.proto

I'm having difficulties deciding between these two options, and would appreciate any feedback from nanopb users.

The 1) way is already implemented in git master, but you have to rename nanopb_generator.py to protoc-gen-nanopb and put it in your path first.

--
Petteri

Michael Haberler

unread,
Sep 12, 2013, 8:20:29 AM9/12/13
to nan...@googlegroups.com
Hi Petteri,
I dont have a founded opinion on what is better, however what I've done is create a Python plugin to generate build dependencies from proto files for my project (which builds C,C++,Python and nanopb C bindings), as I couldnt find a more elegant tool except some homegrown shell script; not sure if you want to add something along these lines but for a larger project correct deps are key:

http://git.mah.priv.at/gitweb?p=emc2-dev.git;a=commit;h=a24b493a207b7a9abd73547cba26619bbe55e634

I found the way of passing options to a Python plugin less than elegant; but that's just one-time suffering

not sure how you'd do this with 2)

- Michael


>
> --
> Petteri
>
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Petteri Aimonen

unread,
Sep 12, 2013, 8:43:14 AM9/12/13
to nan...@googlegroups.com
Hi,

Yeah, there are nice things that can be done using protoc plugins. However, I guess there are too many different build systems to include such a depends functionality in nanopb.

The passing of options through protoc is indeed a bit cumbersome. I have thought something like:
protoc --nanopb_out=.:"--library-include-format='#include ...'" foobar.proto

Though fortunately the need to pass parameters to nanopb_generator.py is very rare.

Another slight problem is using the plugin approach on Windows, but perhaps some .bat wrapper or making an exe with bbfreeze would work.

--
Petteri
Reply all
Reply to author
Forward
0 new messages