-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·298 lines (245 loc) · 8.04 KB
/
install.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash
ARCH_X64=("x64" "x86_64" "amd64")
ARCH_X86=("x86" "i386" "i486" "i586" "i686")
ARCH_ARM=("arm" "armel" "armhf")
ARCH_ARM64=("arm64" "aarch64")
BIN_DEPS=("git" "wget" "tar" "python3" "gcc" "g++")
LIB_DEPS=("egl" "gl" "glesv2" "harfbuzz" "icu-uc" "fontconfig" "freetype2" "zlib" "libpng" "libwebp" "libjpeg")
help() {
echo -e "\nUsage: SK_ARCH=ARCH SK_PREFIX=PREFIX SK_LIBDIR=LIBDIR SK_INCDIR=INCDIR $0"
echo -e "Where:"
echo -e "- ARCH: Target CPU architecture. Supported values:"
echo -e " x64 or alias [x86_64, amd64]"
echo -e " x86 or alias [i386, i486, i586, i686]"
echo -e " arm or alias [armel, armhf]"
echo -e " arm64 or alias [aarch64]"
echo -e "- PREFIX: Install prefix path. For example SK_PREFIX=/"
echo -e "- LIBDIR: Libraries install path relative to SK_PREFIX. For example SK_LIBDIR=/usr/lib -> final path SK_PREFIX/usr/lib/Skia"
echo -e "- INCDIR: Headers install path relative to SK_PREFIX. For example SK_INCDIR=/usr/include -> final path SK_PREFIX/usr/include/Skia\n"
}
summary() {
echo -e "\n**************************** SUMMARY ****************************\n"
echo " Skia Version: $SK_VERSION"
echo " Target Arch: $SK_ARCH"
echo " Install Prefix: $SK_PREFIX"
echo " Final Library Install Path: $SK_FINAL_LIBDIR"
echo " Final Headers Install Path: $SK_FINAL_INCDIR"
echo " Final PKGCONFIG File Install Path: $SK_FINAL_PKG_DIR"
echo -e "\n*****************************************************************\n"
}
concat_paths() {
local path1="$1"
local path2="$2"
# Remove any trailing slash from the first path
path1="${path1%/}"
# Remove any leading slash from the second path
path2="${path2#/}"
# Concatenate the paths
echo "$path1/$path2"
}
in_array() {
local element
for element in "${@:2}"; do
if [[ "$element" == "$1" ]]; then
return 0
fi
done
return 1
}
# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SK_VERSION=$(cat $SCRIPT_DIR/VERSION)
if [ -z "${SK_PREFIX}" ]; then
echo -e "\nError: Missing install prefix."
help
exit 1
else
if [[ "$SK_PREFIX" != /* ]]; then
echo -e "\nError: The install prefix must be an absolute path."
help
exit 1
fi
fi
mkdir -p $SK_PREFIX
if [ -z "${SK_LIBDIR}" ]; then
echo -e "\nError: Missing library install path."
help
exit 1
else
if [[ "$SK_LIBDIR" != /* ]]; then
echo -e "\nError: SK_LIBDIR must start with /"
help
exit 1
fi
fi
if [ -z "${SK_INCDIR}" ]; then
echo -e "\nError: Missing headers install path."
help
exit 1
else
if [[ "$SK_INCDIR" != /* ]]; then
echo -e "\nError: SK_INCDIR must start with /"
help
exit 1
fi
fi
if [ -z "${SK_ARCH}" ]; then
echo -e "\nError: Missing target CPU arch."
help
exit 1
else
TEST_ARCH=""
if in_array "$SK_ARCH" "${ARCH_X64[@]}"; then
TEST_ARCH="x64"
fi
if [ -z "$TEST_ARCH" ] && in_array "$SK_ARCH" "${ARCH_X86[@]}"; then
TEST_ARCH="x86"
fi
if [ -z "$TEST_ARCH" ] && in_array "$SK_ARCH" "${ARCH_ARM[@]}"; then
TEST_ARCH="arm"
fi
if [ -z "$TEST_ARCH" ] && in_array "$SK_ARCH" "${ARCH_ARM64[@]}"; then
TEST_ARCH="arm64"
fi
if [ -z "$TEST_ARCH" ]; then
echo -e "\nError: Invalid CPU arch: $SK_ARCH."
help
exit 1
fi
SK_ARCH=$TEST_ARCH
fi
# Check dependencies
echo -e "\nChecking binary dependencies:"
for DEP in "${BIN_DEPS[@]}"; do
if command -v "$DEP" > /dev/null 2>&1; then
echo " Found $DEP."
else
echo "Error: $DEP not found."
exit 1
fi
done
echo -e "\nChecking library dependencies:"
for DEP in "${LIB_DEPS[@]}"; do
if pkg-config --exists "$DEP"; then
echo " Found $DEP."
else
echo "Error: $DEP not found."
exit 1
fi
done
# Summary
SK_FINAL_LIBDIR=$(concat_paths $SK_PREFIX $SK_LIBDIR)
SK_FINAL_PKG_DIR=$(concat_paths $SK_FINAL_LIBDIR "/pkgconfig")
SK_FINAL_LIBDIR=$(concat_paths $SK_FINAL_LIBDIR "/Skia")
SK_FINAL_INCDIR=$(concat_paths $SK_PREFIX $SK_INCDIR)
SK_FINAL_INCDIR=$(concat_paths $SK_FINAL_INCDIR "/Skia")
mkdir -p $SK_FINAL_INCDIR
mkdir -p $SK_FINAL_LIBDIR
mkdir -p $SK_FINAL_PKG_DIR
summary
TMP_DIR=${SCRIPT_DIR}/tmp
mkdir -p ${TMP_DIR}/build
mkdir -p ${TMP_DIR}/include
cd ${TMP_DIR}/build
if [ ! -e "$TMP_DIR/build/depot_tools" ]; then
git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
else
echo -e "\ndepot_tools already cloned, skipping..."
fi
export PATH="${PWD}/depot_tools:${PATH}"
if [ ! -e "$TMP_DIR/build/$SK_VERSION.tar.gz" ]; then
wget https://github.com/google/skia/archive/refs/tags/canvaskit/$SK_VERSION.tar.gz
tar -xvf $SK_VERSION.tar.gz
else
echo -e "\n$SK_VERSION.tar.gz already downloaded, skipping..."
fi
cd skia-canvaskit-$SK_VERSION
# For some reason this sometimes fails the first time
max_retries=5
attempt=0
if [ ! -e "$TMP_DIR/build/skia-canvaskit-$SK_VERSION/bin/gn" ]; then
until python3 tools/git-sync-deps; do
attempt=$((attempt+1))
if [ $attempt -ge $max_retries ]; then
echo "tools/git-sync-deps failed after $max_retries attempts."
break
fi
echo "tools/git-sync-deps failed. Retrying ($attempt/$max_retries)..."
done
else
echo -e "\nbin/gn already downloaded, skipping..."
fi
bin/gn gen out/Shared --args='
target_os="linux"
target_cpu="'$SK_ARCH'"
cc="gcc"
cxx="g++"
is_debug=false
is_official_build=true
is_component_build=true
text_tests_enabled=false
skia_compile_modules=true
skia_compile_sksl_tests=false
skia_enable_tools=false
skia_enable_gpu=true
skia_enable_fontmgr_custom_directory=false
skia_enable_sksl=true
skia_enable_skshaper=true
skia_enable_svg=true
skia_enable_pdf=false
skia_use_harfbuzz=true skia_use_system_harfbuzz=true
skia_use_icu=true skia_use_system_icu=true
skia_use_freetype=true skia_use_system_freetype2=true
skia_use_zlib=true skia_use_system_zlib=true
skia_use_sfntly=true
skia_use_gl=true
skia_use_egl=true
skia_use_libheif=true
skia_use_system_libpng=true
skia_use_system_libwebp=true
skia_use_system_libjpeg_turbo=true
skia_use_angle=false
skia_use_vulkan=false
skia_use_metal=false
skia_use_direct3d=false
skia_use_dawn=false
skia_use_expat=false
skia_use_ffmpeg=false
skia_use_sfml=false'
ninja -C out/Shared
if [ $? -ne 0 ]; then
echo -e "Error: Skia compilation failed."
exit 1
fi
echo -e "\nInstalling libraries into $SK_FINAL_LIBDIR:"
mkdir -p $SK_FINAL_LIBDIR
cp -v $TMP_DIR/build/skia-canvaskit-$SK_VERSION/out/Shared/*.a $SK_FINAL_LIBDIR
cp -v $TMP_DIR/build/skia-canvaskit-$SK_VERSION/out/Shared/*.so $SK_FINAL_LIBDIR
echo -e "\nInstalling headers into $SK_FINAL_INCDIR:"
mkdir -p $SK_FINAL_INCDIR/include
mkdir -p $SK_FINAL_INCDIR/modules
cd $TMP_DIR/build/skia-canvaskit-$SK_VERSION/include
find . -name "*.h" -exec cp -v --parents {} $SK_FINAL_INCDIR/include \;
cd $TMP_DIR/build/skia-canvaskit-$SK_VERSION/modules
find . -name "*.h" -exec cp -v --parents {} $SK_FINAL_INCDIR/modules \;
# Gen pkgconfig file
cat <<EOF > $TMP_DIR/build/skia-canvaskit-$SK_VERSION/out/Shared/Skia.pc
Name: Skia
Description: Skia is a complete 2D graphic library for drawing Text, Geometries, and Images.
Version: $SK_VERSION
Libs: -L$SK_LIBDIR/Skia -lskia -lskottie -lskparagraph -lcompression_utils_portable -lpathkit -lskcms -lskresources -lskshaper -lskunicode -ldng_sdk -lpiex -lsksg -lsktext -lwuffs
Cflags: -I$SK_INCDIR/Skia -DSK_GL -DSK_GANESH
EOF
echo -e "\nInstalling Skia.pc into $SK_FINAL_PKG_DIR."
cp $TMP_DIR/build/skia-canvaskit-$SK_VERSION/out/Shared/Skia.pc $SK_FINAL_PKG_DIR
cd $SCRIPT_DIR
# Create uninstaller
cat <<EOF > $SCRIPT_DIR/uninstall.sh
#!/bin/bash
rm -rfv $SK_FINAL_LIBDIR
rm -rfv $SK_FINAL_INCDIR
rm -rfv $SK_FINAL_PKG_DIR/Skia.pc
EOF
chmod +x $SCRIPT_DIR/uninstall.sh
summary
echo -e "Installation complete. Use uninstall.sh to remove.\n"