|  | 
| 1 | 1 | # Bazel toolchain for pre-built protoc | 
| 2 | 2 | 
 | 
| 3 |  | -Using Protocol Buffers with Bazel has always been painful. | 
|  | 3 | +_#NeverCompileProtocAgain_ | 
|  | 4 | + | 
|  | 5 | +Using Protocol Buffers with Bazel has always been difficult. | 
| 4 | 6 | 
 | 
| 5 | 7 | - Nearly every Bazel user has waited for `protoc` to compile from sources many, MANY times. | 
|  | 8 | +  This universally slows down builds, especially due to issues like https://github.com/bazelbuild/bazel/issues/7095 where it is observed to be easily cache-busted. | 
| 6 | 9 | - The versioning of the protobuf module on Bazel Central Registry has fallen behind and contains many patches. | 
|  | 10 | +  As of mid-March 2024 there are [7 patches](https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/protobuf/23.1/patches) | 
|  | 11 | +  which essentially constitute a fork of the protobuf repo specifically for publishing to BCR. | 
| 7 | 12 | - Relying on the protobuf runtime for each language from the `@com_google_protobuf` repo forces you to use | 
| 8 | 13 |   the same version of the runtime for all languages in a monorepo, and matching protoc. | 
| 9 | 14 | 
 | 
| 10 | 15 | The key observations: | 
| 11 | 16 | 
 | 
| 12 | 17 | - `protoc` has always been distributed as pre-built binaries on https://github.com/protocolbuffers/protobuf/releases | 
| 13 |  | -- the protobuf runtimes for each language are distributed to the appropriate package manager | 
|  | 18 | +- That distribution includes the "well known types" such as `timestamp.proto` | 
|  | 19 | +- The protobuf runtimes for each language are distributed to the appropriate package manager. | 
| 14 | 20 | 
 | 
| 15 | 21 | Bazel 7 introduced `--incompatible_enable_proto_toolchain_resolution` to allow us fetch `protoc` rather than re-build it! | 
| 16 | 22 | That flag ALSO decouples how each language rule locates the runtime. | 
| 17 |  | - | 
| 18 |  | -This repo simply contains a toolchain that resolves those pre-built binaries. | 
|  | 23 | +Thanks to that flag, this repo simply contains a toolchain that resolves those pre-built binaries. | 
| 19 | 24 | 
 | 
| 20 | 25 | See `examples` for several language rules like `py_proto_library` and `java_proto_library`. | 
| 21 | 26 | There is NO dependency on `@com_google_protobuf` anywhere. | 
|  | 
0 commit comments