Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto_library: Bazel does not use toolchain since v29.0 #20182

Closed
tsawada opened this issue Jan 31, 2025 · 1 comment
Closed

proto_library: Bazel does not use toolchain since v29.0 #20182

tsawada opened this issue Jan 31, 2025 · 1 comment
Assignees
Labels

Comments

@tsawada
Copy link

tsawada commented Jan 31, 2025

My MODULE.bazel

bazel_dep(name = "toolchains_protoc", version = "0.3.6")
protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
protoc.toolchain(
    google_protobuf = "com_google_protobuf",
    version = "v26.0",
)
use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")
register_toolchains("@toolchains_protoc_hub//:all")
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a")
# single_version_override(module_name = "protobuf", version = "29.3")

.bazelrc

common --incompatible_enable_proto_toolchain_resolution

I use Bazel 7.4.1

With Protobuf v26.0 .. v28.3, proto_library uses prebuilt toolchain and the build finishes instantly.

$ bazel query 'deps(@googleapis//google/type:color_proto)'
@googleapis//google/type:color.proto
@googleapis//google/type:color_proto
@@protobuf~//:wrappers_proto
@@protobuf~//src/google/protobuf:wrappers.proto
@@protobuf~//src/google/protobuf:wrappers_proto

$ bazel build @googleapis//google/type:color_proto
...
INFO: Elapsed time: 1.267s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

With protobuf >= v29.0 by uncommenting the single_version_override line at the bottom, bazel starts compiling protoc

$ bazel query 'deps(@googleapis//google/type:color_proto)' 
@googleapis//google/type:color.proto
@googleapis//google/type:color_proto
@@protobuf~//:LICENSE
@@protobuf~//:license
@@protobuf~//:wrappers_proto
@@protobuf~//bazel/private:experimental_proto_descriptor_sets_include_source_info
@@protobuf~//bazel/private:experimental_proto_descriptor_sets_include_source_info_setting
@@protobuf~//bazel/private:strict_proto_deps
@@protobuf~//bazel/private:strict_proto_deps_setting
@@protobuf~//bazel/private:strict_public_imports
@@protobuf~//bazel/private:strict_public_imports_setting
@@protobuf~//src/google/protobuf:wrappers.proto
@@protobuf~//src/google/protobuf:wrappers_proto

$ bazel build @googleapis//google/type:color_proto
<< bazel starts compiling absl and proto >>
INFO: Elapsed time: 73.891s, Critical Path: 18.82s
INFO: 984 processes: 537 internal, 447 darwin-sandbox.
INFO: Build completed successfully, 984 total actions

For Bazel 7.4.1, Bazel uses precompiled binary when protobuf=v26.0 or v28.3, but not for v29.0...v29.3 as I mentioned above.
For Bazel 8.0.1, Bazel starts compiling protoc for both protobuf=v26.0 and v29.0.
Thus I'm guessing that proto_library being migrated from Bazel to starlark has something to do with this.

I wasn't able to reproduce this behavior for simpler targets like @protobuf//:any_proto or @googleapis//google/type:calendar_period_proto

@tsawada tsawada added the untriaged auto added to all issues by default when created. label Jan 31, 2025
@tsawada tsawada changed the title proto_library: Bazel does not use precompiled toolchain since v29.0 proto_library: Bazel does not use toolchain since v29.0 Jan 31, 2025
@JasonLunn JasonLunn added bazel and removed untriaged auto added to all issues by default when created. labels Feb 5, 2025
@zhangskz
Copy link
Member

zhangskz commented Feb 7, 2025

This is using https://github.com/aspect-build/toolchains_protoc which is a separate experimental repo not maintained by us. I recommend filing an issue there.

I believe this was broken by Bazel 8 and recent rules_proto changes at some point, but looks like may have been fixed in aspect-build/toolchains_protoc@56b554d#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5.

We don't currently have direct support for protoc prebuilts yet but have this feature on our radar: https://engdoc.corp.google.com/eng/doc/devguide/proto/news/2024-10-01.md#end-goal.

@zhangskz zhangskz closed this as completed Feb 7, 2025
mbland added a commit to mbland/rules_scala that referenced this issue Mar 1, 2025
Keeps the `README` guidance in sync with what we're actually using in
`WORKSPACE` for consistency's sake.

@crt-31 and I found that the Windows build failure for bazelbuild#1710 mentioned
in the earlier commit is related to the Windows/MSVC file path length
limit. `src/google/protobuf/compiler/java/java_features.pb.h`, the path
specified in the error message, doesn't exist until `protobuf` v25.0.

- protocolbuffers/protobuf#12947

Furthermore, the Protobuf team currently plans to just drop MSVC
support:

- https://protobuf.dev/news/v30/#poison-msvc--bazel
- protocolbuffers/protobuf#20085

I plan to experiment again with "Protobuf Toolchainization", which I'd
tried in October when beginning the Bzlmod experiment. Here are some
interesting background resources before I dig in on that:

- bazelbuild/rules_proto#213
- bazelbuild/rules_proto#179
- https://github.com/bazelbuild/rules_proto/releases/tag/6.0.0
- https://github.com/aspect-build/toolchains_protoc/
- protocolbuffers/protobuf#20182
- protocolbuffers/protobuf#19679
- protocolbuffers/protobuf#19558
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants