go: cmd/go: `go install` with CGO_ENABLED=0 tries to install standard packages, which can fail
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
[jaten@biggie tmp]$ go version
go version go1.8rc3 linux/amd64 ## also happens on go1.7.4
[jaten@biggie tmp]$
What operating system and processor architecture are you using (go env
)?
[jaten@biggie tmp]$ go env
GOARCH=“amd64”
GOBIN=“”
GOEXE=“”
GOHOSTARCH=“amd64”
GOHOSTOS=“linux”
GOOS=“linux”
GOPATH=“/home/jaten/go”
GORACE=“”
GOROOT=“/usr/local/go”
GOTOOLDIR=“/usr/local/go/pkg/tool/linux_amd64”
GCCGO=“gccgo”
CC=“gcc”
GOGCCFLAGS=“-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build885638224=/tmp/go-build -gno-record-gcc-switches”
CXX=“g++”
CGO_ENABLED=“0”
PKG_CONFIG=“pkg-config”
CGO_CFLAGS=“-g -O2”
CGO_CPPFLAGS=“”
CGO_CXXFLAGS=“-g -O2”
CGO_FFLAGS=“-g -O2”
CGO_LDFLAGS=“-g -O2”
[jaten@biggie tmp]$
What did you do?
I ran make for https://github.com/glycerine/vhaline Makefile does go install on the library github.com/glycerine/vhaline/vhaline and then on a test executable; github.com/glycerine/vhaline/cmd/vhaline
What did you expect to see?
successful build. build is successful without CGO_ENABLED=0
What did you see instead?
[jaten@biggie vhaline]$ make
cd vhaline && go install && cd ../cmd/vhaline && go install
go install net: open /usr/local/go/pkg/linux_amd64/net.a: permission denied ### problem!
make: *** [build] Error 1
[jaten@biggie vhaline]$ go version
go version go1.8rc3 linux/amd64
[jaten@biggie vhaline]$ env|grep GO
CGO_ENABLED=0
GOROOT=/usr/local/go
GODEBUG=netdns=go
GOPATH=/home/jaten/go
[jaten@biggie vhaline]$ ls -al /usr/local/go/pkg/linux_amd64/net.a
-rw-r--r-- 1 root root 1209910 Jan 26 18:55 /usr/local/go/pkg/linux_amd64/net.a
[jaten@biggie vhaline]$ file /usr/local/go/pkg/linux_amd64/net.a
/usr/local/go/pkg/linux_amd64/net.a: current ar archive
[jaten@biggie vhaline]$ mkdir tmp
[jaten@biggie vhaline]$ cd tmp
[jaten@biggie tmp]$ ar x /usr/local/go/pkg/linux_amd64/net.a
[jaten@biggie tmp]$ ls -al
total 1192
drwxrwxr-x 2 jaten jaten 48 Feb 7 16:57 .
drwxrwxr-x 7 jaten jaten 4096 Feb 7 16:57 ..
-rw-r--r-- 1 jaten jaten 19172 Feb 7 16:57 _all.o
-rw-r--r-- 1 jaten jaten 1169185 Feb 7 16:57 _go_.o
-rw-r--r-- 1 jaten jaten 21364 Feb 7 16:57 __.PKGDEF
[jaten@biggie tmp]$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jaten/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build885638224=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="0"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
[jaten@biggie tmp]$ go version
go version go1.8rc3 linux/amd64
[jaten@biggie tmp]$ unset CGO_ENABLED
[jaten@biggie tmp]$ cd ..
[jaten@biggie vhaline]$ make
cd vhaline && go install && cd ../cmd/vhaline && go install
[jaten@biggie vhaline]$ #successful build
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (10 by maintainers)
Commits related to this issue
- Remove CGO_ENABLED=0 from make install It was writing to stdlib packages net, x/crypto, etc. and failing when it didn't have write access to them (which it often shouldn't) Fixes issue #941 Explain... — committed to tendermint/tendermint by ethanfrey 7 years ago
- Remove CGO_ENABLED=0 from make install It was writing to stdlib packages net, x/crypto, etc. and failing when it didn't have write access to them (which it often shouldn't) Fixes issue #941 Explain... — committed to tendermint/tendermint by ethanfrey 7 years ago
- Removes disabling CGO for dev builds. This works around https://github.com/golang/go/issues/18981 until that fix makes it into an official release. — committed to hashicorp/envconsul by slackpad 6 years ago
- Documentation/development: Bump minimum Go version to 1.10 This gets us a fixed 'CGO_ENABLED=0 go install' [1,2] and avoids 1.8 (which is no longer supported upstream now that 1.10 has been released ... — committed to wking/bootkube by wking 6 years ago
- Makefile: Use 'go install ...' for the install target GOBIN (documented in [1]) defaults to DIR/bin, but it's a configurable variable in its own right. The old logic was just looking at GOPATH, thou... — committed to wking/bootkube by wking 6 years ago
- Makefile: Use 'go install ...' for the install target (#949) GOBIN (documented in [1]) defaults to DIR/bin, but it's a configurable variable in its own right. The old logic was just looking at GOPA... — committed to kubernetes-retired/bootkube by wking 6 years ago
Work on better caching will fix this. I have a prototype. Not for Go 1.9 but probably for Go 1.10.
That would be wonderful if that was the outcome of this ticket, the “official binary + cross compile + go install” story is the last remaining hurdle to Go developers having a seamless cross compilation experience with our official builds.
On Wed, Feb 8, 2017 at 7:51 AM, Ian Lance Taylor notifications@github.com wrote: