rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

no go_sdk from a go_sdk.from_file set up

Open jmhodges opened this issue 1 month ago • 5 comments

This is on bazel 8.4.2 and rules_go 0.58.3.

I've previously had a go_sdk.download call and a use_repo(go_sdk, "go_sdk") in my MODULE.bazel to provide a target for aspect_rules_lint's format_multirun to have a gofmt (that is, go = "@go_sdk//:bin/gofmt",). This has worked fine.

But when I change the go_sdk.download to a go_sdk.from_file(go_mod = "//:go.mod)", the line use_repo(go_sdk, "go_sdk") errors with:

ERROR: module extension @@rules_go+//go:extensions.bzl%go_sdk does not generate repository "go_sdk", yet it is imported as "go_sdk" in the usage at /Users/jmhodges/founding/src/founding/MODULE.bazel:34:23

I suspect this wasn't intentioned. Perhaps, I'm not getting a gofmt in the correct way, of course. But the error is from way before the call to format_multirun.

(I could also be convinced that go_sdk.from_file isn't as useful as go_deps.from_file)

jmhodges avatar Oct 31 '25 05:10 jmhodges

This is expected, we are moving away from explicitly named SDK repos in favor of toolchain resolution and Bzlmod was a convenient opportunity for that.

Can you use go fmt instead of gofmt? You can easily run the former via @rules_go//go. If that's not sufficient, we should add @rules_go//go:gofmt or @rules_go//gofmt as a supported replacement.

@jayconrod Do you know whether there is a way to run something equivalent to gofmt via go?

fmeum avatar Oct 31 '25 06:10 fmeum

There's not. I'm not sure why but gofmt was always shipped in $GOROOT/bin rather than $GOROOT/pkg/tool, so it can only be invoked by itself, not by go tool.

Adding @rules_go//gofmt sounds good.

jayconrod avatar Oct 31 '25 14:10 jayconrod

@jmhodges Would you be willing to add this target along the lines of @rules_go//go?

fmeum avatar Oct 31 '25 16:10 fmeum

@fmeum can do!

jmhodges avatar Oct 31 '25 17:10 jmhodges

(I've been working on this, but have been blocked by #4499)

jmhodges avatar Nov 04 '25 01:11 jmhodges