Open elieux opened 9 years ago
Need more work on relocating go folders. Right now it not usable at all. It still look into ${GOROOT}/src
instead ${GOROOT}/lib/go/src
For reference: the Go Language manual Getting Started (doc/install) recommends never to install Go in other path than the installer suggests. Currently, BTW, GOROOT variable is always hardcoded into the binaries when Go is built. In Windows it's in pkg/windows_amd64/runtime/cgo.a
now.
$GOROOT
is widely used in every platform, while it's assumed to be hardcoded as the installer suggests. And it does not seem to change in the future. So I don't even think writing a patch is possible.
Despite not recommended by the language maintainers, it's enough to set $GOROOT
for equivalent of $MINGW_PREFIX/lib/go
; i.e. run GOROOT=/mingw64/lib/go go env
or GOROOT=$MINGW_PREFIX/lib/go go env
instead of go env
. So if possible, the package need to contain only one more line of setting GOROOT variable when installed.
@elieux Is this issue still reproducible?
I can confirm this issue is still reproducible
❯ pacman -S mingw-w64-x86_64-go
resolving dependencies...
looking for conflicting packages...
Packages (1) mingw-w64-x86_64-go-1.20.2-1
... # truncated for brevity
❯ go env GOROOT
go: cannot find GOROOT directory: D:\a\msys64\mingw64\lib\go
This means installing any go
package also requires setting all relevant environment variables.
I don't know if it's somehow possible to have it use Unix-like paths (e.g. /mingw64/lib/go
) but that would solve the issue entirely as that can be created as part of the install process. If that isn't possible, then perhaps including a wrapper script that sets defaults and alerts the user on invocation (perhaps file-checked so a simple touch
silences it) would be a cleaner solution?
edit: it's not just go env GOROOT
causing problems by the way, it's every go ...
command including go version
, they just all output the same error
Second edit: simply having the bash profile refreshed """fixes""" the problem, but only within an active bash session. So even when exclusively going through the MSYS2 env, --noprofile
will break any use of go
❯ env -i /bin/bash --noprofile -c '/mingw64/bin/go version'
go: cannot find GOROOT directory: D:\a\msys64\mingw64\lib\go
Example inspired by 1480c1's comment
Still happening with go version
:(
yep, this happens every single time, why not add it to bashrc or something when go is installed?
There is a variable, GOROOT, that specifies where go should look for its files. If not set in environment, go uses a hardcoded path defined at build-time (which for current binaries is
C:\repo\mingw-w64-go\src\go
).We need to define GOROOT in
profile.d
(which is probably bad, because it's a mingw package) or patch the source, so go finds the path relatively to its executable.
also it is not bad, if called within msys2 it will behave like msys2 expects, but if called outside of msys2, it will default for windows path, the best of both worlds?
There is a variable, GOROOT, that specifies where go should look for its files. If not set in environment, go uses a hardcoded path defined at build-time (which for current binaries is
C:\repo\mingw-w64-go\src\go
).We need to define GOROOT in
profile.d
(which is probably bad, because it's a mingw package) or patch the source, so go finds the path relatively to its executable.