Skip to content

Conversation

@srikrsna-buf
Copy link
Owner

@srikrsna-buf srikrsna-buf commented Sep 4, 2025

Add support for @bufbuild/protobuf runtime

This PR adds support for generating service definitions compatible with the @bufbuild/protobuf runtime, a popular and conformant protobuf implementation.

What this PR does:

Adds a new plugin option called runtime to select the protobuf runtime. Supported values are bufbuild-protobuf and defaults to use google-protobuf. When the runtime is set to bufbuild-protobuf, the plugin generates service definitions that use @bufbuild/protobuf's message types and serialization methods instead of the default runtime.

Why this change?

@bufbuild/protobuf supports Editions and passes significantly more conformance tests than currently supported runtimes, ensuring better protocol buffer compatibility.

Usage

Alongside grpc-tools, users will need to install @bufbuild/protoc-gen-es and change the grpc_tools_node_protoc call to use the new runtime and use the protoc-gen-es:

npm install -g grpc-tools @bufbuild/protoc-gen-es
grpc_tools_node_protoc --es_out=target=js,js_import_style=legacy_commonjs:../helloworld/static_codegen_es/ --grpc_out=grpc_js,runtime=bufbuild-protobuf:../helloworld/static_codegen_es/ helloworld.proto

Alternatives

Happy to discuss other options like a separate runtime package or plugin package. Having either of those will also bring TypeScript and ESM support.

Signed-off-by: Sri Krishna <[email protected]>
Copy link
Owner Author

@srikrsna-buf srikrsna-buf left a comment

Choose a reason for hiding this comment

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

Figuring out the tests

bool grpc_js;
// Omit instanceof check for messages in serialize methods
bool omit_serialize_instanceof;
// Runtime to use for protobuf serialization (default: "google-protobuf", "es" for @bufbuild/protobuf)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Perhaps we should use bufbuild-protobuf instead of es

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be a better fit for the "runtime" argument. I wouldn't change the example directory name, and it isn't feasible to change --es_out.

bool grpc_js;
// Omit instanceof check for messages in serialize methods
bool omit_serialize_instanceof;
// Runtime to use for protobuf serialization (default: "google-protobuf", "es" for @bufbuild/protobuf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be a better fit for the "runtime" argument. I wouldn't change the example directory name, and it isn't feasible to change --es_out.

}

grpc::string NodeObjectPath(const Descriptor* descriptor) {
grpc::string NodeObjectPath(const Descriptor* descriptor, const grpc::string& runtime) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't know how to test it, but the diff looks good to me.

@srikrsna-buf srikrsna-buf changed the title Support bufbuild-protobuf Support @bufbuild/protobuf Sep 10, 2025
Signed-off-by: Sri Krishna <[email protected]>
Signed-off-by: Sri Krishna <[email protected]>
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.

3 participants