Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(client/electron): build cross-platform with zig #1960

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ LINUX_BUILDDIR=$(BUILDDIR)/linux

linux: $(LINUX_BUILDDIR)/tun2socks

$(LINUX_BUILDDIR)/tun2socks: $(XGO)
mkdir -p "$(LINUX_BUILDDIR)/$(IMPORT_PATH)"
$(XGO) -ldflags $(XGO_LDFLAGS) --targets=linux/amd64 -dest "$(LINUX_BUILDDIR)" -pkg $(ELECTRON_PKG) .
mv "$(LINUX_BUILDDIR)/$(IMPORT_PATH)-linux-amd64" "$@"
rm -r "$(LINUX_BUILDDIR)/$(IMPORT_HOST)"
$(LINUX_BUILDDIR)/tun2socks:
mkdir -p "$(@D)"
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc go build --ldflags=--extldflags=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)
jyyi1 marked this conversation as resolved.
Show resolved Hide resolved

# TODO: build directly when on windows
WINDOWS_BUILDDIR=$(BUILDDIR)/windows
Expand All @@ -57,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=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build --ldflags=--extldflags=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)
jyyi1 marked this conversation as resolved.
Show resolved Hide resolved

$(GOMOBILE): go.mod
mkdir -p "$(@D)"
Expand Down
13 changes: 11 additions & 2 deletions src/electron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ npm run action electron/start [windows|linux]

## Windows

To build for Windows on a macOS, you need to first install [MinGW-w64](https://www.mingw-w64.org/) v11.0.1+.
To build for Windows on a macOS or Linux, 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):

Expand All @@ -43,7 +43,7 @@ With Homebrew (unofficial, how to ensure consistent version?):
brew install mingw-w64
jyyi1 marked this conversation as resolved.
Show resolved Hide resolved
```

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

```sh
apt update && apt install -y gcc-mingw-w64-x86-64
Expand All @@ -52,3 +52,12 @@ apt update && apt install -y gcc-mingw-w64-x86-64
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).
jyyi1 marked this conversation as resolved.
Show resolved Hide resolved
You can do that with a [Homebrew formula](https://github.com/FiloSottile/homebrew-musl-cross):

```sh
brew install filosottile/musl-cross/musl-cross
```
Loading