I have a stripped down environment, where I want to use go at a custom path.
printenv
gives me:
GOOS=linux
GOROOT=/mygo
GOHOSTOS=linux
GOARCH=amd64
TMPDIR=/mytmp
GOHOSTARCH=amd64
GOPATH=/mysrcs
PWD=/home/andreas
Now if I try to compile go code, it fails to find the stdlib:
could not import fmt (cannot find package "fmt" in any of:
/mygo/src/fmt (from $GOROOT)
If I do find /mygo | grep fmt
, I get:
/mygo/pkg/linux_amd64/fmt.a
When I use the system go (normal bash environment), it works fine. What implicit dependencies does go need to find the stdlib packages?
Thanks to @JimB, I managed to get it working.
I indeed want binary-only packaging of stdlib. Discussion online is that $GOROOT/pkg
is a valid use-case for binary distribution, while $GOPATH/pkg
might get deprecated soonish, so beware.
If you want to provide binary-only packages, https://github.com/tcnksm/go-binary-only-package shows how to create (annotated) src
directory structure, in order for go to stop searching for source files.