bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.37k stars 651 forks source link

How do I depend on the "bazel" package of rules_go when using MODULE.bazel #3940

Closed jjh42 closed 4 months ago

jjh42 commented 4 months ago

What version of rules_go are you using?

0.47.1

What version of gazelle are you using?

0.36.0

What version of Bazel are you using?

7.1.1

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

Yes

What operating system and processor architecture are you using?

Linux, amd64

What did you do?

In MODULE.bazel i have bazel_dep(name = "rules_go", version = "0.47.1")

and standard go setup.

I wanted to use the bazel go package to find runfiles.

https://pkg.go.dev/github.com/bazelbuild/rules_go/go/tools/bazel

To a go package I added deps = ["@rules_go//rules_go/go/tools/bazel"]

What did you expect to see?

Since the rules_go package is already being downloaded by bazel I expected my go code to compile with the bazel package available.

What did you see instead?

ERROR: no such package '@@rules_go~//rules_go/go/tools/bazel': BUILD file not found in directory 'rules_go/go/tools/bazel' of external repository @@rules_go~. Add a BUILD file to a directory to mark it as a package.

https://stackoverflow.com/questions/71120426/bazel-how-to-get-the-path-of-a-binary-that-i-built-along-a-bazel-test

I think this is due to using MODULES.bazel instead of the older style WORKSPACE with http_package.

fmeum commented 4 months ago

"@rules_go//go/tools/bazel" should work, try that instead. Do note that most functions in that package are deprecated though, @rules_go//go/runfiles is the replacement.

Feel free to reopen if you need anything else.

jjh42 commented 4 months ago

Thanks that worked. It would have been helpful for me to have an example on this. I could make a small PR with an example if there is an appropriate folder to put it?

fmeum commented 4 months ago

Are you using Gazelle? With it, your deps should have been updated automatically. That's why we don't really have examples for this situation (managing deps manually).