andrewkroh / gvm

Go Version Manager (written in Go for cross-platform usability)
Apache License 2.0
195 stars 24 forks source link

Default install does not honor GOARCH #52

Closed mdelapenya closed 2 years ago

mdelapenya commented 2 years ago

I'm trying to install Go on my Macbook Pro M1 with GVM, but it always installs the AMD64 version of Go:

$ eval "$(gvm 1.17.8)"
$ go version
go version go1.17.8 darwin/amd64

It's not until I add the GOARCH variable when it respects the architecture of my machine:

$ GOARCH=arm64 eval "$(gvm 1.17.8)"
$ go version                       
go version go1.17.8 darwin/arm64
mdelapenya commented 2 years ago

I'd also add installation instructions in the docs for ARM :)

curl -sL -o /usr/local/bin/gvm https://github.com/andrewkroh/gvm/releases/download/v0.4.1/gvm-darwin-arm64
andrewkroh commented 2 years ago

It does not use GOARCH. It is supposed to support the --arch flag and GVM_ARCH env var. But I see a bug in setting that prevent its use (will fix).

gvm flags can be set via environment variables by setting GVM_<flag>. For example --http-timeout can be set via GVM_HTTP_TIMEOUT=10m.

Optional flags:
  -h, --help                   Show context-sensitive help (also try --help-long and --help-man).
  -d, --debug                  Enable debug logging to stderr.
      --os=OS                  Go binaries target os.
      --arch=ARCH              Go binaries target architecture.

You must already have the darwin/amd64 version of gvm installed, because it defaults to using the architecture of gvm (via runtime.GOARCH). So if you install the darwin/arm64 release then it should default to arm64.

andrewkroh commented 2 years ago

Relates: https://github.com/andrewkroh/gvm/pull/53 (fixes --arch)

andrewkroh commented 2 years ago

It's not until I add the GOARCH variable when it respects the architecture of my machine:

GOARCH=arm64 eval "$(gvm 1.17.8)"

In general, that environment variable won't be made available to the subshell. So it would be surprising to have GOARCH affect anything within that subshell.

andrewkroh commented 2 years ago

I tested the fix for the --arch flag and it is working. I also updated the README to include MacOS arm64 commands.

On a M1 mac I tested using an amd64 gvm binary with the --arch flag to install an arm64 Go version.

% gvm -d --arch=arm64 1.19
DEBU[0000] GVM version: v0.4.2-0.20220803200806-2fe721bcadc0 
DEBU[0000] GVM commit: h1:/rI3EYbmCdpCyPXqoNjBOifkcWFmyhke0iR/jQuxM+A= 
DEBU[0000] GVM arch: amd64                                               # <-- Architecture of gvm binary.
DEBU[0000] Using Go version 1.19                         package=main
export GOROOT="/Users/akroh/.gvm/versions/go1.19.darwin.arm64"
export PATH="/Users/akroh/.gvm/versions/go1.19.darwin.arm64/bin:$PATH"

The env var works too:

GVM_ARCH=arm64 gvm -d 1.19
DEBU[0000] GVM version: v0.4.2-0.20220803200806-2fe721bcadc0 
DEBU[0000] GVM commit: h1:/rI3EYbmCdpCyPXqoNjBOifkcWFmyhke0iR/jQuxM+A= 
DEBU[0000] GVM arch: amd64                              
DEBU[0000] Using Go version 1.19                         package=main
export GOROOT="/Users/akroh/.gvm/versions/go1.19.darwin.arm64"
export PATH="/Users/akroh/.gvm/versions/go1.19.darwin.arm64/bin:$PATH"

Or when using eval:

eval "$(GVM_ARCH=arm64 gvm -d 1.19)"

eval "$(gvm --arch=arm64 -d 1.19)"

andrewkroh commented 2 years ago

I'd also add installation instructions in the docs for ARM :)

I forgot we have a universal binary for mac so I now changed the readme to use that.