Publishing a Buf check plugin to the BSR
Publishing a plugin to the BSR allows you to share it with other developers. To publish a plugin, it must be compiled as a WASM binary.
The process varies depending on the language you're using — in this example, we'll use the rpc-suffix plugin built in Go from the quickstart.
Compiling the plugin
To compile your plugin to Wasm, you need to target the WebAssembly System Interface (WASI) syscall API. WASI provides a standard interface for Wasm modules to interact with the host system. The supported version is WASI 0.1.
For Go plugins, you can compile your plugin by setting the GOOS and GOARCH environment variables to wasip1 and wasm, respectively. This tells the Go compiler to target the WASI syscall API and compile the code to Wasm. For example, this command compiles the rpc-suffix plugin outputting a rpc-suffix.wasm file:
GOOS=wasip1 GOARCH=wasm go build -o rpc-suffix.wasm ./cmd/rpc-suffixThe output of this command is a Wasm binary file named rpc-suffix.wasm. The .wasm suffix is an important convention, as it tells the Buf CLI the plugin type. If the plugin doesn't have the .wasm suffix, the Buf CLI interprets it as a native plugin.
Pushing a plugin
To push a plugin to the BSR, you use the buf plugin push command. We'll use the rpc-suffix.wasm plugin built in Go from the quickstart and compiled to WASM to demonstrate how to push a plugin to the BSR.
buf plugin push buf.build/acme/rpc-suffix \
--binary=rpc-suffix.wasm \
--create \
--create-type=check \
--create-visibility=publicThis command pushes the plugin rpc-suffix.wasm to the BSR organization acme at buf.build/acme/rpc-suffix.
Once pushed, the plugin is now available in the BSR and can be used by other developers.
Using the plugin
To use the plugin, you update your buf.yaml file to point to the remote plugin.
version: v2
modules:
- path: proto
name: buf.build/tutorials/lint-plugin
lint:
use:
- STANDARD
- RPC_SUFFIX
plugins:
- plugin: buf.build/acme/rpc-suffixNext, you need to update the buf.lock file to set the plugin version:
buf plugin updateWhen you run buf lint and buf breaking checks, they now use the plugin you just pushed to the BSR.
buf lint
proto/pet/v1/pet.proto:30:3:method name should not end with "Method" (buf.build/acme/rpc-suffix)