bazel-contrib / bazel-contrib/rules_go
gazelle resolve directives not working
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 762
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
### What version of gazelle are you using?
0.35.0 (bazel-gazelle)
### What version of rules_go are you using?
0.44.0
### What version of Bazel are you using?
6.4.0
### Does this issue reproduce with the latest releases of all the above?
Yes (currently using latest versions).
### What operating system and processor architecture are you using?
Ubuntu 20.04, x86_64
### Any other potentially useful information about your toolchain?
Using GO version 1.20.3
### What did you do?
Created a minimalistic bazel repo (https://github.com/VhalPurohit/gazelle-go-bug/tree/master) for a single main.go file that imports `"cloud.google.com/go/storage"`
its build rule has `deps = ["@com_google_cloud_go//storage"]` with a directive `# gazelle:resolve go google.golang.org/genproto/googleapis/iam/v1 @org_golang_google_genproto//googleapis/iam/v1
` and the build has a `go_repository` rule defined as such
```
go_repository(
name = "com_google_cloud_go",
build_file_proto_mode = "disable_global",
build_directives = [
"gazelle:resolve go google.golang.org/genproto/googleapis/iam/v1 @org_golang_google_genproto//googleapis/iam/v1", # keep
],
importpath = "cloud.google.com/go",
strip_prefix = "google-cloud-go-storage-v1.36.0",
build_file_generation = "on",
urls = ["https://github.com/googleapis/google-cloud-go/archive/storage/v1.36.0.zip"],
)
```
this repository rule by itself doesn't work so I kept adding go_repositories that `@com_google_cloud_go` depends on unitl the missing strict dependencies error that I couldn't get around
### What did you expect to see?
`bazel build t2:main` succeeds (there are explicit gazelle resolve directives both in the go_repository rule and the BUILD file to prevent the missing strict deps error)
### What did you see instead?
❯ bazel build t2:main
Starting local Bazel server and connecting to it...
DEBUG: /home/bazel/.cache/bazel/_bazel_bazel/fd6cc03cf1b89c041f6c1d0c8a59d607/external/io_bazel_rules_go/go/private/actions/link.bzl:58:18: Multiple copies of github.com/googleapis/gax-go/v2 passed to the linker. Ignoring bazel-out/k8-fastbuild/bin/external/com_github_googleapis_gax_go_v2/gax-go.a in favor of bazel-out/k8-fastbuild/bin/external/com_github_googleapis_gax_go/v2/gax-go.a
INFO: Analyzed target //t2:main (267 packages loaded, 11758 targets configured).
INFO: Found 1 target...
ERROR: /home/bazel/.cache/bazel/_bazel_bazel/fd6cc03cf1b89c041f6c1d0c8a59d607/external/com_google_cloud_go/iam/BUILD.bazel:3:11: GoCompilePkg external/com_google_cloud_go/iam/iam.a failed: (Exit 1): builder failed: error executing command (from target @com_google_cloud_go//iam:iam) bazel-out/k8-opt-exec-2B5CBBC6/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/com_google_cloud_go/iam/iam.go -embedroot '' -embedroot ... (remaining 25 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
**compilepkg: missing strict dependencies:
/home/bazel/.cache/bazel/_bazel_bazel/fd6cc03cf1b89c041f6c1d0c8a59d607/sandbox/linux-sandbox/426/execroot/__main__/external/com_google_cloud_go/iam/iam.go: import of "google.golang.org/genproto/googleapis/iam/v1"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.**
Target //t2:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 115.067s, Critical Path: 61.41s
INFO: 445 processes: 21 internal, 424 linux-sandbox.
FAILED: Build did NOT complete successfully
### Comments
The import that causes the failing strict dep is a protobuf import `pb "google.golang.org/genproto/googleapis/iam/v1"
` in com_google_cloud_go/iam/iam.go ; so I tried the `go_repository` rule with all of
1. `build_file_proto_mode = "disable_global"`
2. `build_file_proto_mode = "disable"`
3. `build_file_proto_mode = "default"`
4. removing the `build_file_proto_mode` attribute altogether.
But all of them lead to the same error.
It seems like the build directives are not working, but I don't really know what's going on to be fully honest. Please help.
Contributor guide
Research direction
Start with the linked minimal repository, its main.go, the generated external/com_google_cloud_go/iam/BUILD.bazel, and the go_repository build_directives. Run bazel build t2:main and inspect how the gazelle:resolve directive is applied to the google.golang.org/genproto/googleapis/iam/v1 import. Done means the strict-dependencies error is resolved without adding unsupported repository declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100