Skip to content

Commit

Permalink
add library build script to Go taskfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Nov 12, 2024
1 parent 9c6a234 commit 3c607ed
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions client/go/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,45 @@ vars:

tasks:
electron:
desc: "Build the tun2socks binary for Electron platforms"
desc: "Build the tun2socks binary and library for Electron platforms"
internal: true
requires: {vars: [TARGET_OS]}
requires: {vars: [TARGET_OS, TARGET_ARCH]}
vars:
# TODO(fortuna): remove this, it's not really needed since we don't release it separately anymore.
TUN2SOCKS_VERSION: "v1.16.11"
OUTPUT: '{{.OUT_DIR}}/{{.TARGET_OS}}/tun2socks{{if eq .TARGET_OS "windows"}}.exe{{end}}'
# Linux=libbackend.so; Windows=backend.dll
OUTPUT_LIB: '{{.OUT_DIR}}/{{.TARGET_OS}}/{{if eq .TARGET_OS "linux"}}libbackend.so{{else}}backend.dll{{end}}'
cmds:
- rm -rf "{{dir .OUTPUT}}" && mkdir -p "{{dir .OUTPUT}}"
# C cross-compile (zig) targets:
# Linux (x64) = x86_64-linux-gnu (`x86_64-linux` defaults to `x86_64-linux-musl`, prefer `gnu` over `musl`)
# Windows (x86) = x86-windows
# Linker flags: https://pkg.go.dev/cmd/link
# -s Omit the symbol table and debug information.
# -w Omit the DWARF symbol table.
# -X Set the value of the string variable.
# -s Omit the symbol table and debug information.
# -w Omit the DWARF symbol table.
# -X Set the value of the string variable.
- |
{{if ne OS .TARGET_OS -}}
GOOS={{.TARGET_OS}} GOARCH=amd64 CGO_ENABLED=1 CC='zig cc -target x86_64-{{.TARGET_OS}}'
{{if or (ne OS .TARGET_OS) (ne ARCH .TARGET_ARCH) -}}
GOOS={{.TARGET_OS}} GOARCH={{.TARGET_ARCH}} CGO_ENABLED=1 \
CC='zig cc -target {{if eq .TARGET_ARCH "386"}}x86{{else}}x86_64{{end}}-{{.TARGET_OS}}{{if eq .TARGET_OS "linux"}}-gnu{{end}}'
{{- end}} \
go build -trimpath -ldflags="-s -w -X=main.version={{.TUN2SOCKS_VERSION}}" -o '{{.OUTPUT}}' '{{.TASKFILE_DIR}}/outline/electron'
- |
{{if or (ne OS .TARGET_OS) (ne ARCH .TARGET_ARCH) -}}
GOOS={{.TARGET_OS}} GOARCH={{.TARGET_ARCH}} CGO_ENABLED=1 \
CC='zig cc -target {{if eq .TARGET_ARCH "386"}}x86{{else}}x86_64{{end}}-{{.TARGET_OS}}{{if eq .TARGET_OS "linux"}}-gnu{{end}}'
{{- end}} \
go build -trimpath -buildmode=c-shared -ldflags="-s -w -X=main.version={{.TUN2SOCKS_VERSION}}" -o '{{.OUTPUT_LIB}}' '{{.TASKFILE_DIR}}/outline/electron'
windows:
desc: "Build the tun2socks binary for Windows"
cmds: [{task: electron, vars: {TARGET_OS: "windows"}}]
desc: "Build the tun2socks binary and library for Windows"
# 32bit Windows 10 still exists until October 14, 2025
cmds: [{task: electron, vars: {TARGET_OS: "windows", TARGET_ARCH: "386"}}]

linux:
desc: "Build the tun2socks binary for Linux"
cmds: [{task: electron, vars: {TARGET_OS: "linux"}}]
desc: "Build the tun2socks binary and library for Linux"
cmds: [{task: electron, vars: {TARGET_OS: "linux", TARGET_ARCH: "amd64"}}]

android:
desc: "Build the tun2socks.aar library for Android"
Expand Down

0 comments on commit 3c607ed

Please sign in to comment.