bazel-gazelle: Cannot compile //:gazelle when using version 0.25.0
What version of gazelle are you using?
0.25.0
What version of rules_go are you using?
0.31.0
What version of Bazel are you using?
5.0.0
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
Linux, amd64
What did you do?
+$ cat BUILD
load("@bazel_gazelle//:def.bzl", "gazelle")
gazelle(name = "gazelle")
+$ cat WORKSPACE
workspace(name = "foobar")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
maybe(
http_archive,
name = "io_bazel_rules_go",
urls = [
"https://github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
],
sha256 = "f2dcd210c7095febe54b804bb1cd3a58fe8435a909db2ec04e31542631cf715c",
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
maybe(
http_archive,
name = "bazel_gazelle",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.25.0/bazel-gazelle-v0.25.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.25.0/bazel-gazelle-v0.25.0.tar.gz",
],
sha256 = "5982e5463f171da99e3bdaeff8c0f48283a7a5f396ec5282910b9e8a49c0dd7e",
)
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
############################################################
# Define your own dependencies here using go_repository.
# Else, dependencies declared by rules_go/gazelle will be used.
# The first declaration of an external repository "wins".
############################################################
go_rules_dependencies()
go_register_toolchains(version = "1.18")
gazelle_dependencies()
+$ bazel build --verbose_failures //:gazelle
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:gazelle (81 packages loaded, 8685 targets configured).
INFO: Found 1 target...
ERROR: /home/wolf/.cache/bazel/_bazel_wolf/6dd1b1f68dde97d4c1e29873f38ce7a7/external/org_golang_x_mod/module/BUILD.bazel:3:11: GoCompilePkg external/org_golang_x_mod/module/module.a [for host] failed: (Exit 1): builder failed: error executing command
(cd /home/wolf/.cache/bazel/_bazel_wolf/6dd1b1f68dde97d4c1e29873f38ce7a7/sandbox/linux-sandbox/17/execroot/foobar && \
exec env - \
CGO_ENABLED=1 \
GOARCH=amd64 \
GOOS=linux \
GOPATH='' \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=/usr/bin:/bin \
bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/org_golang_x_mod/module/module.go -src external/org_golang_x_mod/module/pseudo.go -arc 'golang.org/x/mod/internal/lazyregexp=golang.org/x/mod/internal/lazyregexp=bazel-out/host/bin/external/org_golang_x_mod/internal/lazyregexp/lazyregexp.x' -arc 'golang.org/x/mod/semver=golang.org/x/mod/semver=bazel-out/host/bin/external/org_golang_x_mod/semver/semver.x' -importpath golang.org/x/mod/module -p golang.org/x/mod/module -package_list bazel-out/host/bin/external/go_sdk/packages.txt -o bazel-out/host/bin/external/org_golang_x_mod/module/module.a -x bazel-out/host/bin/external/org_golang_x_mod/module/module.x -gcflags '' -asmflags '')
# Configuration: ad7becf1f627c98f4c44ac49f5991ab41aa98662628ab4c26b029d7fb1035392
# Execution platform: @local_config_platform//:host
Use --sandbox_debug to see verbose messages from the sandbox
compilepkg: missing strict dependencies:
/home/wolf/.cache/bazel/_bazel_wolf/6dd1b1f68dde97d4c1e29873f38ce7a7/sandbox/linux-sandbox/17/execroot/foobar/external/org_golang_x_mod/module/module.go: import of "golang.org/x/xerrors"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
Target //:gazelle failed to build
INFO: Elapsed time: 68.110s, Critical Path: 1.56s
INFO: 32 processes: 18 internal, 14 linux-sandbox.
FAILED: Build did NOT complete successfully
What did you expect to see?
The build to succeed.
What did you see instead?
The build failed.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 14
- Comments: 19 (6 by maintainers)
Commits related to this issue
- deps: Updated rules_gazelle to 0.25.0 This also required marking golang.org/x/mod as needing to use external dependency resolution for some reason. See bazelbuild/bazel-gazelle#1217 Signed-off-by: S... — committed to ProjectSerenity/firefly by SlyMarbo 2 years ago
- Rollback gazelle due to dependency resolution failures: https://github.com/bazelbuild/bazel-gazelle/issues/1217 — committed to rules-proto-grpc/rules_proto_grpc by aaliddell 2 years ago
- go_repository: set build_external default to external Previously in 9c475138e6c118b55309a55dbf28de77bcf77621 we introduce the new static dep resolution mode to improve performance of gazelle when run... — committed to sluongng/bazel-gazelle by sluongng 2 years ago
- Adding WORKSPACE and BUILD to generate all BUILD.bazel for this project with bazel_gazelle. 由于 rules_go-v0.33.0 not works well with gazelle v0.25.0, see the issue: https://github.com/bazelbuild/bazel... — committed to qiaoliang/shop-online-go by qiaoliang 2 years ago
- update README.rst install instructions to 0.26 This is especially useful as I ran into https://github.com/bazelbuild/bazel-gazelle/issues/1217 from using the 0.25 version of this README. — committed to jmhodges/bazel-gazelle by jmhodges 2 years ago
- Fix the new static dependency resolution mode https://github.com/bazelbuild/bazel-gazelle/issues/1217#issuecomment-1082074061 — committed to jankremlacek/go-bazel by jankremlacek 2 years ago
- set build mode to external for all deps Consult the following resources for more information: - https://github.com/bazelbuild/bazel-gazelle/issues/1217 - https://github.com/bazelbuild/bazel-gazelle/... — committed to malt3/bazeldnf by malt3 a year ago
- set build mode to external for all deps Consult the following resources for more information: - https://github.com/bazelbuild/bazel-gazelle/issues/1217 - https://github.com/bazelbuild/bazel-gazelle/... — committed to malt3/bazeldnf by malt3 a year ago
- set build mode to external for all deps Consult the following resources for more information: - https://github.com/bazelbuild/bazel-gazelle/issues/1217 - https://github.com/bazelbuild/bazel-gazelle/... — committed to malt3/bazeldnf by malt3 a year ago
- set build mode to external for all deps Consult the following resources for more information: - https://github.com/bazelbuild/bazel-gazelle/issues/1217 - https://github.com/bazelbuild/bazel-gazelle/... — committed to malt3/bazeldnf by malt3 a year ago
Edit: After some more messing around, I found that placing this in my
WORKSPACE
was sufficient to fix the problemThis seems to be related to the new static dependency resolution mode (9c47513). I had success applying this patch to Gazelle:
Without the patch (i.e. using static dependency resolution mode), the generated
@org_golang_x_mod//module:module
target is missing the@org_golang_x_xerrors//:go_default_library
dependency which causes the “missing strict dependencies” error.Using rules_go v0.34.0 and gazelle v0.26.0, I get these errors when my
go_repository()
calls are in a macro, but not when the same calls are in the WORKSPACE. Should I file a new issue about this?To expand on @nickgooding’s comment, if you use gazelle from within bazel, then putting the following in the
WORKSPACE
file worked for me:I still get some issues with dependency resolve of
org_golang_x_tools
.Adding this to WORKSPACE file manually tell gazelle how to resolve the dependency which works as a lightweighted workaround in some cases.
These deps are being loaded into WORKSPACE from a macro in a separate file, so I wonder if that affected the static resolution somehow?
The latest version of
rules_go
andbazel-gazelle
works out of the boxI tested it in my repo yesterday and I was able to build everything without build_external, so I think you are right that new rules_go version might have fixed this. https://github.com/sluongng/nogo-analyzer/commit/21610b27d2d0219610e43b0d8bbaa263786f438d
However, i think that
org_golang_x_xerrors
andorg_golang_x_mod
are very common dependencies in all projects and thus can be easily overriden inside several WORKSPACE macro calls. User can troubleshoot this by doing this query.Thank you @nickgooding
Your solution works. I just took this diff and applied it with
patch_args = ["-p1"],
. Now my project works!Actually for us it also doesn’t really work. The workaround only partially helped but then with clean cache builds fail.
Seems manually adding the xerrors dependency helps:
This seems to be explicitly overriding the version that would otherwise come from
rules_go
.