Chapter 11: Setting Up the Toolchain
What You Need
- protoc — Protocol Buffer compiler (converts .proto → code)
- Language plugin — generates gRPC service stubs (e.g., grpc_cpp_plugin)
- gRPC library — runtime library for your language
Installation (Ubuntu/Linux)
# Install protoc (Protocol Buffer compiler)
$ apt install -y protobuf-compiler
$ protoc --version # libprotoc 3.x+
# C++: install gRPC and plugin
$ apt install -y libgrpc++-dev grpc-proto protobuf-compiler-grpc
$ which grpc_cpp_plugin # /usr/bin/grpc_cpp_plugin
# Go: install plugins
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Python: install grpcio-tools (includes protoc)
$ pip install grpcio grpcio-tools
Buf: The Modern Alternative
# Buf replaces raw protoc with a better developer experience
$ curl -sSL https://buf.build/install | sh
$ buf --version
# buf.yaml — project config
version: v1
name: buf.build/mycompany/myservice
breaking:
use: [FILE]
lint:
use: [DEFAULT]
# buf.gen.yaml — code generation config
version: v1
plugins:
- plugin: cpp
out: gen/cpp
- plugin: grpc-cpp
out: gen/cpp
# Generate code
$ buf generate
Project Structure
my-grpc-project/
├── proto/
│ └── myservice/
│ └── v1/
│ ├── service.proto
│ └── messages.proto
├── gen/ ← generated code (gitignored)
│ ├── cpp/
│ ├── go/
│ └── python/
├── server/ ← server implementation
├── client/ ← client implementation
├── buf.yaml
├── buf.gen.yaml
└── CMakeLists.txt (or go.mod, requirements.txt)
Key Takeaways
- protoc + language plugin = code generation pipeline
- Buf is the modern replacement (linting, breaking change detection, simpler config)
- Keep .proto files in a proto/ directory, generated code in gen/ (gitignored)
- Generated code is NOT checked in — regenerate from .proto as part of build