Skip to main content

Command Palette

Search for a command to run...

Bazel 9 Upstream Prebuilt Protobuf

Work in collaboration with the Google Protobuf team

Updated
2 min read
Bazel 9 Upstream Prebuilt Protobuf

Bazel 9.0 is a major long-term support (LTS) release. It contains new features and backwards incompatible changes.

This prebuilt protobuf compiler follows up on our blog article https://blog.aspect.build/never-compile-protoc-again which ended with the promise “We’re hoping to upstream our toolchains_protoc to the protobuf repository, so that the default Bazel experience will be fast.”

This is now (nearly) true as of the https://github.com/protocolbuffers/protobuf/releases/tag/v33.4 release.

We thank the Google Protobuf team for sponsoring this work and reviewing the implementation, including changes to the release process.

Enabling the Protobufs toolchains feature

Bazel 9 flips the --incompatible_enable_proto_toolchain_resolution flag to true. This means Bazel is responsible for resolving the symbol @protobuf//bazel/private:proto_toolchain_type to a “concrete” toolchain that provides the right protoc binary for your execution platform. This is also the case for a toolchain_type for each language stub generator.

If you’re on Bazel 9, there’s nothing to do, but earlier Bazels require you set the flag.

Opting-in

Until https://github.com/protocolbuffers/protobuf/pull/25313 lands and is released, you need to opt-in to using the protoc binaries from https://github.com/protocolbuffers/protobuf/releases. Add to your .bazelrc:

common --@protobuf//bazel/toolchains:prefer_prebuilt_protoc

note, if you have a repo_name=com_google_protobuf you’ll have to adapt the @protobuf name

Enforcing

You can enforce that no rules do the “Wrong Thing” of directly referencing the cc_binary target @protobuf//:protoc by following our snippets: https://github.com/aspect-build/toolchains_protoc#ensure-protobuf-and-grpc-never-built

If this fails to build, it means that there’s a bug you should find or report.

The https://github.com/aspect-build/toolchains_protoc and https://github.com/bazelbuild/rules_proto repositories are now archived, completing the deprecation period.

Next

Need help migrating from WORKSPACE to Bzlmod or other steps to move to Bazel 9? View Aspect Build services and email us at hello@aspect.build or ping us on Bazel Slack. We’re happy to support you.