rules_go: rules_go (or gazelle?) fails to resolve google/rpc/code.proto in com_github_googleapis_gax_go_v2
Workaround / Solution
See mpawlowski’s solution or linzhp’s explanation.
What version of rules_go are you using?
0.41.0
What version of gazelle are you using?
0.32.0
What version of Bazel are you using?
6.2.0
Does this issue reproduce with the latest releases of all the above?
I didn’t try Bazel 6.2.1. rules_go and gazelle are latest. It does not reproduce with the previous releases, 0.40.1 and 0.31.1.
What operating system and processor architecture are you using?
Similar to Debian testing, x86.
Any other potentially useful information about your toolchain?
n/a
What did you do?
Updated to rules_go 0.41 and gazelle 0.32 and tried to build https://github.com/googlecloudrobotics/core.
What did you expect to see?
Build succeeds.
What did you see instead?
ERROR: /usr/local/google/home/rodrigoq/.cache/bazel/_bazel_rodrigoq/f3eae32d9daee2b06e08ee03f5238858/external/com_github_googleapis_gax_go_v2/apierror/internal/proto/BUILD.bazel:18:17: no such package '@com_github_googleapis_gax_go_v2//google/rpc': BUILD file not found in directory 'google/rpc' of external repository @com_github_googleapis_gax_go_v2. Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_googleapis_gax_go_v2//apierror/internal/proto:jsonerror_go_proto'
The error appears to be because code.proto is resolved incorrectly to //google/rpc:code_proto
instead of to something inside @org_golang_google_genproto
as the release notes suggest.
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 18 (9 by maintainers)
Commits related to this issue
- Bump rules_go, rules_pkg, gazelle, and buildtools Tested with `bazel build --incompatible_disable_starlark_host_transitions //...`. Fixes #95. These aren't the newest rules_go/gazelle because of htt... — committed to googlecloudrobotics/core by drigz a year ago
- Bump rules_go, rules_pkg, gazelle, and buildtools (#175) Tested with `bazel build --incompatible_disable_starlark_host_transitions //...`. Fixes #95. These aren't the newest rules_go/gazelle beca... — committed to googlecloudrobotics/core by drigz a year ago
- Update rules_go and Go dependencies (#179) This required a slightly tricky manual change to go_repositories.bzl: https://github.com/bazelbuild/rules_go/issues/3625 I also updated the Go dependenc... — committed to googlecloudrobotics/core by drigz a year ago
- Add an entry for "github.com/googleapis/gax-go/v2" to default_gazelle_overrides.bzl When updating to v0.32.0 anyone with a transient dependency on `github.com/googleapis/gax-go/v2` will need to add a... — committed to andrewmbenton/bazel-gazelle by andrewmbenton 10 months ago
- Add an entry for "github.com/googleapis/gax-go/v2" to default_gazelle_overrides.bzl When updating to v0.32.0 anyone with a transient dependency on `github.com/googleapis/gax-go/v2` will need to add a... — committed to andrewmbenton/bazel-gazelle by andrewmbenton 10 months ago
- Add an entry for "github.com/googleapis/gax-go/v2" to default_gazelle_overrides.bzl (#1623) * Add an entry for "github.com/googleapis/gax-go/v2" to default_gazelle_overrides.bzl When updating to v0.... — committed to bazelbuild/bazel-gazelle by andrewmbenton 10 months ago
@drigz
As you mentioned in the description of this issue,
com_github_googleapis_gax_go_v2
actually depends on//google/rpc:code_proto
. 😃So this is what would be necessary:
This is assuming that you have the googleapis archive using the name
googleapis
in your WORKSPACE:Also,
build_file_generation = "on"
does not seem necessary.This did the trick for me
For those using Bzlmod and struggling to resolve this manually (as I have been for many hours over the last couple days), adding the following to
MODULE.bazel
worked for our setup:I suppose this might be a useful addition to the registry of default build directives.
The release notes overlook the case of a dependency on a third-party repo that depends on googleapis - unfortunately this probably affects a larger number of clueless maintainers like me.
I don’t understand whether com_github_googleapis_gax_go_v2 is “importing Google APIs proto and generating Go code” or whether it should be. It was also not clear how/where to add these resolution directives. fmeum’s comment adds the missing info (thank you) and suggests that I should tell go_repository to generate Go code.
mpawlowski’s comment implies that the go_repository does not need to generate the Go code, but that Gazelle’s
update-repos
command is unable to guess this. This seems like a much simpler workaround that is less likely to break if the repo adds new dependencies on googleapis in future, but I (obviously) don’t understand everything that’s going on here.@fmeum Is
build_file_proto_mode = "disable_global"
a good way to solve the problem? Or is there a reason the maintainers did not suggest it?