/go-protoc-gen-builtins

Code generator plugins for built-in protoc languages buildable with Go

Primary LanguageGoMIT LicenseMIT

go-protoc-gen-builtins

go-protoc-gen-builtins is a distribution of the code generator plugins from protoc, the protocol buffers compiler, that can be built with Go. It does not actually reimplement any functionality of protoc in Go, instead compiling the original source code to WebAssembly, and executing with the pure Go Wasm runtime wazero. This means that go install or go run can be used to execute it, with no need to rely on external package managers such as Homebrew, on any platform that Go supports.

This project is primarily targeted at Buf users, or users of other alternative protocol buffer compilers. protoc users should have no need for the plugins in this repository because they are already built-in to protoc.

Installation

Precompiled binaries are available in the releases. Alternatively, install the plugin you want using go install.

$ go install github.com/wasilibs/go-protoc-gen-builtins/cmd/protoc-gen-python@latest

As long as $GOPATH/bin, e.g. ~/go/bin is on the PATH, buf should find it automatically.

version: v2
plugins:
  - local: protoc-gen-python
    out: out/python

Note that with v2 format, you must use local and protoc-gen-<plugin>, not protoc_builtin.

To avoid installation entirely, it can be convenient to use go run with path instead.

version: v2
plugins:
  - local:
      - go
      - run
      - github.com/wasilibs/go-protoc-gen-builtins/cmd/protoc-gen-python@latest
    out: out/python

If invoking buf itself with go run, it is possible to have full protobuf generation with no installation of tools, besides Go itself, on any platform that Go supports. The above examples use @latest, but it is recommended to specify a version, in which case all of the developers on your codebase will use the same version of the tool with no special steps.

For gRPC plugins, also see go-protoc-gen-grpc.

A full example is available at example. To generate protos, enter the directory and run go run github.com/bufbuild/buf/cmd/buf@v1.32.0 generate. As long as your machine has Go installed, you will be able to generate protos. The first time using go run for a command, Go automatically builds it making it slower, but subsequent invocations should be quite fast.