forked from tladesignz/IPtProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·79 lines (64 loc) · 2.36 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
#!/bin/sh
TARGET=ios,iossimulator,macos
OUTPUT=IPtProxy.xcframework
TEMPDIR="$TMPDIR/IPtProxy"
if test "$1" = "android"; then
TARGET=android
OUTPUT=IPtProxy.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
printf '\n\n--- Prepare build environment at %s...\n' "$TEMPDIR"
CURRENT=$PWD
rm -rf "$TEMPDIR"
mkdir -p "$TEMPDIR"
cp -a IPtProxy.go "$TEMPDIR/"
# Fetch submodules lyrebird and snowflake.
printf '\n\n--- Fetching Lyrebird and Snowflake 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 lyrebird || exit 1
git reset --hard
cp -a . "$TEMPDIR/lyrebird"
cd ../snowflake || exit 1
git reset --hard
cp -a . "$TEMPDIR/snowflake"
cd ..
else
# No .git directory - That's a normal install.
git clone https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird.git "$TEMPDIR/lyrebird"
cd "$TEMPDIR/lyrebird" || exit 1
git checkout --force --quiet aab4891
git clone https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git "$TEMPDIR/snowflake"
cd "$TEMPDIR/snowflake" || exit 1
git checkout --force --quiet 05a9580
cd "$CURRENT" || exit 1
fi
# Apply patches.
printf '\n\n--- Apply patches to Lyrebird and Snowflake...\n'
patch --directory="$TEMPDIR/lyrebird" --strip=1 < lyrebird.patch
patch --directory="$TEMPDIR/snowflake" --strip=1 < snowflake.patch
# Compile framework.
printf '\n\n--- Compile %s...\n' "$OUTPUT"
export PATH=~/go/bin:$PATH
cd "$TEMPDIR/IPtProxy.go" || exit 1
gomobile init
MACOSX_DEPLOYMENT_TARGET=11.0 gomobile bind -target=$TARGET -ldflags="-s -w" -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 "$TEMPDIR"
printf '\n\n--- Done.\n\n'