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): use Taskfile for tun2socks #1967

Merged
merged 16 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.idea
.task
.vs/
.vscode
*.DS_Store
Expand Down
69 changes: 0 additions & 69 deletions Makefile

This file was deleted.

13 changes: 13 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'

set: [pipefail]

run: when_changed

includes:
client:tun2socks: ./client/src/tun2socks/Taskfile.yml
Copy link
Contributor

@daniellacosse daniellacosse Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self that we'll need to change this to "backend" if that other PR is merged


tasks:
clean:
deps:
- client:tun2socks:clean
111 changes: 111 additions & 0 deletions client/src/tun2socks/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
version: '3'

vars:
# This needs to be updated if the file moves.
REPO_ROOT: '{{joinPath .TASKFILE_DIR "../../.."}}'
# TODO: Output to $REPO_ROOT/output/client/tun2socks instead.
OUT_DIR: '{{joinPath .REPO_ROOT "client/output/build"}}'
BIN_DIR: "{{.OUT_DIR}}/build"
MOBILE_PKG: "{{.TASKFILE_DIR}}/outline/tun2socks"
GOMOBILE_BIND_CMD: "env PATH=\"{{.BIN_DIR}}:${PATH}\" '{{.BIN_DIR}}/gomobile' bind -ldflags='-s -w'"

tasks:
electron:
desc: "Build the tun2socks binary for Electron platforms"
internal: true
requires: {vars: [TARGET_OS]}
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}}'
cmds:
- rm -rf "{{dir .OUTPUT}}" && mkdir -p "{{dir .OUTPUT}}"
# 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.
- |
{{if ne OS "{{.TARGET_OS}}" -}}
GOOS={{.TARGET_OS}} GOARCH=amd64 CGO_ENABLED=1 CC='zig cc -target x86_64-{{.TARGET_OS}}'
{{- end}} \
go build -trimpath -ldflags="-s -w -X=main.version={{.TUN2SOCKS_VERSION}}" -o '{{.OUTPUT}}' '{{.TASKFILE_DIR}}/outline/electron'

windows:
desc: "Build the tun2socks binary for Windows"
cmds: [{task: electron, vars: {TARGET_OS: "windows"}}]

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

android:
desc: "Build the tun2socks.aar library for Android"
vars:
TARGET_DIR: "{{.OUT_DIR}}/android"
# ANDROID_API must match the minSdkVersion that the Android client supports.
ANDROID_API: 22
preconditions:
- sh: '[[ -d "$ANDROID_HOME" ]]'
msg: "Must set ANDROID_HOME"
- sh: '[[ -d "$ANDROID_NDK" ]]'
msg: "Must set ANDROID_NDK"
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
- "{{.GOMOBILE_BIND_CMD}} -target=android -androidapi '{{.ANDROID_API}}' -o '{{.TARGET_DIR}}/tun2socks.aar' '{{.TASKFILE_DIR}}/outline/tun2socks' '{{.TASKFILE_DIR}}/outline/shadowsocks'"
deps: ["gomobile"]

ios-only:
desc: "Build the Tun2socks.xcframework library for iOS only"
internal: true
vars:
TARGET_DIR: '{{.OUT_DIR}}/ios'
# TARGET_IOS_VERSION must match the target version that the iOS client supports.
TARGET_IOS_VERSION: 12.0
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
- "{{.GOMOBILE_BIND_CMD}} -target=ios,iossimulator -iosversion={{.TARGET_IOS_VERSION}} -bundleid org.outline.tun2socks -o '{{.TARGET_DIR}}/Tun2socks.xcframework' '{{.TASKFILE_DIR}}/outline/tun2socks' '{{.TASKFILE_DIR}}/outline/shadowsocks'"
deps: ["gomobile"]

macos-only:
desc: "Build the Tun2socks.xcframework library for macOS only"
internal: true
vars:
TARGET_DIR: '{{.OUT_DIR}}/macos'
# MACOSX_DEPLOYMENT_TARGET must match the version the version set in the XCode project.
MACOSX_DEPLOYMENT_TARGET: 10.14
# TARGET_IOS_VERSION must be at least 13.1 for macCatalyst and >= the iOS TARGET_IOS_VERSION.
TARGET_IOS_VERSION: 13.1
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
- export MACOSX_DEPLOYMENT_TARGET={{.MACOSX_DEPLOYMENT_TARGET}}; {{.GOMOBILE_BIND_CMD}} -target=macos,maccatalyst -iosversion={{.TARGET_IOS_VERSION}} -bundleid org.outline.tun2socks -o '{{.TARGET_DIR}}/Tun2socks.xcframework' '{{.TASKFILE_DIR}}/outline/tun2socks' '{{.TASKFILE_DIR}}/outline/shadowsocks'
deps: ["gomobile"]

