Generating Ruby Code From Proto Files
I'll admit that using proto files and gRPC is a new concept to me, so I might be doing something wrong here. But here's what I've been able to do...
protoc --proto_path=atc --ruby_out=lib atc/v1/atc.proto outputs an lib/v1/atc_pb.rb file successfully.
However, when I run
protoc --proto_path=atc --ruby_out=lib atc/v1/atc.proto atc/v1/airplane.proto I get...
atc/v1/map.proto: File not found.
atc/v1/tag.proto: File not found.
v1/airplane.proto:5:1: Import "atc/v1/map.proto" was not found or had errors.
v1/airplane.proto:6:1: Import "atc/v1/tag.proto" was not found or had errors.
v1/airplane.proto:10:3: "Point" is not defined.
v1/airplane.proto:11:12: "Node" is not defined.
v1/airplane.proto:12:3: "Tag" is not defined.
v1/airplane.proto:25:12: "Node" is not defined.
And I have confirmed that the map.proto and tag.proto file is there. So that file not found error doesn't really make sense. Do you have any idea what might be going on?
I don't. I can look into it, but I wanted to add a client library for Ruby anyways, there was just no need for it yet. Let me try creating a gem for you tomorrow that you can just add as a dependency to your project.
It looks like this stems from running protoc alongside the outer package folder. I resolved this by moving one folder up and using protoc-3.11.3-windows-x86_64.exe --proto_path=proto --ruby_out=lib proto\atc\v1\*.
Presumably, this is why the original 'working' step results in lib/v1/atc_pb.rb and not lib/atc/v1/atc_pb.rb
Thanks!
From the project root, this works protoc --proto_path=api --ruby_out=lib api/atc/v1/* You'll need to create the lib directory first of course.
Thanks for the help, @Nzen!
I started working on the gem, but didn't have the time to finish it yet. Will get back to it early next week.
@jdno Thanks for the effort! I messed around with the generated files last night, but didn't make much progress. I assume once I have access to the gem it will be much easier because the actual gRPC calls and connection will be abstracted away.
For the record, I used the following command to generate Go bindings (run from api/ directory):
protoc \
--proto_path=. \
--go_out=proto \
--go-grpc_out=proto \
--go_opt=Matc/v1/airplane.proto=proto/ --go-grpc_opt=Matc/v1/airplane.proto=proto/ \
--go_opt=Matc/v1/atc.proto=proto/ --go-grpc_opt=Matc/v1/atc.proto=proto/ \
--go_opt=Matc/v1/event.proto=proto/ --go-grpc_opt=Matc/v1/event.proto=proto/ \
--go_opt=Matc/v1/game.proto=proto/ --go-grpc_opt=Matc/v1/game.proto=proto/ \
--go_opt=Matc/v1/map.proto=proto/ --go-grpc_opt=Matc/v1/map.proto=proto/ \
--go_opt=Matc/v1/tag.proto=proto/ --go-grpc_opt=Matc/v1/tag.proto=proto/ \
v1/airplane.proto atc/v1/atc.proto atc/v1/event.proto atc/v1/game.proto atc/v1/map.proto atc/v1/tag.proto
--go_opt=M{file}={package} options are required as the package names for go are not specified. --go-grpc_out is for gRPC bindings generation.
This required the following two commands installed:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@jdno if you post what you have for a ruby gem, I can take a look at finishing it if you want to take a look at some of the other feature requests that have come in.
I finally had the time to finish the gem. It's README should provide a good starting point, but feel free to extend it with any information you are missing. There is also an example.
I've pushed the gem to rubygems.org under the name atc, which matches the namespace of the Protocol Buffers. I kinda regret this, though, since it's not consistent with the other packages. Should've just renamed the namespace...
Please let me know if you run into any issues. If you find anything that can be improve in the gem or example, feel free to open a pull request. It's been a few years since I used Ruby in production. 😅