bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.39k stars 664 forks source link

Fix `go_tool_binary` non-hermeticity and Go 1.19 incompatibility #4167

Closed fmeum closed 2 weeks ago

fmeum commented 2 weeks ago

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

go_tool_binary used to non-hermetically pick up rules_go's go.mod file when run unsandboxed, which resulted in it downloading a different toolchain and messing up version checks.

Also make nogo_main.go compatible with Go 1.19 and test with nogo (which requires fixing a bunch of violations).

Which issues(s) does this PR fix?

Fixes #

Other notes for review

zecke commented 2 weeks ago

Slightly related. Should the go.mod file be passed as dependency? For things like https://go.dev/blog/loopvar-preview the content of the go.mod file seems to determine the behavior.

From a rules_go users point of view. What is the capture behavior now when using Go 1.22+?

fmeum commented 2 weeks ago

From a rules_go users point of view. What is the capture behavior now when using Go 1.22+?

rules_go currently always uses the Go language version corresponding to the version of the Go SDK.

Slightly related. Should the go.mod file be passed as dependency? For things like https://go.dev/blog/loopvar-preview the content of the go.mod file seems to determine the behavior.

I started working on this in https://github.com/bazel-contrib/rules_go/pull/4106, but haven't gotten around to finalizing the PR. If anyone wants to take a stab at this, please do.