|
| 1 | ++++ |
| 2 | +title = "Debugging" |
| 3 | +weight = 915 |
| 4 | +description = "Debugging common issues in Protocol Buffers." |
| 5 | +type = "docs" |
| 6 | ++++ |
| 7 | + |
| 8 | +Frequently asked questions and debugging scenarios encountered by protobuf |
| 9 | +users. |
| 10 | + |
| 11 | +<!--* |
| 12 | +# Document freshness: For more information, see go/fresh-source. |
| 13 | +freshness: { owner: 'sangki' reviewed: '2025-02-11' } |
| 14 | +*--> |
| 15 | + |
| 16 | +## Bazel: Resolving Issues with Prebuilt Protoc {#prebuilt-protoc} |
| 17 | + |
| 18 | +As mentioned in [this news article](/news/2026-01-16), |
| 19 | +Bazel 7 and later support builds that use a prebuilt protoc. When everything is |
| 20 | +configured correctly, this can save a lot of time building, reduce logging |
| 21 | +volume, and eliminate the need for C++ toolchain in non-C++ implementations. |
| 22 | + |
| 23 | +To prevent protoc compilation from source, add the following to your `.bazelrc` |
| 24 | +file: |
| 25 | + |
| 26 | +```bazel |
| 27 | +common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT |
| 28 | +common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT |
| 29 | +common --per_file_copt=external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT |
| 30 | +common --host_per_file_copt=external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT |
| 31 | +``` |
| 32 | + |
| 33 | +When there are hard-coded references to `@com_google_protobuf//:protoc` that are |
| 34 | +reachable by the dependency graph, protoc will force it to be built for those |
| 35 | +cases, negating this benefit. To resolve this, you'll need to find where the |
| 36 | +dependencies are and request that those rulesets be updated. |
| 37 | + |
| 38 | +To find where you depend on protoc, use the following command: |
| 39 | + |
| 40 | +```none |
| 41 | +bazel cquery 'somepath("//...", "@com_google_protobuf//:all")' |
| 42 | +``` |
| 43 | + |
| 44 | +**Note:** Prebuilts are only available for our standard set of platforms. Anyone |
| 45 | +on a nonstandard platform will have to build protoc from source. |
0 commit comments