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

Circular dependency between newer golang.org/x/tools and rules_go #2910

Closed
oakad opened this issue Jul 2, 2021 · 13 comments
Closed

Circular dependency between newer golang.org/x/tools and rules_go #2910

oakad opened this issue Jul 2, 2021 · 13 comments
Assignees

Comments

@oakad
Copy link

oakad commented Jul 2, 2021

I was happily building my project with bazel for months until suddenly this happened:

ERROR: .../external/io_bazel_rules_nogo/BUILD.bazel:3:6: in alias rule @io_bazel_rules_nogo//:nogo: cycle in dependency graph:
//some/targets
@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/internal/facts:go_tool_library
| @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
`-- @io_bazel_rules_nogo//:nogo
ERROR: Analysis of target '//some/targer' failed; build aborted

The build was in good health until I needed to upgrade some packages (presumably pulling a newer version of golang.org/x/tools).

Building with plain go build works just fine, as before.

@oakad
Copy link
Author

oakad commented Jul 2, 2021

Using some bisection, I established that golang.org/x/tools@v0.1.2 works, but v0.1.3 and v0.1.4 result in breakage, as reported.

@oakad oakad changed the title Sudden, non obvious breakage caused by nogo rules Circular dependency between newer golang.org/x/tools and rules_go Jul 5, 2021
@asv
Copy link

asv commented Jul 9, 2021

still reproduced in rules_go 0.28.0

@tanyabouman
Copy link
Contributor

I reproduced the same problem, and that it happens between golang.org/x/tools@v0.1.2 and v0.1.3

This is what the dependencies used to look like with v0.1.2, and there's no cycle.

$ bazel query "allpaths(@org_golang_x_tools//internal/typeparams:typeparams,@org_golang_x_tools//go/ast/astutil:go_tool_library)"

@org_golang_x_tools//internal/typeparams:typeparams
@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/internal/facts:go_tool_library
@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

@tanyabouman
Copy link
Contributor

Are you using Gazelle? I think the dependency problem might have been fixed in bazel-contrib/bazel-gazelle#1074. The fix is not in a release yet, but I was able to work around the problem by using this in my WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "bazel_gazelle",
    remote = "https://github.com/bazelbuild/bazel-gazelle",
    commit = "9f72eed9f79bfc18a04e8ac6204751998c7cba4a",
    shallow_since = "1625010873 -0600",
)

@oakad
Copy link
Author

oakad commented Jul 16, 2021

I, personally, do not always use gazelle. Sometimes I find it more convenient to write the BUILD file manually and add the necessary go_repository rules.

There are few popular packages around go ecosystem that require manual tweaking of go_repository flags to build. It will be handy if somebody could advice on a good option to pass to x/tools go_repository rule to make it build.

@tanyabouman
Copy link
Contributor

Right, if you're using go_repository, that comes from Gazelle, so as far as I know, Gazelle is loaded in your project somewhere.

Alternatively, I suppose you could work around the problem by keeping x/tools at an older version.

    go_repository(
        name = "org_golang_x_tools",
        importpath = "golang.org/x/tools",
        sum = "h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=",
        version = "v0.1.2",
    )

@oakad
Copy link
Author

oakad commented Jul 17, 2021

That's what my bug report says. :-)

@robfig robfig self-assigned this Sep 23, 2021
@robfig
Copy link
Contributor

robfig commented Sep 24, 2021

Now that we merged #2922 , the cycle due to nogo should be resolved. Can you try using rules_go at HEAD and see if that fixes your problem? Thanks

@oakad
Copy link
Author

oakad commented Sep 27, 2021

The below works, but somebody should make a proper Gazelle release.

http_archive(
        name = "io_bazel_rules_go",
        sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
        urls = [
                "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
                "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
        ],
)

http_archive(
        name = "bazel_gazelle",
        sha256 = "86a5fcfb73f443d9cbf8d387f689a0f545200ca1ba294234e3ef866c50a4c2c2",
        strip_prefix = "bazel-gazelle-b1e37463c2ef0997c5cf0e90cdf03e696caaed27",
        urls = [
                "https://github.com/bazelbuild/bazel-gazelle/archive/b1e37463c2ef0997c5cf0e90cdf03e696caaed27.zip",
        ],
)

@c16a
Copy link
Contributor

c16a commented Oct 14, 2021

I'm guessing this still doesn't work? I had to switch to an older org_golang_x_tools version as a fix for now.

@robfig
Copy link
Contributor

robfig commented Oct 14, 2021

I believe it works with the latest release of Gazelle/rules_go. Please let me know if not. Here's the latest WORKSPACE boilerplate.

https://github.com/bazelbuild/bazel-gazelle/#running-gazelle-with-bazel

@c16a
Copy link
Contributor

c16a commented Oct 14, 2021

Thanks @robfig - confirmed that this is fixed with latest rules_go and gazelle.

@robfig
Copy link
Contributor

robfig commented Oct 14, 2021

Thanks for confirming. Closing

@robfig robfig closed this as completed Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants