WireGuard / wgctrl-go

Package wgctrl enables control of WireGuard interfaces on multiple platforms.
https://godoc.org/golang.zx2c4.com/wireguard/wgctrl
MIT License
727 stars 85 forks source link

Missing files in Windows imports #98

Closed precisionpete closed 3 years ago

precisionpete commented 3 years ago

I'm trying to compile code on Windows that works on Linux and I'm missing files after importing.

I tried cross-compiling from linux without luck. Now I've copied the code to a Windows box.

Using: go version go1.15.7 windows/amd64

vscode shows no missing dependencies. But when you execute, you get:

C:\Users\peter\go\src\golang.zx2c4.com\wireguard\wgctrl\internal\wguser\conn_windows.go:14:2: cannot find package "golang.zx2c4.com/wireguard/ipc/winpipe" in any of: c:\go\src\golang.zx2c4.com\wireguard\ipc\winpipe (from $GOROOT) C:\Users\peter\go\src\golang.zx2c4.com\wireguard\ipc\winpipe (from $GOPATH) exit status 1 Process exiting with code: 1

If I try to reimport wgctrl, I get the following: go get golang.zx2c4.com/wireguard/wgctrl package golang.zx2c4.com/wireguard/ipc/winpipe: C:\Users\peter\go\src\golang.zx2c4.com\wireguard exists but C:\Users\peter\go\src\golang.zx2c4.com\wireguard.git does not - stale checkout?

Any ideas?

mdlayher commented 3 years ago

Works fine for me cross compiling for Windows on Linux.

✔ ~/src/golang.zx2c4.com/wgctrl [master|✔] 
12:34 $ GOOS=windows go build ./...
✔ ~/src/golang.zx2c4.com/wgctrl [master|✔] 
12:34 $ echo $?
0

You need to make sure you're using Go modules as well.

precisionpete commented 3 years ago

This is what I get from within Linux as well:

$ env GOOS=windows GOARCH=amd64 go build -o bin/wgagent.exe wgagent.go
../golang.zx2c4.com/wireguard/wgctrl/internal/wguser/conn_windows.go:14:2: cannot find package "golang.zx2c4.com/wireguard/ipc/winpipe" in any of:
        /home/pcarroll/.go/src/golang.zx2c4.com/wireguard/ipc/winpipe (from $GOROOT)
        /home/pcarroll/Development/go/src/golang.zx2c4.com/wireguard/ipc/winpipe (from $GOPATH)

I suspect it has something to do with how the packages were imported. I'm just doing: no errors...

$ go get golang.zx2c4.com/wireguard/wgctrl
$ go get golang.zx2c4.com/wireguard/wgctrl/wgtypes

The code works fine for Linux and Darwin

mdlayher commented 3 years ago

There's something wrong with your Go environment, not this package. Closing.

precisionpete commented 3 years ago

Can you suggest what it might be? It seems to work for everything else other than wgctrl compiling for Windows...

From within bash, I have:

$ echo $GOROOT
/home/pcarroll/.go
$ echo $GOPATH
/home/pcarroll/Development/go
$ which go
/home/pcarroll/.go/bin/go
$ go version
go version go1.15.7 linux/amd64
$ env GOOS=linux GOARCH=amd64 go build -o bin/wgagent wgagent.go
$ env GOOS=windows GOARCH=amd64 go build -o bin/wgagent.exe wgagent.go
../golang.zx2c4.com/wireguard/wgctrl/internal/wguser/conn_windows.go:14:2: cannot find package "golang.zx2c4.com/wireguard/ipc/winpipe" in any of:
    /home/pcarroll/.go/src/golang.zx2c4.com/wireguard/ipc/winpipe (from $GOROOT)
    /home/pcarroll/Development/go/src/golang.zx2c4.com/wireguard/ipc/winpipe (from $GOPATH)

I suspect something is missing from the package that is required for windows. Can you please confirm specifically what packages you are importing? I'm out of ideas... I can't find the files it's complaining about online. I suspect something moved...

mdlayher commented 3 years ago

You probably aren't using Go modules (go env -w GO111MODULE=on). I can confirm that a fresh checkout and build works just fine for me on a Windows 10 development VM.

precisionpete commented 3 years ago

That was it. Threw me off because it worked fine for Linux and Darwin. Only broke once I got to Windows.

Thanks for your help.