Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: fails with go: cannot find GOROOT directory after cross-compiling from WSL to Windows. #45763

Open
aodhneine opened this issue Apr 25, 2021 · 15 comments

Comments

@aodhneine
Copy link

@aodhneine aodhneine commented Apr 25, 2021

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

$ GOROOT=/usr/local/go go version
go version go1.16.3 linux/amd64

Does this issue reproduce with the latest release?

No, building from go1.16.3 branch doesn't reproduce this bug.

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

Using WSL 2 with Alpine Linux on Windows 10 Home, build 21364.co_release.210416-1504.

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/freya/.cache/go-build"
GOENV="/home/freya/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/freya/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/freya/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"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3203524129=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Cross-compiled Go toolchain master using Go 1.16.3 for windows/amd64, using the standard procedures as described on https://golang.org/doc/install/source. When running /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version I got the following error instead: go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot. The same happens when setting GOROOT=/mnt/c/Users/admer/goroot/.

What did you expect to see?

go.exe version running correctly and not failing.

What did you see instead?

% /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version
go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot
% GOROOT=/mnt/c/Users/freya/goroot/ /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version
go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot
@AlexRouSg
Copy link
Contributor

@AlexRouSg AlexRouSg commented Apr 25, 2021

What happens when you unset GOROOT? You normally do not have to set it as the default is dertermined by the executable location.

@aodhneine
Copy link
Author

@aodhneine aodhneine commented Apr 25, 2021

Same as whenGOROOT is set. Tried with GOROOT= /mnt/..., export GOROOT=, and unset GOROOT.

% /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version
go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot
@aodhneine aodhneine changed the title Fails with go: cannot find GOROOT directory after cross-compiling from Linux to Windows. Fails with go: cannot find GOROOT directory after cross-compiling from WSL to Windows. Apr 25, 2021
@AlexRouSg
Copy link
Contributor

@AlexRouSg AlexRouSg commented Apr 25, 2021

The path /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe looks like you are running inside WSL, which is weird cause you are trying to run a .exe.
Can you run it through powershell?

@aodhneine
Copy link
Author

@aodhneine aodhneine commented Apr 26, 2021

It returns the exactly same error.

Let me try to clarify what I exactly did. First, I cloned Go repo to C:\Users\freya\goroot, since I cannot build it in WSL, as it requires support for LockFileEx, which isn't currently supported (see #37461 and microsoft/WSL#5762). Then I downloaded Go 1.16.3 release for Linux to /usr/local/go in WSL, and added it to the PATH. Lastly, I went to the goroot folder and ran GOOS=windows GOARCH=amd64 ./all.bash, building the Windows version of the compiler. When I ran bin/windows_amd64/go.exe, it failed with that error.

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Apr 26, 2021

How do you run the Windows program? I think it is supposed to be run from Windows, not from the Linux environment.

@cherrymui cherrymui changed the title Fails with go: cannot find GOROOT directory after cross-compiling from WSL to Windows. cmd/go: fails with go: cannot find GOROOT directory after cross-compiling from WSL to Windows. Apr 26, 2021
@aodhneine
Copy link
Author

@aodhneine aodhneine commented Apr 26, 2021

WSL allows to transparently run Windows programs from the Linux environment.

@AlexRouSg
Copy link
Contributor

@AlexRouSg AlexRouSg commented Apr 26, 2021

WSL allows to transparently run Windows programs from the Linux environment.

And I am asking whether it runs in a normal power shell, this is importatnt to know whether it is a WSL specific problem.

@aodhneine
Copy link
Author

@aodhneine aodhneine commented Apr 26, 2021

As I previously wrote, it returns the same error.

@AlexRouSg
Copy link
Contributor

@AlexRouSg AlexRouSg commented Apr 26, 2021

Was GOROOT unset while running in power shell?
Did you try setting GOROOT=C:/Users/freya/goroot

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Apr 26, 2021

Could you provide the exact commands that you use to build the toolchain, as well as how you run it? Thanks.

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Apr 26, 2021

@aodhneine
Copy link
Author

@aodhneine aodhneine commented Apr 26, 2021

... Why does it work now?

% git clone https://go.googlesource.com/go goroot-master --depth 1
Cloning into 'goroot-master'...
remote: Finding sources: 100% (10857/10857)
remote: Total 10857 (delta 1384), reused 7013 (delta 1384)
Receiving objects: 100% (10857/10857), 22.75 MiB | 4.05 MiB/s, done.
Resolving deltas: 100% (1384/1384), done.
Updating files: 100% (10022/10022), done.
% cd goroot-master
% git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
% cd src
% GOOS=windows GOARCH=amd64 GOROOT_BOOTSTRAP=/usr/local/go ./all.bash
Building Go cmd/dist using /usr/local/go. (go1.16.3 linux/amd64)
Building Go toolchain1 using /usr/local/go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for host, linux/amd64.
Building packages and commands for target, windows/amd64.

##### Testing packages.
... see https://p.teknik.io/Raw/5dgnv ...
% /home/freya/goroot-master/bin/go version
go version devel go1.17-d020264 Mon Apr 26 17:52:46 2021 +0000 linux/amd64
% /home/freya/goroot-master/bin/windows_amd64/go.exe version
go version devel go1.17-d020264 Mon Apr 26 17:52:46 2021 +0000 windows/amd64
PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Alpine\home\freya\goroot-master> .\bin\windows_amd64\go.exe version
go version devel go1.17-d020264 Mon Apr 26 17:52:46 2021 +0000 windows/amd64
@AlexRouSg
Copy link
Contributor

@AlexRouSg AlexRouSg commented Apr 26, 2021

Did you change from WSL1 to WSL2?

@aodhneine
Copy link
Author

@aodhneine aodhneine commented Apr 26, 2021

No, it was WSL2 before too.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Apr 28, 2021

How do you run the Windows program? I think it is supposed to be run from Windows, not from the Linux environment.

WSL is not Windows.

If you want to use WSL environment, then you should follow Linux instructions on how to install and use Go.

If you want to use Windows environment, then you should follow Windows instructions for Go.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants