Skip to content

Commit

Permalink
build(client/electron): build Windows with MinGW (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna authored Apr 5, 2024
1 parent db98df4 commit 29d2f2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
22 changes: 9 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ IMPORT_PATH=$(IMPORT_HOST)/Jigsaw-Code/outline-apps
all: android apple linux windows

ROOT_PKG=client/src/tun2socks
# Don't strip Android debug symbols so we can upload them to crash reporting tools.
ANDROID_BUILD_CMD=$(GOBIND) -a -ldflags '-w' -target=android -androidapi 19 -tags android -work

android: $(BUILDDIR)/android/tun2socks.aar

$(BUILDDIR)/android/tun2socks.aar: $(GOMOBILE)
mkdir -p "$(BUILDDIR)/android"
$(ANDROID_BUILD_CMD) -o "$@" $(IMPORT_PATH)/$(ROOT_PKG)/outline/tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/shadowsocks
# Don't strip Android debug symbols so we can upload them to crash reporting tools.
$(GOBIND) -target=android -androidapi 19 -tags android -work -a -ldflags '-w' -o "$@" $(IMPORT_PATH)/$(ROOT_PKG)/outline/tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/shadowsocks

$(BUILDDIR)/ios/Tun2socks.xcframework: $(GOMOBILE)
# -iosversion should match what outline-client supports.
$(GOBIND) -iosversion=12.0 -target=ios,iossimulator -o $@ -ldflags '-w' -bundleid org.outline.tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/shadowsocks
$(GOBIND) -target=ios,iossimulator -iosversion=12.0 -bundleid org.outline.tun2socks -ldflags '-w' -o "$@" $(IMPORT_PATH)/$(ROOT_PKG)/outline/tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/shadowsocks

$(BUILDDIR)/macos/Tun2socks.xcframework: $(GOMOBILE)
# MACOSX_DEPLOYMENT_TARGET and -iosversion should match what outline-client supports.
Expand All @@ -38,7 +37,7 @@ $(BUILDDIR)/apple/Tun2socks.xcframework: $(BUILDDIR)/ios/Tun2socks.xcframework $
XGO=$(GOBIN)/xgo
TUN2SOCKS_VERSION=v1.16.11
XGO_LDFLAGS='-w -X main.version=$(TUN2SOCKS_VERSION)'
ELECTRON_PKG=$(ROOT_PKG)/outline/electron
ELECTRON_PKG="./client/src/tun2socks/outline/electron"

# TODO: build directly when on linux
LINUX_BUILDDIR=$(BUILDDIR)/linux
Expand All @@ -56,16 +55,13 @@ WINDOWS_BUILDDIR=$(BUILDDIR)/windows

windows: $(WINDOWS_BUILDDIR)/tun2socks.exe

$(WINDOWS_BUILDDIR)/tun2socks.exe: $(XGO)
mkdir -p "$(WINDOWS_BUILDDIR)/$(IMPORT_PATH)"
$(XGO) -ldflags $(XGO_LDFLAGS) --targets=windows/386 -dest "$(WINDOWS_BUILDDIR)" -pkg $(ELECTRON_PKG) .
mv "$(WINDOWS_BUILDDIR)/$(IMPORT_PATH)-windows-386.exe" "$@"
rm -r "$(WINDOWS_BUILDDIR)/$(IMPORT_HOST)"

$(WINDOWS_BUILDDIR)/tun2socks.exe:
mkdir -p "$(@D)"
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build --ldflags=--extldflags=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)

$(GOMOBILE): go.mod
env GOBIN="$(GOBIN)" go install golang.org/x/mobile/cmd/gomobile
env GOBIN="$(GOBIN)" $(GOMOBILE) init
mkdir -p "$(@D)"
go build -o "$(@D)" golang.org/x/mobile/cmd/gomobile golang.org/x/mobile/cmd/gobind

$(XGO): go.mod
env GOBIN="$(GOBIN)" go install github.com/crazy-max/xgo
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions src/electron/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Electron Development Instructions
# Electron Development Instructions

Unlike the Android and Apple clients, the Windows and Linux clients use the Electron framework, rather than Cordova.

Expand All @@ -7,7 +7,6 @@ You will need [Docker](https://www.docker.com/) installed to build the Electron
> If you can't use Docker, you can use [podman](https://podman.io) as substitute by running the following (for macOS):
```sh
brew install podman
podman machine init
sudo ln -s $(which podman) /usr/local/bin/docker
sudo /opt/homebrew/Cellar/podman/<podman version>/bin/podman-mac-helper install
Expand All @@ -28,7 +27,27 @@ To run the Electron clients, run:
npm run action electron/start [windows|linux]
```

### Windows
## Windows

To build for Windows on a macOS, you need to first install [MinGW-w64](https://www.mingw-w64.org/) v11.0.1+.

With [MacPorts](https://www.mingw-w64.org/downloads/#macports) (official channel):

```sh
sudo port install x86_64-w64-mingw32-gcc @11.0.1
```

With Homebrew (unofficial, how to ensure consistent version?):

```sh
brew install mingw-w64
```

You can also build it on Ubuntu. To install MinGW-w64:

```sh
apt update && apt install -y gcc-mingw-w64-x86-64
```

To build the _release_ version of Windows installer, you'll also need:

Expand Down

0 comments on commit 29d2f2b

Please sign in to comment.