bazelbuild / stardoc

Stardoc: Starlark Documentation Generator
Apache License 2.0
103 stars 40 forks source link

Upgrading to proto toolchains #236

Closed lberki closed 2 weeks ago

lberki commented 2 weeks ago

I'm trying to upgrade Stardoc to work with --incompatible_enable_proto_toolchain_resolution as part of yak shaving to make rules_go work with --experimental_sibling_repository_layout (I need to upgrade the Stardoc version there, see https://github.com/bazelbuild/rules_go/pull/3966)

I'm failing. My best attempt can be seen here:

https://github.com/bazelbuild/stardoc/compare/0.6.2...lberki-proto-toolchains?expand=1

, which works for --enable_bzlmod, but not for --noenable_bzlmod, which, regrettably, I also need to support.

The command to reproduce the breakage is

bazel build //stardoc/proto:stardoc_output_java_proto --incompatible_enable_proto_toolchain_resolution --enable_bzlmod and the error message is something like this (but a lot more):

  symbol:   class GeneratedMessageV3
  location: package com.google.protobuf
bazel-out/k8-fastbuild/bin/stardoc/proto/_javac/stardoc_output_proto/libstardoc_output_proto-speed_tmp/com/google/devtools/build/skydoc/rendering/proto/StardocOutputProtos.java:9353: error: package com.google.protobuf.GeneratedMessageV3 does not exist
        com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
                                              ^
bazel-out/k8-fastbuild/bin/stardoc/proto/_javac/stardoc_output_proto/libstardoc_output_proto-speed_tmp/com/google/devtools/build/skydoc/rendering/proto/StardocOutputProtos.java:9341: error: package com.google.protobuf.GeneratedMessageV3 does not exist
        com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {

This looks like a mismatch between the protoc plugin and the runtime version, but I have no idea how that came to be and how to fix it.

Funnily enough, the diff in its current state doesn't work with either value of --enable_bzlmod, but if I comment out the protoc_toolchains() invocations in the WORKSPACE file, it start to work with --enable_bzlmod but not with --noenable_bzlmod, somewhat expectedly citing the inability to find some toolchains.

The obvious shot in the dark to replace the protoc_toolchains version with 21.7 instead of 25.3 does not help.

How do I fix this? Or how do I even debug this?

lberki commented 2 weeks ago

@alexeagle maybe you have an idea?

lberki commented 2 weeks ago

I dug a bit deeper and it turns out that in the non-working case, protoc seems to come from the protoc_toolchains.linux_x86_64 repository, whereas in the working case, it's toolchains_protoc~~protoc~toolchains_protoc_hub.linux_x86_64.

My guess: the protoc_toolchains() stanza makes Bazel use the wrong protoc version, for some values of "wrong".

lberki commented 2 weeks ago

Argh. Got it. Turns out, the for some reason, without the protoc_toolchains() stanza, protoc 27.1 was used, with it, 25.3. If I update the version to 27.1 it starts working.

lberki commented 2 weeks ago

236 makes Bazel succeed in building //stardoc/proto:stardoc_output_java_proto with both values of --enable_bzlmod and --incompatible_enable_proto_toolchain_resolution. Let's see what the presubmits say.

tetromino commented 2 weeks ago

Fixed by @lberki in #237