Skip to content

Commit

Permalink
Build linux with musl-cross
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Apr 6, 2024
1 parent 29d2f2b commit 2433e31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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)

# 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)

$(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
```

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).
You can do that with a [Homebrew formula](https://github.com/FiloSottile/homebrew-musl-cross):

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

0 comments on commit 2433e31

Please sign in to comment.