From 2433e31f3d5be1ade97895d20d7ae398061a5816 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Fri, 5 Apr 2024 20:11:35 -0400 Subject: [PATCH] Build linux with musl-cross --- Makefile | 10 ++++------ src/electron/README.md | 13 +++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index d19085aaf1..a179ef2ba1 100644 --- a/Makefile +++ b/Makefile @@ -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) # TODO: build directly when on windows WINDOWS_BUILDDIR=$(BUILDDIR)/windows @@ -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) $(GOMOBILE): go.mod mkdir -p "$(@D)" diff --git a/src/electron/README.md b/src/electron/README.md index 5db4ed4306..3f0f317513 100644 --- a/src/electron/README.md +++ b/src/electron/README.md @@ -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): @@ -43,7 +43,7 @@ With Homebrew (unofficial, how to ensure consistent version?): brew install mingw-w64 ``` -You can also build it on Ubuntu. To install MinGW-w64: +On Ubuntu: ```sh apt update && apt install -y gcc-mingw-w64-x86-64 @@ -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). +You can do that with a [Homebrew formula](https://github.com/FiloSottile/homebrew-musl-cross): + +```sh +brew install filosottile/musl-cross/musl-cross +```