Skip to content

cmd/go: get ignores GOARCH environment variable #36022

@dh1tw

Description

@dh1tw

What version of Go are you using (go version)?

$ go version
go version go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

$ go env

GO111MODULE=""
GOARCH="386"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=".exe"
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="windows"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
GO386="sse2"
AR="ar"
CC="i686-w64-mingw32-gcc"
CXX="i686-w64-mingw32-g++"
CGO_ENABLED="1"
GOMOD="/usr/src/myapp/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build660781913=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I want to cross compile a program to GOOS=windows and GOARCH=386. These variables have already been set in the environment (see above). However, I want to install some tools (code generators) before actually (cross) compiling.

Since the HostOS and HostARCH differ, I inline GOOSand GOARCH before the actual go get:

$ GOOS=linux GOARCH=amd64 go get github.com/gogo/protobuf/protoc-gen-gofast

What did you expect to see?

I expect that by specifying GOOS and GOARCH inline with the go get command, that the program (in this case protoc-gen-gofast) is compiled for linux amd64.

What did you see instead?

The inline GOARCH environment variable is ingnored. Instead a binary is produced for linux_386.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions