SEANK.H.LIAO

offline buf generate

why does codegen need internet...

buf generate offline

Recently I was on a plane, and decided to do a bit of refactoring, moving some of my protobuf definitions around. Naturally, I wanted to regenerate the code, to make sure everything still worked.

I use buf, so I ran buf generate. I was quite disappointed to receive the message:

1$ buf generate
2Failure: the server hosted at that remote is unavailable.

Why? Looking at my bug.gen.yaml file, it had:

1version: v2
2plugins:
3  - remote: buf.build/protocolbuffers/go
4    out: .
5    opt:
6      - paths=source_relative

At first I thought it was just because I was following buf's examples and recommendations to not pin versions or revisions. However, with a little more experimenting, I realized that buf generate with remote plugins just won't work offline, apparently with no plans to make it work either...

So, what's the right way? I think it's to use a local plugin, specifically using the same version of protoc-gen-go as your code, running it via go:

1version: v2
2plugins:
3  - local: ["go", "run", "google.golang.org/protobuf/cmd/protoc-gen-go"]
4    out: .
5    opt:
6      - paths=source_relative