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

cmd/go: respect GOARCH setting with automatic toolchain downloads #66562

Closed
eskultety opened this issue Mar 27, 2024 · 4 comments
Closed

cmd/go: respect GOARCH setting with automatic toolchain downloads #66562

eskultety opened this issue Mar 27, 2024 · 4 comments
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@eskultety
Copy link

Go version

go version go1.21.4 linux/amd64

Output of go env in your module/workspace:

GOCACHE=/foo/deps/gomod
GOMODCACHE=/foo/deps/gomod/pkg/mod
GOPATH=/foo/deps/gomod
GOPROXY=file:///foo/deps/gomod/pkg/mod/cache/download
GOTOOLCHAIN=auto

What did you do?

  1. Pre-fetch dependencies of a project and store them in the mod cache favoring the latest toolchain on a given arch (x86) using GOTOOLCHAIN=auto:
  2. Run a build on a different arch (aarch64) using the mod cache from previous step with no network:

What did you see happen?

  1. on an online x86_64 machine:
$ go version
go version go1.21.4 linux/amd64

$ cat go.mod
go 1.21
toolchain 1.21.6
...

$ GOTOOLCHAIN=auto GOSUMDB=sum.golang.org ... go mod download
go: downloading go1.21.6 (linux/amd64)
...
  1. on an offline aarch64 machine:
$ go version
go version go1.21.4 linux/arm64

$ GOTOOLCHAIN=auto GOMODCACHE=/foo/deps/gomod/pkg/mod GOPROXY=file:///foo/deps/gomod/pkg/mod/cache/download ... go build -a -x -v
go: downloading go1.21.6 (linux/arm64)
go: download go1.21.6 for linux/arm64: toolchain not available

$ tree /foo/deps/gomod| grep -C5 toolchain
...
cache
  └ download
        ├ golang.org
              ├ toolchain
                    └ @v
                           ├ v0.0.1-go1.21.6.linux-amd64.lock
                           ├ **v0.0.1-go1.21.6.linux-amd64.zip**
                           ├ v0.0.1-go1.21.6.linux-amd64.ziphash
                           └ **v0.0.1-go1.21.6.linux-arm64.lock**
...

What did you expect to see?

Given that one is able to fetch and download a given release of Go for a given arch manually successfully:
GOARCH=arm64 go install 'golang.org/dl/go1.21.8@latest'; <path>/go/bin/linux_arm64/go1.21.8

I would assume that by instrumenting Go with GOARCH=<arch> GOTOOLCHAIN=auto with e.g. go mod download Go would also fetch a toolchain of the desired version for the desired architecture, but instead a native toolchain of the desired version is always downloaded instead, naturally failing the build on the other arch. Now, aside from Go being able to cross-compile for many platform/arch pairs out-of-the box already I'm wondering if you could consider this use case as well (have a single node to prefetch artifacts for the rest of the nodes in a multi-arch node setup) or there's some major technical blocker rendering this as a complete non-issue not worth addressing.

@thanm thanm added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 27, 2024
@thanm
Copy link
Contributor

thanm commented Mar 27, 2024

@golang/tools-team

@seankhliao seankhliao changed the title Respect GOARCH setting with automatic toolchain downloads (i.e. with GOTOOLCHAIN=auto) for multi-arch use-cases cmd/go: respect GOARCH setting with automatic toolchain downloads Mar 27, 2024
@seankhliao
Copy link
Member

GOTOOLCHAIN not only triggers a download but also a switch to that version to perform any command that was passed, including go mod download. Obviously this won't be possible if you download a toolchain for a different OS or arch.

perhaps it would be more appropriate for you to explicitly specify the toolchain module to pre download? https://proxy.golang.org/golang.org/toolchain/@v/list

@matloob
Copy link
Contributor

matloob commented Apr 16, 2024

The go install command in your example works because you're compiling the golang.org/dl/go1.21.8 tool for ARM and then running go1.21.8 download will download the runtime.GOARCH (which is ARM) version of the Go command. So it's using it's essentially just using Go's normal cross compiling behavior. (Assuming you run the go install on a non-arm system, and then the download command on an arm system).

I like @seankhliao 's suggestion.

@matloob
Copy link
Contributor

matloob commented Apr 16, 2024

Closing this issue. Please reopen if you need more help.

@matloob matloob closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants