From 9c9c8d13bbc9b58de02271d4690cb20840c1d7c2 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 7 Mar 2019 06:27:53 +0100 Subject: ui: embed resource the old fashioned way If we ever get rid of the cgo requirement, we can return to rsrc or some variant of it. But given that win32 GUI stuff benefits from the larger cgo stacks, that seems unlikely. This gives us a bit more latitude to embed all sorts of interesting things in here as well. Clean up the makefile while we're at it and reduce the size of the exe. --- Makefile | 24 ++++++++++++++++-------- build.bat | 5 +++-- go.mod | 1 - manifest.xml | 26 ++++++++++++++++++++++++++ resources.rc | 39 +++++++++++++++++++++++++++++++++++++++ ui/manifest.xml | 14 -------------- ui/ui.go | 2 +- version.h | 1 + 8 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 manifest.xml create mode 100644 resources.rc delete mode 100644 ui/manifest.xml create mode 100644 version.h diff --git a/Makefile b/Makefile index 0fb865a9..720c0099 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,27 @@ -CFLAGS ?= -O3 -CFLAGS += -Wall -std=gnu11 +export CFLAGS := -O3 -Wall -std=gnu11 +export CC := x86_64-w64-mingw32-gcc +WINDRES := x86_64-w64-mingw32-windres +export CGO_ENABLED := 1 +export GOOS := windows +export GOARCH := amd64 + +DEPLOYMENT_HOST ?= winvm +DEPLOYMENT_PATH ?= Desktop all: wireguard.exe -resources.syso: ui/icon/icon.ico ui/manifest.xml go.mod - go run github.com/akavel/rsrc -manifest ui/manifest.xml -ico ui/icon/icon.ico -arch amd64 -o resources.syso +resources.syso: resources.rc manifest.xml ui/icon/icon.ico + $(WINDRES) -i $< -o $@ -O coff rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) wireguard.exe: resources.syso $(call rwildcard,,*.go *.c *.h) - CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -ldflags="-H windowsgui" -o $@ + go build -ldflags="-H windowsgui -s -w" -v -o $@ -run: wireguard.exe - wine wireguard.exe +deploy: wireguard.exe + -ssh $(DEPLOYMENT_HOST) -- 'taskkill /im wireguard.exe /f' + scp wireguard.exe $(DEPLOYMENT_HOST):$(DEPLOYMENT_PATH) clean: rm -rf resources.syso wireguard.exe -.PHONY: run clean all +.PHONY: deploy clean all diff --git a/build.bat b/build.bat index 2d2224dd..0c8f1831 100644 --- a/build.bat +++ b/build.bat @@ -4,15 +4,16 @@ set OLDPATH=%PATH% if not exist deps\.prepared call :installdeps set PATH=%STARTDIR%\deps\x86_64-w64-mingw32-native\bin\;%STARTDIR%\deps\go\bin\;%PATH% set CC=x86_64-w64-mingw32-gcc.exe +set CFLAGS=-O3 -Wall -std=gnu11 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 +windres.exe -i resources.rc -o resources.syso -O coff || goto :error echo Building program -go build -ldflags="-H windowsgui" -o wireguard.exe || goto :error +go build -ldflags="-H windowsgui -s -w" -v -o wireguard.exe || goto :error goto :out :installdeps diff --git a/go.mod b/go.mod index 5c6d8f27..10d466cc 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( ) replace ( - github.com/akavel/rsrc => golang.zx2c4.com/wireguard/windows pkg/rsrc github.com/lxn/walk => golang.zx2c4.com/wireguard/windows pkg/walk github.com/lxn/win => golang.zx2c4.com/wireguard/windows pkg/walk-win ) diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 00000000..72e407d3 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + true + + + diff --git a/resources.rc b/resources.rc new file mode 100644 index 00000000..fd3a521d --- /dev/null +++ b/resources.rc @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +#include +#include "version.h" + +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST manifest.xml + +1 ICON ui/icon/icon.ico + +VS_VERSION_INFO VERSIONINFO +FILEVERSION 0,0,0,1 +PRODUCTVERSION 0,0,0,1 +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_APP +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "WireGuard LLC" + VALUE "FileDescription", "WireGuard: Fast, Modern, Secure VPN Tunnel" + VALUE "FileVersion", WIREGUARD_WINDOWS_VERSION + VALUE "InternalName", "wireguard" + VALUE "LegalCopyright", "Copyright \xa9 2015-2019 Jason A. Donenfeld . All Rights Reserved." + VALUE "OriginalFilename", "wireguard.exe" + VALUE "ProductName", "WireGuard" + VALUE "ProductVersion", WIREGUARD_WINDOWS_VERSION + VALUE "Comments", "https://www.wireguard.com/" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/ui/manifest.xml b/ui/manifest.xml deleted file mode 100644 index a14c4be4..00000000 --- a/ui/manifest.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - true - - - diff --git a/ui/ui.go b/ui/ui.go index 2abd6de0..f82d3f4d 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -28,7 +28,7 @@ AllowedIPs = 0.0.0.0/0 ` func RunUI() { - icon, _ := walk.NewIconFromResourceId(8) + icon, _ := walk.NewIconFromResourceId(1) mw, _ := walk.NewMainWindowWithName("WireGuard") tray, _ := walk.NewNotifyIcon(mw) diff --git a/version.h b/version.h new file mode 100644 index 00000000..8da652db --- /dev/null +++ b/version.h @@ -0,0 +1 @@ +#define WIREGUARD_WINDOWS_VERSION "0.0.20190307" -- cgit v1.2.3-59-g8ed1b