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 9 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.

8 changes: 8 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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

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

vars:
# This needs to be updated if the file moves.
# TODO: Output to $REPO_ROOT/output/client/tun2socks instead.
OUT_DIR: '{{joinPath .TASKFILE_DIR "../../output/build"}}'
BIN_DIR: "{{.OUT_DIR}}/build"
VERSION: "v1.16.11"
# 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.
ELECTRON_BUILD_FLAGS: -trimpath -ldflags="-s -w -X=main.version={{.VERSION}}"
ELECTRON_MAIN_PKG: "{{.TASKFILE_DIR}}/outline/electron"
MOBILE_PKG: "{{.TASKFILE_DIR}}/outline/tun2socks"
GOMOBILE_BIND_CMD: "env PATH=\"{{.BIN_DIR}}:${PATH}\" '{{.BIN_DIR}}/gomobile' bind -ldflags='-s -w'"

tasks:
windows:
desc: "Build the tun2socks binary for Windows"
vars:
TARGET_DIR: "{{.OUT_DIR}}/windows"
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
- |
{{if ne OS "windows"}}GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC='zig cc -target x86_64-windows' {{end}}go build {{.ELECTRON_BUILD_FLAGS}} -o '{{.TARGET_DIR}}/tun2socks.exe' '{{.ELECTRON_MAIN_PKG}}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we can space this out to make it more readable? ie

{{if ne OS "windows"}}
  GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC='zig cc -target x86_64-windows' \
{{end}}
go build {{.ELECTRON_BUILD_FLAGS}} -o '{{.TARGET_DIR}}/tun2socks.exe' '{{.ELECTRON_MAIN_PKG}}'

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe it makes sense to load env or taskfiles based on the environment in a "setup environment" task

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did the reformatting you suggested.


linux:
desc: "Build the tun2socks binary for Linux"
vars:
TARGET_DIR: '{{.OUT_DIR}}/linux'
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
- |
{{if ne OS "linux"}}GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC='zig cc -target x86_64-linux' {{end}}go build {{.ELECTRON_BUILD_FLAGS}} -o '{{.TARGET_DIR}}/tun2socks' '{{.ELECTRON_MAIN_PKG}}'

android:
desc: "Build the tun2socks.aar library for Android"
vars:
TARGET_DIR: "{{.OUT_DIR}}/android"
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}}"
# -androidapi should match the minSdkVersion that the Android client supports.
Copy link
Contributor

Choose a reason for hiding this comment

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

should we hoist the androidapi into a var?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like that, it's cleaner. Done.

- "{{.GOMOBILE_BIND_CMD}} -target=android -androidapi 22 -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'
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
# -iosversion should match the target version that the iOS client supports.
Copy link
Contributor

Choose a reason for hiding this comment

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

same with iosversion

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

- "{{.GOMOBILE_BIND_CMD}} -target=ios,iossimulator -iosversion=12.0 -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'
cmds:
- rm -rf "{{.TARGET_DIR}}" && mkdir -p "{{.TARGET_DIR}}"
# MACOSX_DEPLOYMENT_TARGET and -iosversion should match the versions that the macOS client supports.
- export MACOSX_DEPLOYMENT_TARGET=10.14; {{.GOMOBILE_BIND_CMD}} -target=macos,maccatalyst -iosversion=13.1 -bundleid org.outline.tun2socks -o '{{.TARGET_DIR}}/Tun2socks.xcframework' '{{.TASKFILE_DIR}}/outline/tun2socks' '{{.TASKFILE_DIR}}/outline/shadowsocks'
Copy link
Contributor

Choose a reason for hiding this comment

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

and macosx deployment target

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

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 "{{.REPO_ROOT}}/output/client/tun2socks" .task
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add this clean to the root package.json clean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. Done.

- 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
30 changes: 23 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
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