protobuild
protobuild copied to clipboard
Generating for other languages
I understand that this tool has a focus on Go applications but in general, a GRPC or protobuf definition is shared by other languages in order to generate the client code necessary to talk to those services.
Is there any guide or recommendation on how to do that? Currently protoc throws errors such as (Example taken from containerd):
gogoproto/gogo.proto: File not found.
github.com/containerd/containerd/protobuf/plugin/fieldpath.proto: File not found.
api/events/container.proto: Import "gogoproto/gogo.proto" was not found or had errors.
api/events/container.proto: Import "github.com/containerd/containerd/protobuf/plugin/fieldpath.proto" was not found or had errors
Is there any simple/recommended way to make those imports resolve when generating for other languages? Or any way to tell protobuild to run protoc
with a specific plugin, i.e. --rust_out
or --ruby_out
, etc?
Protobuild is really only for managing protobuf generation in Go environment. Much of the configuration is around resolving includes (-I
argument on protoc
) out of GOPATH.
For another language, you'd have to build a tool that would be focused on that. For example, a javascript version might look at using node_modules to resolve the files.
You can craft the includes manually, which might be enough for your approach. For example, the error on github.com/containerd/containerd/protobuf/plugin/fieldpath.proto
just means you need the containerd source checked out on your local filesystem that is resolved relative to the include path.
Now, it would be cool to have Protobuild support other languages, but I am not sure I have the bandwidth or expertise to support. However, I can help you to get them compiling in another language.
Let me know how you'd like to proceed.
Thanks for the answer.
That makes sense and I don't think Protobuild needs to know how to build for other languages but it would be nice if it could help the user somehow. Protobuf/grpc is widely used for systems where you have multiple languages/stack involved, so it's not a rare occurrence.
In this case, I was trying to build containard proto definitions in Rust, so that I could call the GRPC API using Rust. Technically, all I needed was for Protobuild to output the import paths that it was generating so that I could plug that into my protoc command.
For example, I was able to build successfully with the following snippet, which required a lot of digging to figure out how Protobuild works internally:
protoc \
-I=$GOPATH/src/github.com/containerd/containerd \
-I=$GOPATH/src/github.com/gogo/protobuf/ \
-I=$GOPATH/src/github.com/googleapis/googleapis \
-I=$GOPATH/src \
# additional options of target language and grpc plugin
If Protobuild could simply output those parameters, or allow the user to specify additional parameters when invoking protoc, then it would make things a lot easier.
Sorry for the late response here.
What if we added the ability to dump the import paths?
$ protobuild imports
$GOPATH/src/github.com/containerd/containerd
$GOPATH/src/github.com/gogo/protobuf/
$GOPATH/src/github.com/googleapis/googleapis
$GOPATH/src
Let me think about this a bit. This might be useful for debugging environment issues, as well.
@stevvooe that would be good enough and would solve the problem.
@divoxx did you manage to solve this? I also just tried to create bindings for containerd using tonic. Found this in a python repo: https://github.com/siemens/pycontainerd/blob/master/script/genpb2.sh But still wasn't able to make it work.