forked from abbasnaqdi/nekoray-macos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nekoray_macos_builder.sh
145 lines (116 loc) · 4.18 KB
/
nekoray_macos_builder.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
set -e
# Clone or update repositories
clone_or_update_with_tag() {
local repo="$1"
local url="$2"
if [ -d "$repo" ]; then
git -C "$repo" reset --hard
git -C "$repo" fetch --all --tags --prune
else
git clone --recursive "$url" "$repo"
fi
if [ -n "$(git -C "$repo" tag --list)" ]; then
git -C "$repo" checkout "$(git -C "$repo" describe --tags $(git -C "$repo" rev-list --tags --max-count=1))"
fi
}
clone_or_update_with_tag "nekoray" "https://github.com/MatsuriDayo/nekoray.git"
clone_or_update_with_tag "v2ray-core" "https://github.com/MatsuriDayo/v2ray-core.git"
# Install dependencies if they are not already installed
command -v "brew" >/dev/null 2>&1 || {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
check_and_install() {
local cmd="$1"
local package="$2"
command -v "$cmd" >/dev/null 2>&1 || {
echo "$cmd could not be found, installing $package"
brew install "$package"
}
}
check_and_install "cmake" "cmake"
check_and_install "ninja" "ninja"
check_and_install "go" "go"
check_and_install "curl" "curl"
check_and_install "macdeployqt" "qt@5"
# Set environment variables
export PATH="/usr/local/opt/qt@5/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/qt@5/lib"
export CPPFLAGS="-I/usr/local/opt/qt@5/include"
export PKG_CONFIG_PATH="/usr/local/opt/qt@5/lib/pkgconfig"
export MACOSX_DEPLOYMENT_TARGET="10.9"
nRoot="$(pwd)"
nPath="$(pwd)/nekoray"
# Create or clean build directory
if [ ! -d "$nPath/build" ]; then
mkdir -p "$nPath/build"
else
read -p "Do you want to clean 'build' and 'libs/deps' directories ? [y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
rm -rf "$nPath/libs/deps"
rm -rf "$nPath/build"
mkdir -p "$nPath/build"
fi
# Get and Build dependencies
bash build_deps_all.sh
cd "$nPath/build"
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DNKR_PACKAGE_MACOS=1 ..
ninja
cd $nPath
nApp=$nPath/build/nekoray.app
# Deploy frameworks using macdeployqt
for arch in "amd64" "arm64"; do
macdeployqt "$nApp" -verbose=1
done
# Download data files for both amd64 and arm64
curl -fLso $nApp/Contents/MacOS/geoip.dat "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
curl -fLso $nApp/Contents/MacOS/geosite.dat "https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat"
curl -fLso $nApp/Contents/MacOS/geoip.db "https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db"
curl -fLso $nApp/Contents/MacOS/geosite.db "https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db"
# copy fa_IR.qm and zh_CN.qm to nekoray.app/Contents/MacOS
for file in "fa_IR.qm" "zh_CN.qm"; do
cp "$nPath/build/$file" "$nApp/Contents/MacOS"
done
# Build nekoray for both amd64 and arm64
for arch in "amd64" "arm64"; do
rm -rf "$nPath/build/nekoray_$arch.app"
cp -r $nApp "$nPath/build/nekoray_$arch.app"
done
rm -rf $nApp
neko_common="github.com/matsuridayo/libneko/neko_common"
cd $nRoot/v2ray-core
version_v2ray=$(git log --pretty=format:'%h' -n 1)
cd $nPath
version_standalone="nekoray-"$(cat $nPath/nekoray_version.txt)
# Build nekobox_core and nekoray_core for both amd64 and arm64
for cmd in "nekobox_core" "nekoray_core"; do
for arch in "amd64" "arm64"; do
cd "$nPath/go/cmd/$cmd"
GOARCH="$arch"
if [ "$cmd" = "nekoray_core" ]; then
go build -o "${cmd}_${arch}" -trimpath -ldflags "-w -s -X $neko_common.Version_v2ray=$version_v2ray -X $neko_common.Version_neko=$version_standalone"
else
go build -o "${cmd}_${arch}" -trimpath -ldflags "-w -s -X $neko_common.Version_neko=$version_standalone" -tags "with_grpc,with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api"
fi
cp "${cmd}_${arch}" "$nPath/build/nekoray_$arch.app/Contents/MacOS/$cmd"
done
done
#zip nekoray by arch
if [ -n "$GITHUB_ACTIONS" ]; then
for arch in "amd64" "arm64"; do
TEMP_PATH=$(pwd)
cd "$nPath/build"
zip -r "nekoray_$arch.zip" "nekoray_$arch.app"
cd "$TEMP_PATH"
done
else
for arch in "amd64" "arm64"; do
zip -r "$nPath/build/nekoray_$arch.zip" "$nPath/build/nekoray_$arch.app"
done
fi
echo "Build finished and output files are in $nPath/build"
cd "$nPath"
open "$nPath/build"