rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

rules_go pulling Envoy proxy protoc and breaking builds

Open popovicu opened this issue 4 months ago • 3 comments

rules_go version

0.54.1

gazelle version

0.43.0

bazel version

$ bazel version
Bazelisk version: v1.23.0
Build label: 8.3.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Jun 30 16:23:40 2025 (1751300620)
Build timestamp: 1751300620
Build timestamp as int: 1751300620

Build platform

Linux, x86_64


I'm trying to add a GCS Go API dependency to my project g2disk. This is done in popovicu/g2disk@5c081a7236d54e76b8a2713f07ac05d314ac3fa3

As a test, I simply want to build the GCS library:

bazel build //remote/gcs

However, the build fails because Go rules + Gazelle bring in some strange Envoy proxy dependencies, not sure why would they even be included:

$ bazel build //remote/gcs
ERROR: error loading package '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate//validate': Unable to find package for @@[unknown repo 'rules_python' requested from @@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate (did you mean 'rules_proto'?)]//python:proto.bzl: The repository '@@[unknown repo 'rules_python' requested from @@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate (did you mean 'rules_proto'?)]' could not be resolved: No repository visible as '@rules_python' from repository '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate'.
ERROR: /home/uros/.cache/bazel/_bazel_uros/62b3f0231c97c4b58fda1fd00c41b8ac/external/gazelle++go_deps+com_github_cncf_xds_go/xds/type/v3/BUILD.bazel:3:11: error loading package '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate//validate': Unable to find package for @@[unknown repo 'rules_python' requested from @@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate (did you mean 'rules_proto'?)]//python:proto.bzl: The repository '@@[unknown repo 'rules_python' requested from @@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate (did you mean 'rules_proto'?)]' could not be resolved: No repository visible as '@rules_python' from repository '@@gazelle++go_deps+com_github_envoyproxy_protoc_gen_validate'. and referenced by '@@gazelle++go_deps+com_github_cncf_xds_go//xds/type/v3:type'
ERROR: Analysis of target '//remote/gcs:gcs' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.389s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
FAILED: 
    Fetching repository @@gazelle++go_deps+io_opentelemetry_go_otel; starting
    Fetching repository @@gazelle++go_deps+org_golang_google_genproto; starting
    Fetching repository @@gazelle++go_deps+org_golang_google_api; starting
    Fetching repository @@gazelle++go_deps+org_golang_x_net; starting
    Fetching repository @@gazelle++go_deps+com_github_envoyproxy_go_control_plane_envoy; starting

My //remote/gcs target is an alias for @com_google_cloud_go_storage//:go_default_library.

This remote dependency was added to the project with this:

bazel run @rules_go//go -- get cloud.google.com/go/storage@latest

I've tried adding rules_python and rules_java to the MODULE.bazel file, but the error persisted.

popovicu avatar Aug 01 '25 00:08 popovicu

I can't reproduce this with:

bazel_dep(name = "rules_go", version = "0.55.1")
bazel_dep(name = "gazelle", version = "0.44.0")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

When I run:

go mod init example.com/m
bazel run @rules_go//go -- get cloud.google.com/go/storage@latest
bazel build @com_google_cloud_go_storage//:go_default_library

The build passes. rules_go just loads the transitive deps of your go.mod including its own go.mod, it doesn't bring in envoy proxy in any other way.

fmeum avatar Aug 02 '25 15:08 fmeum

You're right @fmeum. I've just run the small repro, and I figured out where things go wrong. It's the gazelle directive that introduces some wrinkles.

go_deps.gazelle_default_attributes(
    # Pointers here: https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/bzlmod.md#gazelle-directives
    directives = [
        "gazelle:proto disable",
    ],
)

For posterity, I was trying to solve the same problem from #3971

I'll ask somewhere else what is the right way to fix it, but you're right, this is not a problem with rules_go.

popovicu avatar Aug 02 '25 22:08 popovicu

Interestingly, I don't think the issues from #3971 matter anymore with all the latest versions, so the proto disabling directive no longer seems to matter, it can be safely removed (at least I'm doing so in my project without any issues).

popovicu avatar Aug 02 '25 23:08 popovicu