Chapter 11: Setting Up the Toolchain

What You Need

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