Skip to content

Commit ced414a

Browse files
authored
go_repository_cache: set GOTOOLCHAIN to 'local' (#1859)
**What type of PR is this?** Bug fix **What package or component does this PR mostly affect?** go_repository_cache **What does this PR do? Why is it needed?** Override the **GOTOOLCHAIN** local environment parameter defined by `go env -w` to use the local Go environment made available by `gazelle`. **Which issues(s) does this PR fix?** Fixes #1858 **Other notes for review** Same fix than bazel-contrib/rules_go#3660 in [rules_go](https://github.com/bazelbuild/rules_go).
1 parent f2f9f4f commit ced414a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/go_repository_cache.bzl

+11-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def _go_repository_cache_impl(ctx):
5959
cache_env = {
6060
"GOROOT": go_root,
6161
"GOCACHE": go_cache,
62+
63+
# Since Go v1.21.0, set GOTOOLCHAIN to "local" to use the current toolchain
64+
# of the Go SDK. This is required to avoid `go mod download` commands
65+
# download and use another Go toolchain according to the user’s environment
66+
# default file (GOENV, managed by `go env -w` and `go env -u`).
67+
#
68+
# See https://go.dev/doc/toolchain for more info.
69+
#
70+
# TODO(#1858): Find a way to retrieve this value when the host's Go SDK is used and avoid to override it.
71+
"GOTOOLCHAIN": "local",
6272
}
6373
if go_path:
6474
cache_env["GOPATH"] = go_path
@@ -140,7 +150,7 @@ def _detect_host_platform(ctx):
140150
uname = res.stdout.strip()
141151
if uname == "arm64":
142152
host = "darwin_arm64"
143-
153+
144154
elif ctx.os.name.startswith("windows"):
145155
host = "windows_amd64"
146156
elif ctx.os.name == "freebsd":

0 commit comments

Comments
 (0)