aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-03-04 03:54:29 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-04 06:55:46 +0100
commit852975b9166b05a0906a0c274f879fc77c7d0803 (patch)
tree4a9d1f6d93ad537976a981d3b71e063760c43a9a
parentifaceconfig: remove split routes param (diff)
downloadwireguard-windows-852975b9166b05a0906a0c274f879fc77c7d0803.tar.xz
wireguard-windows-852975b9166b05a0906a0c274f879fc77c7d0803.zip
build: support windows
TDM is old and ugly, but musl.cc is having issues right now.
-rw-r--r--.gitignore1
-rw-r--r--README.md24
-rw-r--r--build.bat52
3 files changed, 64 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 1cf866a4..494c3301 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
*.syso
.tmp
.idea
+deps
diff --git a/README.md b/README.md
index 9772c996..2795c484 100644
--- a/README.md
+++ b/README.md
@@ -4,28 +4,26 @@ Nothing to see here yet. Come back later.
### Requirements
- - [Go ≥1.12](https://www.golang.org)
- [Wintun](https://git.zx2c4.com/wintun)
-### Clone
+### Building on Windows
-This has a few submodules at the moment, so you'll need to clone recursively. While building (below) uses WSL, it's recommended that you still clone into Windows per usual.
+The build script will take care of downloading (without verification) and installing Go 1.12 and Mingw.
```
-$ cd Projects
-$ git clone --recursive https://git.zx2c4.com/wireguard-windows
+C:\Projects> git clone https://git.zx2c4.com/wireguard-windows
+C:\Projects> cd wireguard-windows
+C:\Projects\wireguard-windows> build
```
-### Building
+### Building on Linux
-The use of cgo/mingw makes it slightly easier to compile from WSL. Here are instructions for [Ubuntu 18.04 from the Windows Store](https://www.microsoft.com/en-us/p/ubuntu-1804-lts/9n9tngvndl3q) on WSL:
+You must first have Go 1.12 and Mingw installed.
```
-$ sudo apt update
-$ sudo apt install mingw-w64 make
-$ curl https://dl.google.com/go/go1.12.linux-amd64.tar.gz | tar xzf -
-$ export PATH="$PWD/go/bin:$PATH"
-$ cd /mnt/c/Users/YourUsername/Projects/wireguard-windows
+$ sudo apt install mingw-w64 golang-go
+$ git clone https://git.zx2c4.com/wireguard-windows
+$ cd wireguard-windows
$ make
```
@@ -34,5 +32,5 @@ $ make
After you've built the application, run `wireguard.exe` to install the manager service and show the UI.
```
-$ ./wireguard.exe
+C:\Projects\wireguard-windows> wireguard
```
diff --git a/build.bat b/build.bat
new file mode 100644
index 00000000..e440e56c
--- /dev/null
+++ b/build.bat
@@ -0,0 +1,52 @@
+@echo off
+set STARTDIR=%cd%
+set OLDPATH=%PATH%
+if not exist deps\.prepared call :installdeps
+set PATH=%STARTDIR%\deps\tdm\bin\;%STARTDIR%\deps\go\bin\;%PATH%
+set CC=x86_64-w64-mingw32-gcc.exe
+set GOOS=windows
+set GOARCH=amd64
+set GOPATH=%STARTDIR%\deps\gopath
+set GOROOT=%STARTDIR%\deps\go
+set CGO_ENABLED=1
+echo Assembling resources
+go run github.com/akavel/rsrc -manifest ui/manifest.xml -ico ui/icon/icon.ico -arch amd64 -o resources.syso || goto :error
+echo Building program
+go build -ldflags="-H windowsgui" -o wireguard.exe || goto :error
+goto :out
+
+:installdeps
+ rmdir /s /q deps 2> NUL
+ mkdir deps || goto :error
+ cd deps || goto :error
+ echo Downloading golang
+ curl -#o go.zip https://dl.google.com/go/go1.12.windows-amd64.zip || goto :error
+ echo Downloading gcc
+ curl -#Lo gcc.zip https://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%%205%%20series/5.1.0-tdm64-1/gcc-5.1.0-tdm64-1-core.zip || goto :error
+ echo Downloading binutils
+ curl -#Lo binutils.zip https://sourceforge.net/projects/tdm-gcc/files/GNU%%20binutils/binutils-2.25-tdm64-1.zip || goto :error
+ echo Downloading mingw64rt
+ curl -#Lo mingw64rt.zip https://sourceforge.net/projects/tdm-gcc/files/MinGW-w64%%20runtime/GCC%%205%%20series/mingw64runtime-v4-git20150618-gcc5-tdm64-1.zip
+ echo Extracting golang
+ tar -xf go.zip || goto :error
+ mkdir tdm || goto :error
+ cd tdm || goto :error
+ echo Extracting gcc
+ tar -xf ..\gcc.zip || goto :error
+ echo Extracting binutils
+ tar -xf ..\binutils.zip || goto :error
+ echo Extracting mingw64rt
+ tar -xf ..\mingw64rt.zip || goto :error
+ cd .. || goto :error
+ echo Cleaning up
+ del go.zip gcc.zip binutils.zip mingw64rt.zip || goto :error
+ copy /y NUL .prepared > NUL || goto :error
+ cd .. || goto :error
+ exit /b
+
+:error
+ echo Failed with error #%errorlevel%.
+:out
+ set PATH=%OLDPATH%
+ cd %STARTDIR%
+ exit /b %errorlevel%