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

FR: Gazelle should import direct dependencies directly without requiring buildozer #1749

Open
vicentsegui opened this issue Mar 6, 2024 · 4 comments · May be fixed by bazelbuild/rules_go#3927

Comments

@vicentsegui
Copy link

What version of gazelle are you using?

0.35.0

What version of rules_go are you using?

0.46.0

What version of Bazel are you using?

7.0.2

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

Yes

What operating system and processor architecture are you using?

Macos

What did you do?

When using bzlmod support and go_deps being read from go.mod users still need to add manually direct dependencies to the use_repo rule. When running gazelle it will warn us when those are out of sync and give us a buildozer command to update it.

What did you expect to see?

Gazelle should be able to add this without users having to run the buildozer command. Alternatively rules_go should be able to add the direct dependencies as determined by go.mod without user intervention.

What did you see instead?

I have to run 3 commands to get everything to work:

go get $random_module # get the go module
bazel run //:gazelle  # adds dependency in BUILD file
buildozer 'use_repo_add @gazelle//:extensions.bzl $random_module' //MODULE.bazel:all  # adds the repo

With my proposal we could limit it to 2:

go get $random_module # get the go module
bazel run //:gazelle # adds dependency in BUILD file and repo in MODULE.bazel
@mkmik
Copy link

mkmik commented Mar 27, 2024

I minor improvement comes with bazel 7.1's bazel mod tidy command.

But yes, ideally the user shouldn't have to do anything manually besides running gazelle

@fmeum
Copy link
Collaborator

fmeum commented Mar 27, 2024

We'll integrate bazel mod tidy into @rules_go//go. You then only need to run bazel run @rules_go//go get ... to add a dependency (plus Gazelle). The @rules_go//go binary also does this when invoked directly, so you can wire this up with your IDE or shell aliases.

@vicentsegui
Copy link
Author

Quick question would this also work with bazel run @rules_go//go mod tidy? I tend to use that command instead of go get most of the time.

@fmeum
Copy link
Collaborator

fmeum commented Apr 2, 2024

Quick question would this also work with bazel run @rules_go//go mod tidy? I tend to use that command instead of go get most of the time.

Yes, we'll watch for any changes to your go.mod instead of checking which command you ran.

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

Successfully merging a pull request may close this issue.

3 participants