bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 656 forks source link

Is there any way to automatically generate the deps in the BUILD.bazel file? #4006

Closed liushuai05 closed 2 months ago

liushuai05 commented 2 months ago

What version of rules_go are you using?

0.48.0

What version of gazelle are you using?

0.37.0

What version of Bazel are you using?

7.2.1

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

yes

What operating system and processor architecture are you using?

manjaro 24 x86-64

Any other potentially useful information about your toolchain?

Nothing

What did you do?

1.I introduced a dependency in lib such as "github.com/redis/go-redis/v9" 2.Then I executed bazel run//:gazelle-update-repos to successfully update the dependency file deps.bzl, and then I executed bazel run //:xxx to compile bin, and I got an error. 3.

What did you expect to see?

I hope it compiles normally. I have to manually update the deps in BUILD.bazel under the lib package and add a line "@ com github redis go redis _ v 9//:go-redis" to compile normally, but many of my projects have not used bazel before and want to migrate to bazel mutation. This is undoubtedly a big project, and I have tried to find a solution, but it seems that there is no progress.

What did you see instead?

$ bazel run hello
INFO: Analyzed target //:hello (99 packages loaded, 10499 targets configured).
ERROR: /xxx/bazel_go_test/lib/BUILD.bazel:3:11: GoCompilePkg lib/lib.a failed: (Exit 1): builder failed: error executing GoCompilePkg command (from target //lib:lib) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src lib/lib.go -embedroot '' -embedroot ... (remaining 17 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
        /xxx/333b9a668e98faeb0db1e492ecfd95a4/sandbox/linux-sandbox/78/execroot/_main/lib/lib.go: import of "github.com/redis/go-redis/v9"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
Target //:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 26.055s, Critical Path: 20.64s
INFO: 9 processes: 7 internal, 2 linux-sandbox.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
fmeum commented 2 months ago

The recommended way to use rules_go is via Bzlmod/MODULE.bazel. See our docs on how to manage external dependencies in a way that reuses the information in go.mod and makes it unnecessary to run update-repos.

Let me know if anything is missing to realize a good workflow for your project.