Let's make Twirp and Protobufs easier with Ruby

At Collective Idea, we’re fans of Protocol Buffers. We love Twirp for it’s ease-of-use and simplicity, and have multiple production clients and servers using it.

As Rubyists, we use Twirp-Ruby, and have open-sourced both how we integrate it into our rails apps with our twirp-on-rails gem and how we leverage Twirp in our mobile apps with our twirp-kmm kotlin multiplatform mobile client library. (Editor’s Note: Expect more posts on these… we’ve been lazy.)

We want to make our toolchain even better, but first some background explanation:

Twirp-Ruby is comprised of two distinct parts: 1) A twirp Ruby gem that provides Twirp::Service and Twirp::Client DSLs for runtime use and 2) a plugin to the protoc protobuf compiler, protoc-gen-twirp_ruby written in Go, that generates services and clients from .proto files.

The protoc plugin is mostly fine. It works, but has some issues and can be a headache for folks in the Ruby ecosystem not used to working with Go.

So, we started asking ourselves… what if?

What if we made the code generator more accessible to Rubyists? What if installing the protoc plugin was as simple as installing a gem? What if we could rapidly iterate on it to address community needs, fix longstanding bugs, and add quality-of-life improvements?

We scratched that itch and explored the possibilities. Today we’re happy to announce the result of this effort, the protoc-gen-twirp_ruby gem: a protoc plugin, written in Ruby, for generating Twirp-Ruby clients and/or services.

Our gem is a drop-in replacement for the Go module. It generates similar code, but fixes some things and adds helpful new features along the way. The gem is covered with a comprehensive test suite, allowing us to iterate quickly without worrying about breakage.

We’ve switched our projects over to it. Integration is simple: Addgem install protoc-gen-twirp_ruby or add it to your Gemfile:

gem "protoc-gen-twirp_ruby"

If you previously installed the Go extension from Twirp-Ruby, you have to run one command:

rm `go env GOPATH`/bin/protoc-gen-twirp_ruby

Now when you run protoc, it will use the Ruby version.

We hope you find it as useful as we have!

Photo of Darron Schall

Darron got his internet start on crayola.com building both the website (SQL Server, ColdFusion), and Flash games (starting with Flash 4, then Flash 5 when ActionScript was first introduced). He’s been a lead software engineer, CTO, startup founder, and many roles in between.

Comments