Skip to content

Add anthropics/buffa plugin v0.3.0#2333

Open
iainmcgin wants to merge 1 commit intobufbuild:mainfrom
iainmcgin:add-buffa-plugin
Open

Add anthropics/buffa plugin v0.3.0#2333
iainmcgin wants to merge 1 commit intobufbuild:mainfrom
iainmcgin:add-buffa-plugin

Conversation

@iainmcgin
Copy link
Copy Markdown

@iainmcgin iainmcgin commented Mar 17, 2026

Adds the protoc-gen-buffa plugin for Rust protobuf code generation, under the new top-level anthropics org as requested in earlier review.

About buffa

buffa is a zero-copy Rust Protobuf implementation with:

  • Editions support (2023/2024) and full proto2/proto3 coverage
  • Zero-copy view types - borrowed &str/&[u8] field access without owned allocation
  • no_std + alloc compatible
  • Proto3 JSON mapping with serde integration
  • Conformance: passes the protobuf conformance suite (5539 binary+JSON tests, 0 expected failures)

Crates are on crates.io: buffa, buffa-types, protoc-gen-buffa.

Output convention

The plugin emits one .rs file per proto file with a flat naming scheme: foo/v1/bar.proto -> foo.v1.bar.rs. No subdirectories, no mod.rs - module tree assembly is a separate packaging plugin (protoc-gen-buffa-packaging, submitted separately).

Open questions for review

  1. opts: I set json=true and views=true. If BSR has conventions for which opts to expose vs bake in, please advise.
  2. File naming: The per-file output naming (pkg.subpkg.file.rs) is flat but per-proto-file, not per-package like prost. If BSR's lib.rs synthesis expects per-package naming instead, we can add a plugin option to switch modes.

Process note

CONTRIBUTING.md asks for an issue first - happy to open one if you would prefer to discuss before reviewing the PR. Filed this as a draft in the meantime.

Related: #2334 (anthropics/connect-rust) declares this plugin as a dep, so this one would need to land first.

@bufdev
Copy link
Copy Markdown
Member

bufdev commented Mar 19, 2026

I think we might want to make a top-level anthropics org for this, instead of under community - also re: connect-rust.

@iainmcgin
Copy link
Copy Markdown
Author

I think we might want to make a top-level anthropics org for this, instead of under community - also re: connect-rust.

Sure thing I'll redraft as part of updating to the new versions I'll likely release next week.

@iainmcgin iainmcgin changed the title Add community/anthropics-buffa plugin v0.2.0 Add anthropics/buffa plugin v0.2.0 Apr 2, 2026
@iainmcgin iainmcgin changed the title Add anthropics/buffa plugin v0.2.0 Add anthropics/buffa plugin v0.3.0 Apr 2, 2026
@@ -0,0 +1,4 @@
source:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's supposed to be a crates section here? See the prost plugin as an ezample

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to crate ref instead of github ref 👍

buffa is a zero-copy Rust Protobuf implementation with editions support
(2023/2024), no_std compatibility, and view types for borrowed field
access. Passes the protobuf conformance suite (5539 binary+JSON tests).

The plugin emits one .rs file per proto file using a flat naming
convention (`foo/v1/bar.proto` -> `foo.v1.bar.rs`). Module tree
assembly is a separate `protoc-gen-buffa-packaging` plugin in the same
repo, registered separately.

Crates: https://crates.io/crates/protoc-gen-buffa
Repo: https://github.com/anthropics/buffa
@iainmcgin iainmcgin marked this pull request as ready for review April 3, 2026 15:54
Copy link
Copy Markdown
Member

@pkwarren pkwarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure reproducible builds, we check in a checksum file of generated code using the plugin. This verifies e2e code generation is functional and also ensures that the codegen doesn't change across builds.

https://github.com/bufbuild/plugins/blob/main/CONTRIBUTING.md#creating-a-new-plugin

To create the files, run make test PLUGINS=anthropics/buffa:latest and check in the plugin.sum files created under tests/testdata/buf.build/anthropics/.

@@ -0,0 +1,15 @@
# syntax=docker/dockerfile:1.19
FROM rust:1.91.1-alpine3.22 AS builder
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this branch to latest main then we can update this image to the latest base image:

Suggested change
FROM rust:1.91.1-alpine3.22 AS builder
FROM rust:1.95.0-alpine3.23@sha256:606fd313a0f49743ee2a7bd49a0914bab7deedb12791f3a846a34a4711db7ed2 AS builder

RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked --mount=type=cache,target=/root/target \
cargo install protoc-gen-buffa --version 0.3.0 --locked --root /app

FROM gcr.io/distroless/static-debian12:latest@sha256:87bce11be0af225e4ca761c40babb06d6d559f5767fbf7dc3c47f0f1a466b92c AS base
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FROM gcr.io/distroless/static-debian12:latest@sha256:87bce11be0af225e4ca761c40babb06d6d559f5767fbf7dc3c47f0f1a466b92c AS base
FROM gcr.io/distroless/static-debian13:latest@sha256:47b2d72ff90843eb8a768b5c2f89b40741843b639d065b9b937b07cd59b479c6 AS base

Comment thread plugins/anthropics/buffa/v0.3.0/buf.plugin.yaml
@pkwarren pkwarren requested a review from stefanvanburen April 20, 2026 16:43
@stefanvanburen
Copy link
Copy Markdown
Member

  1. opts: I set json=true and views=true. If BSR has conventions for which opts to expose vs bake in, please advise.

Seems reasonable to me to enable both — since generated SDKs aren't configurable, I think including all of the features makes sense to me (users who want more control can fall back to local generation).

2. File naming: The per-file output naming (pkg.subpkg.file.rs) is flat but per-proto-file, not per-package like prost. If BSR's lib.rs synthesis expects per-package naming instead, we can add a plugin option to switch modes.

What would be most helpful here is actually if both buffa and connect-rust included the lib.rs generation logic themselves (enabled with a plugin option; generate_librs=true strawman name; disabled by default) so that the BSR doesn't need any sort of special-casing for generating it on our end — is that possible to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants