Skip to content

Commit

Permalink
Use prebuilt protoc toolchain
Browse files Browse the repository at this point in the history
This downloads a prebuilt protoc binary and uses that through regular
toolchain resolution (with the incompatible flag). This increases build
speed and removes the many compiler warnings that pop-up during
compilation of protoc sources. And more importantly works better on
Windows. Where for some reason the protoc compilation fails from an
external module:

    gits/bb-deployments $ bazel build \
        --override_module protobuf=../protobuf \
        @protobuf//src/google/protobuf:timestamp_proto
    ERROR: C:/tmp/eprbnvuo/external/protobuf~/src/google/protobuf/compiler/java/BUILD.bazel:99:11: Compiling src/google/protobuf/compiler/java/context.cc [for tool] failed: undeclared inclusion(s) in rule '@@protobuf~//src/google/protobuf/compiler/java:java':
    this rule is missing dependency declarations for the following files included by 'src/google/protobuf/compiler/java/context.cc':
      'bazel-out/x64_windows-opt-exec-ST-d57f47055a04/bin/external/protobuf~/src/google/protobuf/compiler/java/_virtual_includes/java/google/protobuf/compiler/java/context.h'

Whereas it does work when building from its own checkout:

    ~/gits/protobuf $ bazel build \
        //src/google/protobuf:timestamp_proto
    Target //src/google/protobuf:timestamp_proto up-to-date:
      bazel-bin/src/google/protobuf/timestamp_proto-descriptor-set.proto.bin
    INFO: Build completed successfully, 1 total action
  • Loading branch information
stagnation committed Aug 20, 2024
1 parent cc1f3a9 commit a2c16d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ build:remote-ubuntu-22-04 --extra_execution_platforms=//tools/remote-toolchains:

# When running bare executors on your own host machine.
build:remote-local --config=remote-exec

common --incompatible_enable_proto_toolchain_resolution
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bazel_dep(name = "rules_oci", version = "1.7.6")
bazel_dep(name = "rules_pkg", version = "0.10.1")
bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "toolchains_llvm", version = "1.0.0")
bazel_dep(name = "toolchains_protoc", version = "0.3.1")

# # Workarounds 2026-06-27
# ERROR: in tag at https://bcr.bazel.build/modules/grpc-java/1.62.2/MODULE.bazel:89:15: no repository visible as '@com_google_protobuf_javalite' to the repository '@@grpc-java~', but referenced by label '@com_google_protobuf_javalite//:protobuf_javalite' in attribute 'target' of tag 'override'. Is the module 'grpc-java' missing a bazel_dep or use_repo(..., "com_google_protobuf_javalite")?
Expand Down
7 changes: 5 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2c16d0

Please sign in to comment.