xx
.md

protobuf_generate

protobuf_generate runs one built-in protoc generator with a managed compiler. It registers generation as a root task and returns its dependency.

Arguments

ArgumentRequiredDescription
sourcesYesNon-empty list of project-relative .proto files.
generatorYesBuilt-in generator name or a generator returned by protobuf_generator or a language package helper.
outputYesProject-relative output directory.
proto_pathsNoNon-empty list of project-relative import roots. Defaults to ["."].
optionsNoGenerator option strings, each passed through the matching --<generator>_opt flag. Defaults to [].
depsNoDependencies activated before generation, in list order. Defaults to [].

The selected compiler is implicit; do not add protoc to deps. xx appends the managed package's bundled include directory after proto_paths, so imports such as google/protobuf/timestamp.proto resolve without extra configuration. Source files, import roots, and outputs must remain inside the project after symlinks are resolved. Missing output directories are created. Output trees cannot contain symbolic links or overlap another active output.

String generators are limited to cpp, csharp, java, js, kotlin, objc, php, pyi, python, rbs, ruby, and rust. These built-ins vary by Protobuf version. For example, js exists only in older releases, while newer generators require newer releases. Unsupported generator/version combinations fail in protoc.

Plugin dependencies must be wrapped in a typed generator. Selecting one activates its installation dependency automatically before protoc; do not also add it to deps. Prefer language-specific helpers such as go_protobuf. protobuf_generate contains no language-specific installation behavior.

Example

load("@[email protected]", "protobuf_generate")

protobuf_generate(
    sources=["proto/example/v1/service.proto"],
    generator="python",
    output="generated/python",
    proto_paths=["proto"],
)

Go plugin example

load("@[email protected]", "go_protobuf")
load("@[email protected]", "protobuf_generate")

protobuf_generate(
    sources=["proto/example/v1/service.proto"],
    generator=go_protobuf("1.36.6"),
    output="generated/go",
    proto_paths=["proto"],
    options=["paths=source_relative"],
)