apple:
desc: "Build combined Tun2socks.xcframework library for Apple platforms"
aliases: [ios, macos, maccatalyst]
vars:
TARGET_DIR: '{{.OUT_DIR}}/apple'
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
- |
find '{{.OUT_DIR}}/macos/Tun2socks.xcframework' '{{.OUT_DIR}}/ios/Tun2socks.xcframework' -name "Tun2socks.framework" -type d |
xargs -I {} echo " -framework {} " |
xargs xcrun xcodebuild -create-xcframework -output '{{.TARGET_DIR}}/Tun2socks.xcframework'
deps: ["ios-only", "macos-only"]

browser:
desc: "Placeholder for the browser build. Does nothing"

gomobile:
desc: "Build Go Mobile"
internal: true
cmds:
- mkdir -p "{{.BIN_DIR}}"
- go build -o "{{.BIN_DIR}}" golang.org/x/mobile/cmd/gomobile golang.org/x/mobile/cmd/gobind
sources: ["{{.REPO_ROOT}}/go.sum"]
generates: ["{{.BIN_DIR}}/gomobile", "{{.BIN_DIR}}/gobind"]

clean:
cmds:
- rm -r '{{.OUT_DIR}}'
- go clean -i -r '{{.TASKFILE_DIR}}/outline/tun2socks' '{{.TASKFILE_DIR}}/outline/shadowsocks'
20 changes: 1 addition & 19 deletions client/src/tun2socks/build.action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

import url from 'url';
import os from 'os';
import {spawnStream} from '../../../src/build/spawn_stream.mjs';
import {getBuildParameters} from '../build/get_build_parameters.mjs';

Expand All @@ -24,24 +23,7 @@ import {getBuildParameters} from '../build/get_build_parameters.mjs';
*/
export async function main(...parameters) {
const {platform: targetPlatform} = getBuildParameters(parameters);

const currentPlatform = os.platform() === 'win32' ? 'windows' : os.platform();

if (targetPlatform === 'browser') {
return;
}

if (targetPlatform === currentPlatform && ['linux', 'windows'].includes(targetPlatform)) {
return spawnStream(
'go',
'build',
'-o',
`output/build/${targetPlatform}/tun2socks${targetPlatform === 'windows' ? '.exe' : ''}`,
'github.com/Jigsaw-Code/outline-apps/client/src/tun2socks/outline/electron'
);
}

await spawnStream('make', ['ios', 'macos', 'maccatalyst'].includes(targetPlatform) ? 'apple' : targetPlatform);
await spawnStream('go', 'run', 'github.com/go-task/task/v3/cmd/task', '-v', `client:tun2socks:${targetPlatform}`);
}

if (import.meta.url === url.pathToFileURL(process.argv[1]).href) {
Expand Down
31 changes: 23 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
module github.com/Jigsaw-Code/outline-apps

go 1.20
go 1.21

require (
github.com/Jigsaw-Code/outline-sdk v0.0.14-0.20240216220040-f741c57bf854
github.com/Jigsaw-Code/outline-sdk/x v0.0.0-20240223000159-142376ee10ea
github.com/crazy-max/xgo v0.30.0
github.com/eycorsican/go-tun2socks v1.16.11
github.com/stretchr/testify v1.8.2
github.com/go-task/task/v3 v3.36.0
github.com/stretchr/testify v1.9.0
golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a
golang.org/x/sys v0.15.0
golang.org/x/sys v0.19.0
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-zglob v0.0.4 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/radovskyb/watcher v1.0.7 // indirect
github.com/sajari/fuzzy v1.0.0 // indirect
github.com/shadowsocks/go-shadowsocks2 v0.1.5 // indirect
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 // indirect
golang.org/x/crypto v0.17.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/tools v0.16.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mvdan.cc/sh/v3 v3.8.0 // indirect
)
Loading
Loading