xx
.md

protobuf_generator

protobuf_generator combines a protoc plugin name with a dependency that installs or activates its executable. It returns a typed generator accepted by protobuf_generate.

Arguments

ArgumentRequiredDescription
nameYesPlugin suffix used by protoc. "go" selects an executable named protoc-gen-go through --go_out. Must start with an ASCII letter and contain only ASCII letters, digits, hyphens, and underscores. Built-in and reserved protoc output names are rejected.
dependencyYesDependency that makes protoc-gen-<name> available in PATH.

Built-in generator names cannot be wrapped. Pass those names directly to protobuf_generate. Selecting a typed generator activates its dependency automatically.

Prefer language-specific helpers when available. Use this adapter with a generic installer or a custom build task.

Examples

Install a Go plugin manually

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

plugin = go_install(
    package="google.golang.org/protobuf/cmd/protoc-gen-go",
    version="v1.36.6",
)

protobuf_generate(
    sources=["proto/service.proto"],
    generator=protobuf_generator("go", plugin),
    output="generated/go",
    proto_paths=["proto"],
    options=["paths=source_relative"],
)

Generate TypeScript with Protobuf-ES

Pin @bufbuild/protoc-gen-es in the project's package.json and lockfile:

{
  "devDependencies": {
    "@bufbuild/protoc-gen-es": "2.9.0"
  }
}

Install project dependencies, expose npm's local executable directory, and wrap protoc-gen-es as generator es:

load("@[email protected]", "npm_install")
load("@os@1", "env_prepend")
load("@[email protected]", "protobuf_generate", "protobuf_generator")

plugin = protobuf_generator(
    "es",
    npm_install(frozen_lockfile=True) + env_prepend("PATH", "node_modules/.bin"),
)

protobuf_generate(
    sources=["proto/service.proto"],
    generator=plugin,
    output="generated/typescript",
    proto_paths=["proto"],
    options=["target=ts"],
)