The BSR facilitates both local and remote code generation, simplifying how module consumers get access to generated code.

Hosting modules on the BSR allows anyone with proper access to consume those modules. This eliminates the need to coordinate and sync Protobuf files manually amongst multiple consumers, which is error-prone and leads to drift.

Instead, users generate code from a single source of truth: a hosted module on the BSR.

In your buf.gen.yaml, define plugins and their respective options, and then generate your code with the buf CLI by referencing a BSR module:

$ buf generate buf.build/acme/weather

Local code generation

The buf generate command enables you to run local plugins to generate code from remote modules hosted on the BSR. If you already have a workflow that invokes plugins with protoc, then adopting buf generate should be straightforward.

Add a buf.gen.yaml file, and list all the plugins as well as their options. Here is a quick example that generates C++ and Java code.

buf.gen.yaml
version: v1
plugins:
  - plugin: cpp
    out: gen/proto/cpp
  - plugin: java
    out: gen/proto/java

The buf CLI infers the protoc-gen-{name} prefix for each plugin specified by the name key, similar to protoc behaviour.

Once you set up a buf.gen.yaml file, run this command and specify a module hosted on the BSR. That's right, you can reference a hosted BSR module without having the Protobuf files locally!

$ buf generate <MODULE_NAME>

This generates C++ and Java code in the local /gen/proto/{cpp,java} directories.

For a more advanced example, check out the Tour - Generate Go Code

Remote Plugins

The Buf team packages and distributes plugins to the BSR, browsable at: buf.build/plugins

If you're interested in how these plugins are packaged see the bufbuild/plugins repository for more details.

To learn more about how remote plugins can be used in code generation workflows, check out the remote plugins' documentation.

Remote Packages

By combining a BSR module and a plugin, you can fetch generated SDKs with your language's package manager:

Go Module Proxy

$ go get buf.build/gen/go/bufbuild/eliza/bufbuild/connect-go

NPM Registry

$ npm install @buf/bufbuild_eliza.bufbuild_connect-es@latest

For more information about available packages, see the Remote Packages documentation.