protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

feat(bazel): wire up prebuilt protoc toolchain

Open alexeagle opened this issue 2 months ago • 5 comments

Upstreamed from my https://github.com/aspect-build/toolchains_protoc which provided this feature outside the protobuf repo.

Adds:

  • private API: repository rule prebuilt_protoc_repo to fetch a protoc binary from GitHub releases
  • public API: repository rule prebuilt_toolchains_repo that creates the "hub" letting Bazel's toolchain resolver download only for the execution platform
  • public API: module_extension + tag protoc.prebuilt_toolchain to wrap up the above for bzlmod users
  • WORKSPACE users can live with the inconvenience of having to create toolchains themselve
  • example of proto_library rule with intentionally non-functional cc toolchain, exercising the feature

This needs work with @thesayyn to:

  • constrain users to choosing a protoc version agreeing with design doc https://docs.google.com/document/d/16N-eU-0zHbWmxEuaUAIFTJwQLekIXZ8zIC3K4XDr20E/edit
  • also register lang toolchains when the flag is enabled

Work towards #19558

alexeagle avatar Oct 22 '25 01:10 alexeagle

This looks reasonable to me. But it's still missing the validation layer AFAICT. Is this PR waiting for that? Also the tests are all still broken

mkruskal-google avatar Nov 15 '25 04:11 mkruskal-google

Sure, I can pick up something like https://github.com/protocolbuffers/protobuf/pull/23539 - the only comment I got there was "cannot reproduce" but I'd like to know if the guarantee is strong enough.

Separately I'd be very happy to land this one first. That could unblock the flag flip in time for Bazel 9 due in a month.

alexeagle avatar Nov 17 '25 00:11 alexeagle

Sure, I can pick up something like #23539 - the only comment I got there was "cannot reproduce" but I'd like to know if the guarantee is strong enough.

Separately I'd be very happy to land this one first. That could unblock the flag flip in time for Bazel 9 due in a month.

I'd probably like to see version check to prevent use of arbitrarily old versions of prebuilt protoc or newer versions of protoc from being used like w https://protobuf.dev/support/cross-version-runtime-guarantee/.

zhangskz avatar Nov 17 '25 20:11 zhangskz

Sure, I can pick up something like #23539 - the only comment I got there was "cannot reproduce" but I'd like to know if the guarantee is strong enough.

Separately I'd be very happy to land this one first. That could unblock the flag flip in time for Bazel 9 due in a month.

+1 to Sandy, while we might be ok with landing this PR first, we definitely wouldn't want to flip the flag without the validation we laid out in the design.

I'm not sure what guarantee is in that prototype, but it does seem like an appropriate place to add the validation

mkruskal-google avatar Nov 18 '25 00:11 mkruskal-google

okay @zhangskz I've added the version verification to this PR, PTAL

alexeagle avatar Nov 20 '25 11:11 alexeagle