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

rules_cc & rules_java pulled in by github.com/envoyproxy/protoc-gen-validate/validate BUILD file cause build to fail #1980

Open
fishy opened this issue Nov 14, 2024 · 0 comments

Comments

@fishy
Copy link

fishy commented Nov 14, 2024

What version of gazelle are you using?

0.40.0

What version of rules_go are you using?

0.50.1

What version of Bazel are you using?

7.4.1

Does this issue reproduce with the latest releases of all the above?

Those are latest releases

What operating system and processor architecture are you using?

linux/amd64

What did you do?

When github.com/envoyproxy/protoc-gen-validate/validate is imported by some go code, its BUILD file references to rules_cc and rules_java, which would cause build to fail if I disable gazelle:proto, even if I added them to MODULES.bazel. here is a minimal reproducer:

$ cat BUILD.bazel 
load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_binary", "go_library")

# gazelle:proto disable
gazelle(name = "gazelle")

go_library(
    name = "test-gazelle_lib",
    srcs = ["main.go"],
    importpath = "github.com/fishy/test-gazelle",
    visibility = ["//visibility:private"],
    deps = ["@com_github_envoyproxy_protoc_gen_validate//validate"],
)

go_binary(
    name = "test-gazelle",
    embed = [":test-gazelle_lib"],
    pure = "on",
    visibility = ["//visibility:public"],
)

$ cat go.mod 
module github.com/fishy/test-gazelle

go 1.23

require github.com/envoyproxy/protoc-gen-validate v1.1.0

require (
        github.com/google/go-cmp v0.6.0 // indirect
        google.golang.org/protobuf v1.34.2 // indirect
)

$ cat main.go 
package main

import (
        "fmt"

        _ "github.com/envoyproxy/protoc-gen-validate/validate"
)

func main() {
        fmt.Println("Hello")
}

$ cat MODULE.bazel
bazel_dep(name = "rules_go", version = "0.50.1")
bazel_dep(name = "gazelle", version = "0.40.0")
bazel_dep(name = "rules_cc", version = "0.1.0")
bazel_dep(name = "rules_java", version = "8.3.2")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
    name = "go_sdk",
    version = "1.23.3",
)

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
go_deps.config(check_direct_dependencies = "error")
go_deps.gazelle_default_attributes(
    directives = [
        "gazelle:proto disable",
    ],
)
use_repo(
    go_deps,
    "com_github_envoyproxy_protoc_gen_validate",
)
$ bazel build :test-gazelle
ERROR: error loading package '@@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate//validate': Unable to find package for @@[unknown repo 'rules_java' requested from @@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate]//java:defs.bzl: The repository '@@[unknown repo 'rules_java' requested from @@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate]' could not be resolved: No repository visible as '@rules_java' from repository '@@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate'.
ERROR: /home/fishy/work/test-gazelle/BUILD.bazel:7:11: error loading package '@@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate//validate': Unable to find package for @@[unknown repo 'rules_java' requested from @@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate]//java:defs.bzl: The repository '@@[unknown repo 'rules_java' requested from @@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate]' could not be resolved: No repository visible as '@rules_java' from repository '@@gazelle~~go_deps~com_github_envoyproxy_protoc_gen_validate'. and referenced by '//:test-gazelle_lib'
ERROR: Analysis of target '//:test-gazelle' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.133s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

We only need to go lib there, I was hoping there's a way to ignore rules_cc and rules_java that's not really used by the go_library

What did you expect to see?

What did you see instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant