bazel-gazelle
bazel-gazelle copied to clipboard
Gazelle cannot be built if GOFLAGS="-mod=vendor" is set with go env command
What version of gazelle are you using?
v0.24.0
What version of rules_go are you using?
v0.29.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?
MacOS amd64 and Linux amd64
What did you do?
go env -w GOFLAGS="-mod=vendor" && bazel clean --expunge && bazel build //:gazelle
What did you expect to see?
INFO: Starting clean.
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:gazelle (63 packages loaded, 7899 targets configured).
INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
INFO: Elapsed time: 110,069s, Critical Path: 25,59s
INFO: 55 processes: 13 internal, 42 local.
INFO: Build completed successfully, 55 total action
What did you see instead?
INFO: Starting clean.
Starting local Bazel server and connecting to it...
DEBUG: /private/var/tmp/_bazel_igor.kokhanevych/8b3a107e11aa28daf3fab2eea596be9c/external/bazel_gazelle/internal/go_repository.bzl:209:18: com_github_bmatcuk_doublestar: gazelle: finding module path for import github.com/bmatcuk/doublestar/v2: finding module path for import github.com/bmatcuk/doublestar/v2: go: inconsistent vendoring in /private/var/folders/dj/8v0980sn5cz237w0v_nf0pwjp53c15/T/gazelle-remotecache-4260108464:
github.com/bmatcuk/doublestar/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
To ignore the vendor directory, use -mod=readonly or -mod=mod.
To sync the vendor directory, run:
go mod vendor
DEBUG: /private/var/tmp/_bazel_igor.kokhanevych/8b3a107e11aa28daf3fab2eea596be9c/external/bazel_gazelle/internal/go_repository.bzl:209:18: org_golang_x_mod: gazelle: finding module path for import golang.org/x/xerrors: finding module path for import golang.org/x/xerrors: go: inconsistent vendoring in /private/var/folders/dj/8v0980sn5cz237w0v_nf0pwjp53c15/T/gazelle-remotecache-543518972:
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
To ignore the vendor directory, use -mod=readonly or -mod=mod.
To sync the vendor directory, run:
go mod vendor
gazelle: finding module path for import golang.org/x/crypto/ed25519: finding module path for import golang.org/x/crypto/ed25519: go: inconsistent vendoring in /private/var/folders/dj/8v0980sn5cz237w0v_nf0pwjp53c15/T/gazelle-remotecache-543518972:
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
To ignore the vendor directory, use -mod=readonly or -mod=mod.
To sync the vendor directory, run:
go mod vendor
gazelle: finding module path for import golang.org/x/crypto/ed25519: finding module path for import golang.org/x/crypto/ed25519: go: inconsistent vendoring in /private/var/folders/dj/8v0980sn5cz237w0v_nf0pwjp53c15/T/gazelle-remotecache-543518972:
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
To ignore the vendor directory, use -mod=readonly or -mod=mod.
To sync the vendor directory, run:
go mod vendor
gazelle: finding module path for import golang.org/x/tools/txtar: finding module path for import golang.org/x/tools/txtar: go: inconsistent vendoring in /private/var/folders/dj/8v0980sn5cz237w0v_nf0pwjp53c15/T/gazelle-remotecache-543518972:
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
golang.org/x/[email protected]: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
To ignore the vendor directory, use -mod=readonly or -mod=mod.
To sync the vendor directory, run:
go mod vendor
INFO: Analyzed target //:gazelle (61 packages loaded, 7888 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_igor.kokhanevych/8b3a107e11aa28daf3fab2eea596be9c/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 bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src external/org_golang_x_mod/module/module.go -src external/org_golang_x_mod/module/pseudo.go ... (remaining 18 argument(s) skipped)
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel_igor.kokhanevych/8b3a107e11aa28daf3fab2eea596be9c/execroot/__main__/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
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 86,271s, Critical Path: 2,60s
INFO: 30 processes: 17 internal, 13 local.
FAILED: Build did NOT complete successfully
Passing to gazelle_dependencies
go_env = {"GOFLAGS": "-mod=readonly"}
is a workaround for the issue.
Interesting.. Is there an issue to solve here?
I suppose we could explicitly pass in -mod=readonly
when Gazelle runs go list
here: https://github.com/bazelbuild/bazel-gazelle/blob/master/repo/remote.go#L430.
Although mod=readonly
is set by default for go list
, I assume GOFLAGS
overrides that behavior.
I just ran into this today. Not necessary the GOFLAGS related bug, but rather this weird message
...external/org_golang_x_mod/module/module.go: import of "golang.org/x/xerrors"
No dependencies were provided.
Closer inspection showed that @org_golang_x_mod//module/
has the wrong go_library generated, missing golang.org/x/xerrors
as a dependency.
This happened on Gazelle latest release (0.24.0) as well as latest commit on master. Reverting to 0.23.0 and the issue gone away.
I created a minimal reproducible repo here https://github.com/sluongng/gazelle-x-mod-issue/blob/master/WORKSPACE#L12-L20. This includes latest commit in both rules_go and gazelle running with Bazel 5.0.
Trying to build //:gazelle
yielded that exact same bug.
Downgrading gazelle back to 0.23.0 and issue is gone.
# http_archive(
# name = "bazel_gazelle",
# sha256 = "e9c02f13706e8b1ef05b57e6ae4d59910643bebac6d4e82581aa8c75fce6998b",
# strip_prefix = "bazel-gazelle-e21487a75fffa5616846e3c69de16f65c8953bad",
# urls = [
# "https://github.com/bazelbuild/bazel-gazelle/archive/e21487a75fffa5616846e3c69de16f65c8953bad.tar.gz",
# "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/archive/e21487a75fffa5616846e3c69de16f65c8953bad.tar.gz",
# ],
# )
http_archive(
name = "bazel_gazelle",
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
],
)
There must be a regression somewhere between v0.23 and v0.24 (or latest master)
@sluongng can confirm the issue; downgrading helped on my end as well but is not the final solution
Confirmed this is still an issue with Gazelle v0.25.0. I cannot downgrade to Gazelle v0.23.0 because of https://github.com/bazelbuild/rules_go/issues/3070, which was fixed with v0.25.0
Fresh run of bazel/Gazelle on a new project:
› bazel run //:gazelle
INFO: Analyzed target //:gazelle (84 packages loaded, 8856 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_jleroux/932fa52e3159dbc26fbdbafc99bc0e34/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 bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_arm64 -src external/org_golang_x_mod/module/module.go -src external/org_golang_x_mod/module/pseudo.go ... (remaining 24 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel_jleroux/932fa52e3159dbc26fbdbafc99bc0e34/sandbox/darwin-sandbox/15/execroot/__main__/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
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 39.101s, Critical Path: 1.50s
INFO: 33 processes: 21 internal, 12 darwin-sandbox.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
Fixed by downgrading to v0.23
We faced this issue as well. Upgrading to gazelle 0.26.0 seems to fix it.