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.protoCommon 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_pathcontrols import resolution; set it to your proto root.- Each language needs its own
_outflag and a plugin on PATH. - "program not found" means the protoc-gen-* plugin is not installed/on PATH.
Related guides
go build Command: Compile Go in CIgo build compiles Go packages. Reference for -o, -ldflags, -tags, -race, GOOS/GOARCH cross-compilation, and t…
bazel Command: Build Monorepos in CIbazel is a hermetic, cached build system. Reference for build, test, //..., --config, --remote_cache, --keep_…
cmake Command: Configure C++ Builds in CIcmake configures and builds C/C++ projects. Reference for -S, -B, -G, -D, --build, --target, --preset, and th…