no go_sdk from a go_sdk.from_file set up
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)
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?
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.
@jmhodges Would you be willing to add this target along the lines of @rules_go//go?
@fmeum can do!
(I've been working on this, but have been blocked by #4499)