-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·92 lines (75 loc) · 2.63 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
set -eo pipefail
TARGET=ios,iossimulator,macos
OUTPUT=IEnvoyProxy.xcframework
# test if TMPDIR is unset: https://stackoverflow.com/a/13864829
if [[ -z ${TMPDIR} ]]; then
# macOS
TMPDIR=$(mktemp -dq)
else
# Linux
TMPDIR="${TMPDIR}IEnvoyProxy"
mkdir ${TMPDIR} || true
fi
# TMPDIR may be unbound until now
set -u
# echo "TMPDIR: ${TMPDIR}"
if test "${1:-ios}" = "android"; then
TARGET=android
OUTPUT=IEnvoyProxy.aar
fi
cd "$(dirname "$0")" || exit 1
if test -e $OUTPUT; then
echo "--- No build necessary, $OUTPUT already exists."
exit
fi
# Install dependencies. Go itself is a prerequisite.
printf '\n--- Golang 1.21 or up needs to be installed! Try "brew install go" on MacOS or "snap install go" on Linux if we fail further down!'
printf '\n--- Installing gomobile...\n'
go install golang.org/x/mobile/cmd/gomobile@latest
# Prepare build environment
# Go leaks the build path in to the binary, so use a temp dir to build
# based on https://github.com/tladesignz/IPtProxy/pull/38
printf '\n\n--- Prepare build environment at %s...\n' "$TMPDIR"
CURRENT=$PWD
rm -rf "$TMPDIR" || true
mkdir -p "$TMPDIR"
cp -a IEnvoyProxy "$TMPDIR/"
# Fetch submodules.
printf '\n\n--- Fetching submodule dependencies...\n'
if test -e ".git"; then
# There's a .git directory - we must be in the development pod.
git submodule update --init --recursive
cd hysteria || exit 1
git reset --hard
cp -a . "$TMPDIR/hysteria"
cd ../v2ray-core || exit 1
git reset --hard
git clean -fd # we add a file
cp -a . "$TMPDIR/v2ray-core"
cd ..
else
# No .git directory - That's a normal install.
git clone --recursive --shallow-submodules --depth 1 --branch "234dc45" https://github.com/apernet/hysteria.git "$TMPDIR/hysteria"
git clone --recursive --shallow-submodules --depth 1 --branch "49b50686" https://github.com/v2fly/v2ray-core.git "$TMPDIR/v2ray-core"
fi
# Apply patches.
printf '\n\n--- Apply patches to submodules...\n'
pwd
patch --directory="$TMPDIR/hysteria" --strip=1 < hysteria.patch
patch --directory="$TMPDIR/v2ray-core" --strip=1 < v2ray-core.patch
# Compile framework.
printf '\n\n--- Compile %s...\n' "$OUTPUT"
export PATH=~/go/bin:$PATH
cd "$TMPDIR/IEnvoyProxy" || exit 1
gomobile init
MACOSX_DEPLOYMENT_TARGET=11.0 gomobile bind -target=$TARGET -ldflags="-s -w -checklinkname=0" -o "$CURRENT/$OUTPUT" -iosversion=12.0 -androidapi=21 -v -tags=netcgo -trimpath
### Note:
# $ go tool link -h
# -s disable symbol table
# -w disable DWARF generation
#
# -> Saves > 50% of file size on all targets!
# See https://github.com/guardianproject/orbot/pull/1061
rm -rf "$TMPDIR"
printf '\n\n--- Done.\n\n'