bazel-gazelle: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate'
What version of rules_go are you using?
0.25.1
What version of gazelle are you using?
0.22.3
What version of Bazel are you using?
3.7 & 4.0
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
MacOS 11.1 Intel Go 1.15.6
Any other potentially useful information about your toolchain?
## in BUILD
# gazelle:go_generate_proto false
# gazelle:proto disable_global
## in WORKSPACE
http_archive(
    name = "com_google_protobuf",
    sha256 = "d0f5f605d0d656007ce6c8b5a82df3037e1d8fe8b121ed42e536f569dec16113",
    strip_prefix = "protobuf-3.14.0",
    urls = [
        "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz",
        "https://github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz",
    ],
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
## relevant entries from deps.bzl built by gazelle
    go_repository(
        name = "com_github_envoyproxy_go_control_plane",
        build_file_proto_mode = "disable_global",
        importpath = "github.com/envoyproxy/go-control-plane",
        sum = "h1:bbmjRkjmP0ZggMoahdNMmJFFnK7v5H+/j5niP5QH6bg=",
        version = "v0.9.8",
    )
    go_repository(
        name = "com_github_envoyproxy_protoc_gen_validate",
        build_file_proto_mode = "disable_global",
        importpath = "github.com/envoyproxy/protoc-gen-validate",
        sum = "h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=",
        version = "v0.1.0",
    )
    go_repository(
        name = "com_github_cncf_udpa_go",
        build_file_proto_mode = "disable_global",
        importpath = "github.com/cncf/udpa/go",
        sum = "h1:inpz6arsmh6ys7jjP0G1noZqKcCPpV4GZmffBPilAjA=",
        version = "v0.0.0-20201211205326-cc1b757b3edd",
    )
What did you do?
I imported github.com/envoyproxy/go-control-plane to build an auth server for envoy
What did you expect to see?
Go builds just fine, but Bazel does not
What did you see instead?
ERROR: /external/com_github_cncf_udpa_go/udpa/annotations/BUILD.bazel:3:11: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate': target 'validate' not declared in package 'validate' (did you mean 'validate.h'?) defined by /external/com_github_envoyproxy_protoc_gen_validate/validate/BUILD and referenced by '@com_github_cncf_udpa_go//udpa/annotations:annotations'
ERROR: /external/com_github_envoyproxy_go_control_plane/envoy/type/v3/BUILD.bazel:3:11: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate': target 'validate' not declared in package 'validate' (did you mean 'validate.h'?) defined by /external/com_github_envoyproxy_protoc_gen_validate/validate/BUILD and referenced by '@com_github_envoyproxy_go_control_plane//envoy/type/v3:type'
ERROR: /external/com_github_cncf_udpa_go/xds/core/v3/BUILD.bazel:3:11: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate': target 'validate' not declared in package 'validate' (did you mean 'validate.h'?) defined by /external/com_github_envoyproxy_protoc_gen_validate/validate/BUILD and referenced by '@com_github_cncf_udpa_go//xds/core/v3:core'
ERROR: /external/com_github_envoyproxy_go_control_plane/envoy/type/matcher/v3/BUILD.bazel:3:11: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate': target 'validate' not declared in package 'validate' (did you mean 'validate.h'?) defined by /external/com_github_envoyproxy_protoc_gen_validate/validate/BUILD and referenced by '@com_github_envoyproxy_go_control_plane//envoy/type/matcher/v3:matcher'
ERROR: /external/com_github_envoyproxy_go_control_plane/envoy/config/core/v3/BUILD.bazel:3:11: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate': target 'validate' not declared in package 'validate' (did you mean 'validate.h'?) defined by /external/com_github_envoyproxy_protoc_gen_validate/validate/BUILD and referenced by '@com_github_envoyproxy_go_control_plane//envoy/config/core/v3:core'
ERROR: /external/com_github_envoyproxy_go_control_plane/envoy/service/auth/v3/BUILD.bazel:3:11: no such target '@com_github_envoyproxy_protoc_gen_validate//validate:validate': target 'validate' not declared in package 'validate' (did you mean 'validate.h'?) defined by /external/com_github_envoyproxy_protoc_gen_validate/validate/BUILD and referenced by '@com_github_envoyproxy_go_control_plane//envoy/service/auth/v3:auth'
I hunted through all the references to protoc-gen-validate in rules_go / gazelle, of which there are quite a few. Adding protobuf as an http_archive link as per https://github.com/bazelbuild/rules_go/issues/2489#issuecomment-627519193 got me past a first batch of errors. In another issue, you suggested using tag/commit instead of version/sum in the go_repository, but that didn’t seem to work.
It seems like protoc-gen-validate has caused a lot of heartache, so maybe there isn’t an easy solution, but I’m not quite sure where to go from here. This is just a transitive dependency, so I’m happy to pin it or not load it as a go_repository or whatever might make this work.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (3 by maintainers)
I also ran into this error and can confirms it’s fixed by https://github.com/envoyproxy/protoc-gen-validate/pull/471. Unfortunately, that requires specifying
commitin thego_repositoryrule forcom_github_envoyproxy_protoc_gen_validate.@derekperkins I suspect that we are both going through the same process – I’m upgrading to the latest
rules_goand stepping through the errors one at a time. I am still struggling with themultiple copies of package passed to linkererrors as well.Here’s the patch I ended up with:
and the
go_repositoryrule:Sorry, it looks like this still needs some debugging, but unfortunately I don’t have bandwidth to look into it yet. I would have expected your
go_repositorydeclaration from this comment to work, so perhaps something is wrong inside Gazelle’s dependency resolution.Sorry to be slow to get back to this.
build_file_naming_conventionshould be"go_default_library", not"go-default_library". Sorry for the typo… though I’m surprised nothing reported an error because of that.Could you confirm whether there are build files in that repo and which naming convention is used? It would help narrow this down.
You can see Bazel’s view of a repo by looking in a directory like
$(bazel info output_base)/external/com_github_cncf_udpa_go. That’s the directory produced by the repository rule forcom_github_cncf_udpa_go. It should have build files either checked into the original Git repository or generated by Gazelle withingo_repository.build_file_naming_conventioncontrols two things. First, it determines whether Gazelle targets have names likego_default_libraryorvalidate. By default ingo_repository, Gazelle uses theimport_aliasconvention, which generates targets with names likevalidatebut also aliases namedgo_default_libraryso either name can be used. If the repository already has build files, they won’t be modified though. So the second effect ofbuild_file_naming_conventionis to declare which naming convention is used for dependency resolution in other repositories. If a repository has checked in build files with names following thego_default_libraryconvention, this tells Gazelle in other repositories to use those names.Setting
build_file_naming_convention = "go-default_library"didn’t seem to affect anything. I also tried withbuild_file_generation = "off"as suggested in #892, but that didn’t change the outcome.github.com/cncf/udpahas build files, butgithub.com/cncf/udpa/gois declared as a separate module, and it does not contain any build files. Marking it as such gives this error