error building com_github_prometheus_common: undefined types
What version of gazelle are you using?
0.24.0
What version of rules_go are you using?
0.30.0
What version of Bazel are you using?
4.2.1
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
Linux x64
What did you do?
I have added gazelle_dependencies at the bottom of the WORKSPACE folder below all go_rules directives like
go_embed_data_dependencies()
go_rules_dependencies()
go_register_toolchains()
and go() dependencies
What did you expect to see?
build succeeding
What did you see instead?
external/com_github_prometheus_common/expfmt/openmetrics_create.go:239:7: b.Exemplar undefined (type *io_prometheus_client.Bucket has no field or method Exemplar)
external/com_github_prometheus_common/expfmt/openmetrics_create.go:305:12: undefined: io_prometheus_client.Exemplar
external/com_github_prometheus_common/expfmt/openmetrics_create.go:448:41: undefined: io_prometheus_client.Exemplar
compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/compile: exit status 2
I have followed #1140 and moved the gazelle_dependencies() around in WORKSPACE, but that didn't help.
Please create a minimal example repo on github that demonstrates the problem. Without quite a bit more context there is no way to help out, unfortunately.
@achew22 I have created a minimal repo at https://github.com/bviswana101/BazelBuildTest to reproduce the problem. It mocks our mono repo with much of the complexity removed. Appreciate your guidance.
@bviswana101 I'm generally happy to help with problems like this, but weighing in at 18,134 LOC in just the first commit, this is WAY more than I have time to wade through. Can you possibly start with an empty repo and copy things into it until you're able to reproduce?
@achew22 i have pruned it considerably. most of it is just bazel files now. Let me know if this helps or i should go again at it. btw, i did start from a empty repo and populate...but might have been overzealous in ensuring that i don't miss the Root Cause.
I think you have something that imports com_github_prometheus_common but from an old version on these lines.
https://github.com/bviswana101/BazelBuildTest/blob/main/WORKSPACE#L76-L111
In the future bzlmod will fix most of this, hopefully, but for now it is a bit of guess and check work to find the thing that's importing an old and strange version. Sorry to say.
@achew22 I was hitting this error and managed to fix it.
I had a github.com/prometheus/common v0.37.0 in my go.mod
and in my workspace
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
container_repositories = "repositories",
)
protobuf_deps()
container_repositories()
go_rules_dependencies()
load(
"@io_bazel_rules_docker//go:image.bzl",
_go_image_repos = "repositories",
)
go_register_toolchains(version = "1.19")
load("//:deps.bzl", "go_dependencies")
# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()
_go_image_repos()
gazelle_dependencies()
If I move _go_image_repos() to before go_dependencies() I would hit this error.
gazelle_dependencies adds a lot of go_repository which is unfortunate (they are only needed to build gazelle I think, not to expose as a library?), but luckily they are wrapped in _maybe so it won't override if called last, and if lucky versions will be compatible with gazelle.
Something similar probably happens with rules_docker go dependencies