From afbaa317ed2f6edf66a0498597940738e059159c Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Wed, 10 Apr 2024 12:14:19 -0400 Subject: [PATCH] Use zig --- Makefile | 5 +++-- src/electron/README.md | 41 ++++++----------------------------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index f1c5e47b41..c541f87240 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ $(BUILDDIR)/apple/Tun2socks.xcframework: $(BUILDDIR)/ios/Tun2socks.xcframework $ xargs xcrun xcodebuild -create-xcframework -output "$@" TUN2SOCKS_VERSION=v1.16.11 +# -w disable DWARF generation LDFLAGS='-static -w -X main.version=$(TUN2SOCKS_VERSION)' ELECTRON_PKG="./client/src/tun2socks/outline/electron" @@ -45,7 +46,7 @@ linux: $(LINUX_BUILDDIR)/tun2socks $(LINUX_BUILDDIR)/tun2socks: mkdir -p "$(@D)" - GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc go build --ldflags=--extldflags=$(LDFLAGS) -o "$@" $(ELECTRON_PKG) + GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC='zig cc -target x86_64-linux' go build --trimpath --ldflags=--extldflags=$(LDFLAGS) -o "$@" $(ELECTRON_PKG) # TODO: build directly when on windows WINDOWS_BUILDDIR=$(BUILDDIR)/windows @@ -54,7 +55,7 @@ windows: $(WINDOWS_BUILDDIR)/tun2socks.exe $(WINDOWS_BUILDDIR)/tun2socks.exe: mkdir -p "$(@D)" - GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build --ldflags=--extldflags=$(LDFLAGS) -o "$@" $(ELECTRON_PKG) + GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build --trimpath --ldflags=--extldflags=$(LDFLAGS) -o "$@" $(ELECTRON_PKG) $(GOMOBILE): go.mod mkdir -p "$(@D)" diff --git a/src/electron/README.md b/src/electron/README.md index 3f0f317513..6aec628d26 100644 --- a/src/electron/README.md +++ b/src/electron/README.md @@ -2,19 +2,6 @@ Unlike the Android and Apple clients, the Windows and Linux clients use the Electron framework, rather than Cordova. -You will need [Docker](https://www.docker.com/) installed to build the Electron clients. - -> If you can't use Docker, you can use [podman](https://podman.io) as substitute by running the following (for macOS): - -```sh -podman machine init -sudo ln -s $(which podman) /usr/local/bin/docker -sudo /opt/homebrew/Cellar/podman//bin/podman-mac-helper install -podman machine start -``` - -> You may run into the error: `/var/folders//xgo-cache: no such file or directory`. If so, simply create that directory with `mkdir -p /var/folders//xgo-cache` and try again. - To build the Electron clients, run (it will also package an installer executable into `build/dist`): ```sh @@ -27,37 +14,21 @@ To run the Electron clients, run: npm run action electron/start [windows|linux] ``` -## Windows +## Cross-Compiling -To build for Windows on a macOS or Linux, you need to first install [MinGW-w64](https://www.mingw-w64.org/) v11.0.1+. +To build the app for a platform target on a different host target, you will need a cross-compiler. We use [zig to cross-compile with cgo](https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho). -With [MacPorts](https://www.mingw-w64.org/downloads/#macports) (official channel): - -```sh -sudo port install x86_64-w64-mingw32-gcc @11.0.1 -``` +[Install zig](https://ziglang.org/learn/getting-started/#installing-zig) and make sure it's in the PATH. -With Homebrew (unofficial, how to ensure consistent version?): +You can download the binary tarball, or use a package manager, like Homebrew: ```sh -brew install mingw-w64 +brew install zig ``` -On Ubuntu: - -```sh -apt update && apt install -y gcc-mingw-w64-x86-64 -``` +## Release To build the _release_ version of Windows installer, you'll also need: - [Java 8+ Runtime](https://www.java.com/en/download/). This is required for the cross-platform Windows executable signing tool [Jsign](https://ebourg.github.io/jsign/). If you don't need to sign the executables, feel free to skip this. -## Linux - -To build for Linux on a macOS, you need to first install the [musl-cross compiler](https://github.com/GregorR/musl-cross). -You can do that with a [Homebrew formula](https://github.com/FiloSottile/homebrew-musl-cross): - -```sh -brew install filosottile/musl-cross/musl-cross -```