Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating for other languages #25

Open
divoxx opened this issue Mar 29, 2019 · 5 comments
Open

Generating for other languages #25

divoxx opened this issue Mar 29, 2019 · 5 comments

Comments

@divoxx
Copy link

divoxx commented Mar 29, 2019

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?

@stevvooe
Copy link
Member

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.

@divoxx
Copy link
Author

divoxx commented Apr 15, 2019

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.

@stevvooe
Copy link
Member

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.

@divoxx
Copy link
Author

divoxx commented Feb 6, 2020

@stevvooe that would be good enough and would solve the problem.

@marcelbuesing
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants