<!doctype html><metacharset=utf-8><metaname=viewportcontent="width=device-width,initial-scale=1"><linkrel=stylesheethref=https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown-dark.css><style>.markdown-body{box-sizing:border-box;min-width:200px;max-width:980px;margin:0auto;padding:45px}@media(max-width:767px){.markdown-body{padding:15px}}</style><bodyclass=markdown-body><ahref=index>Index</a><h1><aid=user-content-migrate-to-buf-from-prototoolclass=anchoraria-hidden=truehref=#migrate-to-buf-from-prototool><spanaria-hidden=trueclass="octicon octicon-link"></span></a>Migrate to <code>buf</code> from <code>prototool</code></h1><p>Why? Because <code>prototool</code> is outdated, and can not run on M1 mac.<p>We need 3 files:<ul><li><code>build.go</code>: need to install protoc-gen-* binaries with pin version in <code>go.mod</code><li><code>buf.yaml</code><li><code>buf.gen.yaml</code></ul><p>FYI, the libs version I use:<ul><li><ahref=https://github.com/golang/protobuf/releases/tag/v1.5.2>golang/protobuf v1.5.2</a><li><ahref=https://github.com/grpc-ecosystem/grpc-gateway/releases/tag/v1.16.0>grpc-ecosystem/grpc-gateway v1.16.0</a><li><ahref=github.com/envoyproxy/protoc-gen-validate>envoyproxy/protoc-gen-validate</a><li><ahref=github.com/kei2100/protoc-gen-marshal-zap>kei2100/protoc-gen-marshal-zap</a></ul><p><code>build.go</code>:<divclass="highlight highlight-source-go"><pre><spanclass=pl-c>//go:build tools</span>
buf generate</pre></div><p>Run <code>make gen</code> to have fun of course.<h2><aid=user-content-faqclass=anchoraria-hidden=truehref=#faq><spanaria-hidden=trueclass="octicon octicon-link"></span></a>FAQ</h2><p>Remember <code>grpc-ecosystem/grpc-gateway</code>, <code>envoyproxy/protoc-gen-validate</code>, <code>kei2100/protoc-gen-marshal-zap</code> is optional, so feel free to delete if you don't use theme.<p>If use <code>vendor</code>:<ul><li>Replace <code>buf generate</code> with <code>buf generate --exclude-path vendor</code>.<li>Replace <code>buf format -w</code> with <code>buf format -w --exclude-path vendor</code>.</ul><p>If you use grpc-gateway:<ul><li>Replace <code>import "third_party/googleapis/google/api/annotations.proto";</code> with <code>import "google/api/annotations.proto";</code><li>Delete <code>security_definitions</code>, <code>security</code>, in <code>option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger)</code>.</ul><p>The last step is delete <code>prototool.yaml</code>.<p>If you are not migrate but start from scratch:<ul><li>Add <code>buf lint</code> to make sure your proto is good.<li>Add <code>buf breaking --against "https://your-grpc-repo-goes-here.git"</code> to make sure each time you update proto, you don't break backward compatibility.</ul><h2><aid=user-content-thanksclass=anchoraria-hidden=truehref=#thanks><spanaria-hidden=trueclass="octicon octicon-link"></span></a>Thanks</h2><ul><li><ahref=https://github.com/uber/prototool>uber/prototool</a><li><ahref=https://github.com/bufbuild/buf>bufbuild/buf</a></ul><ahref=mailto:hauvipapro+posts@gmail.com>Feel free to ask me via email</a>