Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set GOTOOLCHAIN environment variable #1188

Closed
atc0005 opened this issue Sep 15, 2023 · 0 comments · Fixed by #1235
Closed

Explicitly set GOTOOLCHAIN environment variable #1188

atc0005 opened this issue Sep 15, 2023 · 0 comments · Fixed by #1235
Assignees
Labels
CI dependencies enhancement New feature or request
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Sep 15, 2023

Overview

In short, Go 1.21 and newer automatically download a newer Go toolchain when building code that has been explicitly marked as requiring a newer Go toolchain.

Overview from the official docs:

Starting in Go 1.21, the Go distribution consists of a go command and a bundled Go toolchain, which is the standard library as well as the compiler, assembler, and other tools. The go command can use its bundled Go toolchain as well as other versions that it finds in the local PATH or downloads as needed.

The choice of Go toolchain being used depends on the GOTOOLCHAIN environment setting and the go and toolchain lines in the main module’s go.mod file or the current workspace’s go.work file. As you move between different main modules and workspaces, the toolchain version being used can vary, just as module dependency versions do.

In the standard configuration, the go command uses its own bundled toolchain when that toolchain is at least as new as the go or toolchain lines in the main module or workspace. For example, when using the go command bundled with Go 1.21.3 in a main module that says go 1.21.0, the go command uses Go 1.21.3. When the go or toolchain line is newer than the bundled toolchain, the go command runs the newer toolchain instead. For example, when using the go command bundled with Go 1.21.3 in a main module that says go 1.21.9, the go command finds and runs Go 1.21.9 instead. It first looks in the PATH for a program named go1.21.9 and otherwise downloads and caches a copy of the Go 1.21.9 toolchain. This automatic toolchain switching can be disabled, but in that case, for more precise forwards compatibility, the go command will refuse to run in a main module or workspace in which the go line requires a newer version of Go. That is, the go line sets the minimum required Go version necessary to use a module or workspace.

The intent behind the images provided by this project are two fold:

  • build code using a specific Go release version for CI purposes
  • generate release assets using a specific Go release version

In both cases the very specific version of Go used is intentional. If I generate a project release after having tested against Go 1.21.1 I don't want to generate assets using Go 1.21.2 instead.

Likewise for CI use I want to fail the build fast if there is a hard version requirement that we're not meeting.

The official docs provide a way to set this expectation:

When GOTOOLCHAIN is set to local, the go command always runs the bundled Go toolchain.

To set user-specific expectation:

go env -w GOTOOLCHAIN=local

References

See also:

@atc0005 atc0005 added the enhancement New feature or request label Sep 15, 2023
@atc0005 atc0005 added this to the Next Release milestone Sep 15, 2023
@atc0005 atc0005 self-assigned this Sep 15, 2023
@atc0005 atc0005 modified the milestones: v0.13.9, v0.14.0 Sep 20, 2023
@atc0005 atc0005 modified the milestones: v0.13.11, v0.14.0 Oct 10, 2023
atc0005 added a commit that referenced this issue Oct 26, 2023
Set variable to `local` to disable automatic fetching of
Go toolchains newer than the version explicitly provided
by each container image.

refs GH-1188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI dependencies enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant