Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cycle dependency in nogo and go_context_data #2479

Closed
linzhp opened this issue May 7, 2020 · 6 comments
Closed

cycle dependency in nogo and go_context_data #2479

linzhp opened this issue May 7, 2020 · 6 comments

Comments

@linzhp
Copy link
Contributor

linzhp commented May 7, 2020

What version of rules_go are you using?

745de50

What version of gazelle are you using?

7e93b118efcdfe63f43057a88711762e0b5d7267

What version of Bazel are you using?

3.0.0

Does this issue reproduce with the latest releases of all the above?

yes

What operating system and processor architecture are you using?

Darwin amd 64

What did you do?

git clone git@github.com:linzhp/bazel_examples.git
cd bazel_examples
git checkout 510e7a2798ab0f3e9cf2b93b06a28a92dad539fd
bazel build //:gazelle

What did you expect to see?

Build completed successfully

What did you see instead?

ERROR: /private/var/tmp/_bazel_zplin/1b23f78923ad6c0028e8aab1a0a6d5fb/external/io_bazel_rules_go/BUILD.bazel:71:1: in go_context_data rule @io_bazel_rules_go//:go_context_data: cycle in dependency graph:
    //:gazelle
    //:gazelle-runner
    @bazel_gazelle//cmd/gazelle:gazelle (host)
.-> @io_bazel_rules_go//:go_context_data (host)
|   @io_bazel_rules_go//:nogo_alias (host)
|   @io_bazel_rules_go//go/config:nogo (host)
|   @io_bazel_rules_nogo//:nogo (host)
|   //:default_nogo (host)
`-- @io_bazel_rules_go//:go_context_data (host)
This cycle occurred because of a configuration option
ERROR: Analysis of target '//:gazelle' failed; build aborted
INFO: Elapsed time: 2.653s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (71 packages loaded, 7044 targets configured)
@jayconrod
Copy link
Contributor

Thanks for reporting. It looks like my workaround for bazelbuild/bazel#11291 won't work.

I'll roll back #2374 and #2374. Which is very disappointing. I was really looking forward to getting rid of go_tool_library.

jayconrod pushed a commit that referenced this issue May 8, 2020
This rolls back #2473 and #2474 due to #2479, which is caused by bazelbuild/bazel#11291. There doesn't seem to be a way to work around that, and I don't want to hold the release back any longer.

Reopens #2374
Reopens #2470
@rickystewart
Copy link
Contributor

We've stumbled across an instance of this bug which, for some reason, seems to manifest when we upgrade golang.org/x/tools. This is the original PR that uncovered the issue, but I've pushed a minimal repro (latest versions of gazelle/rules_go/bazel) to the gazelle_circular branch here -- bazel build :gazelle to repro. Updating these dependencies causes Gazelle, and apparently any go_binary, to fail to build with the cyclic dependency through @io_bazel_rules_go//:go_context_data above. The error isn't stable, but it looks something like this:

ERROR: /private/var/tmp/_bazel_ricky/b12fe6cd3e6e067332cc17cd9865b32d/external/io_bazel_rules_go/BUILD.bazel:73:16: in go_context_data rule @io_bazel_rules_go//:go_context_data: cycle in dependency graph:
    //:gazelle
    //:gazelle-runner
    @bazel_gazelle//cmd/gazelle:gazelle
    @bazel_gazelle//cmd/gazelle:gazelle_lib
    @bazel_gazelle//language:language
    @bazel_gazelle//resolve:resolve
    @bazel_gazelle//label:label
.-> @io_bazel_rules_go//:go_context_data
|   @io_bazel_rules_nogo//:nogo
|   @io_bazel_rules_go//:default_nogo
|   @io_bazel_rules_go//go/tools/builders:nogo_srcs
|   @org_golang_x_tools//go/analysis:go_tool_library
|   @org_golang_x_tools//internal/analysisinternal:go_tool_library
|   @org_golang_x_tools//go/ast/astutil:go_tool_library
|   @org_golang_x_tools//internal/typeparams:typeparams
`-- @io_bazel_rules_go//:go_context_data

I've also confirmed that using a lower version of x/tools fixes the issue and allows bazel build :gazelle to succeed (apply the following patch to my repro to demonstrate):

diff --git a/WORKSPACE b/WORKSPACE
index bf53938..a27b7e8 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -30,8 +30,8 @@ go_repository(
     name = "org_golang_x_tools",
     build_file_proto_mode = "disable_global",
     importpath = "golang.org/x/tools",
-    sum = "h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8=",
-    version = "v0.1.3",
+    sum = "h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=",
+    version = "v0.1.2",
 )
 
 go_repository(

Since this reliably breaks Gazelle, the dependency update is blocked. I haven't been able to find a workaround -- any guidance y'all have would be very helpful.

@nazufel
Copy link

nazufel commented Jun 29, 2021

This issue is affecting me as well.

@tarrencev
Copy link

Running into this issue too. Applying the x/tools downgrade does avoid the issue but is not really viable

knz added a commit to cockroachdb/buf that referenced this issue Jul 5, 2021
Note: this commit should not necessary as this has been
suitably fixed on the 'master' branch already.
However, the fixes are only available in 0.43.3 or later
and CockroachDB cannot upgrade to that version because of
cockroachdb/cockroach#67221 (comment)
and
bazel-contrib/rules_go#2479

So we're using this backport fix instead until that
other dependency management issue is resolved.
knz added a commit to cockroachdb/buf that referenced this issue Jul 6, 2021
Note: this commit should not necessary as this has been
suitably fixed on the 'master' branch already.
However, the fixes are only available in 0.43.3 or later
and CockroachDB cannot upgrade to that version because of
cockroachdb/cockroach#67221 (comment)
and
bazel-contrib/rules_go#2479

So we're using this backport fix instead until that
other dependency management issue is resolved.
rickystewart added a commit to rickystewart/cockroach that referenced this issue Jul 15, 2021
This helps to avoid bazel-contrib/rules_go#2479.

Release note: None
craig bot pushed a commit to cockroachdb/cockroach that referenced this issue Jul 15, 2021
67489: clisqlclient: trim down dependencies r=otan a=knz

Fixes #67482.
Informs  #67470.


67669: bazel: upgrade gazelle to latest r=rail a=rickystewart

This helps to avoid bazel-contrib/rules_go#2479.

Release note: None

Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
Co-authored-by: Ricky Stewart <ricky@cockroachlabs.com>
pawalt pushed a commit to pawalt/cockroach that referenced this issue Jul 22, 2021
This helps to avoid bazel-contrib/rules_go#2479.

Release note: None
@NikBisht
Copy link

NikBisht commented Aug 3, 2021

Also experiencing this issue attempting to update golang.org/x/tools from v0.1.0 to v0.1.5

@dtbartle
Copy link

dtbartle commented Sep 3, 2021

Should be fixed by bazel-contrib/bazel-gazelle@9f72eed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants