Skip to content
Latchkey

protoc Command: Compile Protobuf in CI

protoc compiles .proto files into language-specific code via code-gen plugins.

protoc is the Protocol Buffers compiler that generates client/server stubs in CI codegen steps. It parses .proto schemas and invokes per-language plugins (Go, Java, Python, gRPC) to emit source that the rest of the build consumes.

Common flags

  • --proto_path=DIR / -I DIR - root directory for resolving imports
  • --go_out=DIR / --java_out=DIR / --python_out=DIR - language output dirs
  • --go-grpc_out=DIR - emit gRPC service stubs (Go example)
  • --plugin=protoc-gen-NAME=PATH - register a custom codegen plugin
  • --descriptor_set_out=FILE - emit a compiled FileDescriptorSet
  • --experimental_allow_proto3_optional - allow proto3 optional fields

Example in CI

Generate Go message and gRPC code from a proto tree in a CI codegen job:

shell
protoc -I proto \
  --go_out=gen --go_opt=paths=source_relative \
  --go-grpc_out=gen --go-grpc_opt=paths=source_relative \
  proto/api/v1/service.proto

Common errors in CI

  • File not found / Import "x.proto" was not found - add the dir with --proto_path
  • protoc-gen-go: program not found or is not executable - plugin not on PATH
  • Explicit "optional" labels are disallowed in the Proto3 syntax
  • --go_out: protoc-gen-go: plugins are not supported; use protoc-gen-go-grpc

Key takeaways

  • --proto_path controls import resolution; set it to your proto root.
  • Each language needs its own _out flag and a plugin on PATH.
  • "program not found" means the protoc-gen-* plugin is not installed/on PATH.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →