-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathlinux_build.sh
executable file
·547 lines (495 loc) · 15.6 KB
/
linux_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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
#!/bin/bash
set -e
# Default value for arguments
appimage_build=0
num_processors=$(nproc)
publisher_name="Third Party Publisher"
publisher_website=""
publisher_issue_url="https://app.lizardbyte.dev/support"
skip_cleanup=0
skip_cuda=0
skip_libva=0
skip_package=0
sudo_cmd="sudo"
ubuntu_test_repo=0
function _usage() {
local exit_code=$1
cat <<EOF
This script installs the dependencies and builds the project.
The script is intended to be run on a Debian-based or Fedora-based system.
Usage:
$0 [options]
Options:
-h, --help Display this help message.
-s, --sudo-off Disable sudo command.
--appimage-build Compile for AppImage, this will not create the AppImage, just the executable.
--num-processors The number of processors to use for compilation. Default is the value of 'nproc'.
--publisher-name The name of the publisher (not developer) of the application.
--publisher-website The URL of the publisher's website.
--publisher-issue-url The URL of the publisher's support site or issue tracker.
If you provide a modified version of Sunshine, we kindly request that you use your own url.
--skip-cleanup Do not restore the original gcc alternatives, or the math-vector.h file.
--skip-cuda Skip CUDA installation.
--skip-libva Skip libva installation. This will automatically be enabled if passing --appimage-build.
--skip-package Skip creating DEB, or RPM package.
--ubuntu-test-repo Install ppa:ubuntu-toolchain-r/test repo on Ubuntu.
EOF
exit "$exit_code"
}
# Parse named arguments
while getopts ":hs-:" opt; do
case ${opt} in
h ) _usage 0 ;;
s ) sudo_cmd="" ;;
- )
case "${OPTARG}" in
help) _usage 0 ;;
appimage-build)
appimage_build=1
skip_libva=1
;;
num-processors=*)
num_processors="${OPTARG#*=}"
;;
publisher-name=*)
publisher_name="${OPTARG#*=}"
;;
publisher-website=*)
publisher_website="${OPTARG#*=}"
;;
publisher-issue-url=*)
publisher_issue_url="${OPTARG#*=}"
;;
skip-cleanup) skip_cleanup=1 ;;
skip-cuda) skip_cuda=1 ;;
skip-libva) skip_libva=1 ;;
skip-package) skip_package=1 ;;
sudo-off) sudo_cmd="" ;;
ubuntu-test-repo) ubuntu_test_repo=1 ;;
*)
echo "Invalid option: --${OPTARG}" 1>&2
_usage 1
;;
esac
;;
\? )
echo "Invalid option: -${OPTARG}" 1>&2
_usage 1
;;
esac
done
shift $((OPTIND -1))
# dependencies array to build out
dependencies=()
function add_debain_based_deps() {
dependencies+=(
"bison" # required if we need to compile doxygen
"build-essential"
"cmake"
"doxygen"
"flex" # required if we need to compile doxygen
"gcc-${gcc_version}"
"g++-${gcc_version}"
"git"
"graphviz"
"libcap-dev" # KMS
"libcurl4-openssl-dev"
"libdrm-dev" # KMS
"libevdev-dev"
"libminiupnpc-dev"
"libnotify-dev"
"libnuma-dev"
"libopus-dev"
"libpulse-dev"
"libssl-dev"
"libwayland-dev" # Wayland
"libx11-dev" # X11
"libxcb-shm0-dev" # X11
"libxcb-xfixes0-dev" # X11
"libxcb1-dev" # X11
"libxfixes-dev" # X11
"libxrandr-dev" # X11
"libxtst-dev" # X11
"ninja-build"
"npm" # web-ui
"udev"
"wget" # necessary for cuda install with `run` file
"xvfb" # necessary for headless unit testing
)
if [ "$skip_libva" == 0 ]; then
dependencies+=(
"libva-dev" # VA-API
)
fi
}
function add_debain_deps() {
add_debain_based_deps
dependencies+=(
"libayatana-appindicator3-dev"
)
}
function add_ubuntu_deps() {
if [ "$ubuntu_test_repo" == 1 ]; then
# allow newer gcc
${sudo_cmd} add-apt-repository ppa:ubuntu-toolchain-r/test -y
fi
add_debain_based_deps
dependencies+=(
"libappindicator3-dev"
)
}
function add_opensuse_deps() {
dependencies+=(
"git"
"gcc-c++"
"libappindicator3-devel"
"libcap-devel"
"libcurl-devel"
"libdrm-devel"
"libevdev-devel"
"libminiupnpc-devel"
"libnotify-devel"
"libnuma-devel"
"libopenssl-devel"
"libopus-devel"
"libpulse-devel"
"ninja"
"nodejs"
"rpm-build"
"udev"
)
if [ "$skip_libva" == 0 ]; then
dependencies+=(
"libva-devel" # VA-API
)
fi
}
function add_fedora_deps() {
dependencies+=(
"cmake"
"doxygen"
"gcc"
"g++"
"git"
"graphviz"
"libappindicator-gtk3-devel"
"libcap-devel"
"libcurl-devel"
"libdrm-devel"
"libevdev-devel"
"libnotify-devel"
"libX11-devel" # X11
"libxcb-devel" # X11
"libXcursor-devel" # X11
"libXfixes-devel" # X11
"libXi-devel" # X11
"libXinerama-devel" # X11
"libXrandr-devel" # X11
"libXtst-devel" # X11
"mesa-libGL-devel"
"miniupnpc-devel"
"ninja-build"
"npm"
"numactl-devel"
"openssl-devel"
"opus-devel"
"pulseaudio-libs-devel"
"rpm-build" # if you want to build an RPM binary package
"wget" # necessary for cuda install with `run` file
"which" # necessary for cuda install with `run` file
"xorg-x11-server-Xvfb" # necessary for headless unit testing
)
if [ "$skip_libva" == 0 ]; then
dependencies+=(
"libva-devel" # VA-API
)
fi
}
function install_cuda() {
# check if we need to install cuda
if [ -f "${build_dir}/cuda/bin/nvcc" ]; then
echo "cuda already installed"
return
fi
local cuda_prefix="https://developer.download.nvidia.com/compute/cuda/"
local cuda_suffix=""
if [ "$architecture" == "aarch64" ]; then
local cuda_suffix="_sbsa"
fi
if [ "$architecture" == "aarch64" ]; then
# we need to patch the math-vector.h file for aarch64 fedora
# back up /usr/include/bits/math-vector.h
math_vector_file=""
if [ "$distro" == "ubuntu" ] || [ "$version" == "24.04" ]; then
math_vector_file="/usr/include/aarch64-linux-gnu/bits/math-vector.h"
elif [ "$distro" == "fedora" ]; then
math_vector_file="/usr/include/bits/math-vector.h"
fi
if [ -n "$math_vector_file" ]; then
# patch headers https://bugs.launchpad.net/ubuntu/+source/mumax3/+bug/2032624
${sudo_cmd} cp "$math_vector_file" "$math_vector_file.bak"
${sudo_cmd} sed -i 's/__Float32x4_t/int/g' "$math_vector_file"
${sudo_cmd} sed -i 's/__Float64x2_t/int/g' "$math_vector_file"
${sudo_cmd} sed -i 's/__SVFloat32_t/float/g' "$math_vector_file"
${sudo_cmd} sed -i 's/__SVFloat64_t/float/g' "$math_vector_file"
${sudo_cmd} sed -i 's/__SVBool_t/int/g' "$math_vector_file"
fi
fi
local url="${cuda_prefix}${cuda_version}/local_installers/cuda_${cuda_version}_${cuda_build}_linux${cuda_suffix}.run"
echo "cuda url: ${url}"
wget "$url" --progress=bar:force:noscroll -q --show-progress -O "${build_dir}/cuda.run"
chmod a+x "${build_dir}/cuda.run"
"${build_dir}/cuda.run" --silent --toolkit --toolkitpath="${build_dir}/cuda" --no-opengl-libs --no-man-page --no-drm
rm "${build_dir}/cuda.run"
}
function check_version() {
local package_name=$1
local min_version=$2
local installed_version
echo "Checking if $package_name is installed and at least version $min_version"
if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then
installed_version=$(dpkg -s "$package_name" 2>/dev/null | grep '^Version:' | awk '{print $2}')
elif [ "$distro" == "fedora" ]; then
installed_version=$(rpm -q --queryformat '%{VERSION}' "$package_name" 2>/dev/null)
elif [ "$distro" == "opensuse" ]; then
# avoid using system packages on openSUSE - boost and doxygen versions cause errors
return 1
else
echo "Unsupported Distro"
return 1
fi
if [ -z "$installed_version" ]; then
echo "Package not installed"
return 1
fi
if [ "$(printf '%s\n' "$installed_version" "$min_version" | sort -V | head -n1)" = "$min_version" ]; then
echo "$package_name version $installed_version is at least $min_version"
return 0
else
echo "$package_name version $installed_version is less than $min_version"
return 1
fi
}
function run_install() {
# prepare CMAKE args
cmake_args=(
"-B=build"
"-G=Ninja"
"-S=."
"-DBUILD_WERROR=ON"
"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DSUNSHINE_ASSETS_DIR=share/sunshine"
"-DSUNSHINE_EXECUTABLE_PATH=/usr/bin/sunshine"
"-DSUNSHINE_ENABLE_WAYLAND=ON"
"-DSUNSHINE_ENABLE_X11=ON"
"-DSUNSHINE_ENABLE_DRM=ON"
)
cmake_args+=("-DSUNSHINE_BUILD_DISTRO='${distro}'")
if [ "$appimage_build" == 1 ]; then
cmake_args+=("-DSUNSHINE_BUILD_APPIMAGE=ON")
fi
# Publisher metadata
if [ -n "$publisher_name" ]; then
cmake_args+=("-DSUNSHINE_PUBLISHER_NAME='${publisher_name}'")
fi
if [ -n "$publisher_website" ]; then
cmake_args+=("-DSUNSHINE_PUBLISHER_WEBSITE='${publisher_website}'")
fi
if [ -n "$publisher_issue_url" ]; then
cmake_args+=("-DSUNSHINE_PUBLISHER_ISSUE_URL='${publisher_issue_url}'")
fi
# Update the package list
$package_update_command
if [ "$distro" == "debian" ]; then
add_debain_deps
elif [ "$distro" == "ubuntu" ]; then
add_ubuntu_deps
elif [ "$distro" == "fedora" ]; then
add_fedora_deps
${sudo_cmd} dnf group install "Development Tools" -y
elif [ "$distro" == "opensuse" ]; then
add_opensuse_deps
fi
# Install the dependencies
$package_install_command "${dependencies[@]}"
# reload the environment
# shellcheck source=/dev/null
source ~/.bashrc
gcc_alternative_files=(
"gcc"
"g++"
"gcov"
"gcc-ar"
"gcc-ranlib"
)
# update alternatives for gcc and g++ if a debian based distro
if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then
for file in "${gcc_alternative_files[@]}"; do
file_path="/etc/alternatives/$file"
if [ -e "$file_path" ]; then
mv "$file_path" "$file_path.bak"
fi
done
${sudo_cmd} update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-${gcc_version} 100 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${gcc_version} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${gcc_version} \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-${gcc_version} \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-${gcc_version}
fi
# compile cmake if the version is too low
cmake_min="3.25.0"
target_cmake_version="3.30.1"
if ! check_version "cmake" "$cmake_min"; then
cmake_prefix="https://github.com/Kitware/CMake/releases/download/v"
if [ "$architecture" == "x86_64" ]; then
cmake_arch="x86_64"
elif [ "$architecture" == "aarch64" ]; then
cmake_arch="aarch64"
fi
url="${cmake_prefix}${target_cmake_version}/cmake-${target_cmake_version}-linux-${cmake_arch}.sh"
echo "cmake url: ${url}"
wget "$url" --progress=bar:force:noscroll -q --show-progress -O "${build_dir}/cmake.sh"
${sudo_cmd} sh "${build_dir}/cmake.sh" --skip-license --prefix=/usr/local
echo "cmake installed, version:"
cmake --version
fi
# compile doxygen if version is too low
doxygen_min="1.10.0"
_doxygen_min="1_10_0"
if ! check_version "doxygen" "$doxygen_min"; then
if [ "${SUNSHINE_COMPILE_DOXYGEN}" == "true" ]; then
echo "Compiling doxygen"
doxygen_url="https://github.com/doxygen/doxygen/releases/download/Release_${_doxygen_min}/doxygen-${doxygen_min}.src.tar.gz"
echo "doxygen url: ${doxygen_url}"
wget "$doxygen_url" --progress=bar:force:noscroll -q --show-progress -O "${build_dir}/doxygen.tar.gz"
tar -xzf "${build_dir}/doxygen.tar.gz"
cd "doxygen-${doxygen_min}"
cmake -DCMAKE_BUILD_TYPE=Release -G="Ninja" -B="build" -S="."
ninja -C "build" -j"${num_processors}"
ninja -C "build" install
else
echo "Doxygen version too low, skipping docs"
cmake_args+=("-DBUILD_DOCS=OFF")
fi
fi
# install node from nvm
if [ "$nvm_node" == 1 ]; then
nvm_url="https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh"
echo "nvm url: ${nvm_url}"
wget -qO- ${nvm_url} | bash
source "$HOME/.nvm/nvm.sh"
nvm install node
nvm use node
fi
# run the cuda install
if [ -n "$cuda_version" ] && [ "$skip_cuda" == 0 ]; then
install_cuda
cmake_args+=("-DSUNSHINE_ENABLE_CUDA=ON")
cmake_args+=("-DCMAKE_CUDA_COMPILER:PATH=${build_dir}/cuda/bin/nvcc")
else
cmake_args+=("-DSUNSHINE_ENABLE_CUDA=OFF")
fi
# Cmake stuff here
mkdir -p "build"
echo "cmake args:"
echo "${cmake_args[@]}"
cmake "${cmake_args[@]}"
ninja -C "build"
# Create the package
if [ "$skip_package" == 0 ]; then
if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then
cpack -G DEB --config ./build/CPackConfig.cmake
elif [ "$distro" == "fedora" ] || [ "$distro" == "opensuse" ]; then
cpack -G RPM --config ./build/CPackConfig.cmake
fi
fi
if [ "$skip_cleanup" == 0 ]; then
# Restore the original gcc alternatives
if [ "$distro" == "debian" ] || [ "$distro" == "ubuntu" ]; then
for file in "${gcc_alternative_files[@]}"; do
if [ -e "/etc/alternatives/$file.bak" ]; then
${sudo_cmd} mv "/etc/alternatives/$file.bak" "/etc/alternatives/$file"
else
${sudo_cmd} rm "/etc/alternatives/$file"
fi
done
fi
# restore the math-vector.h file
if [ "$architecture" == "aarch64" ] && [ -n "$math_vector_file" ]; then
${sudo_cmd} mv -f "$math_vector_file.bak" "$math_vector_file"
fi
fi
}
# Determine the OS and call the appropriate function
cat /etc/os-release
if grep -q "Debian GNU/Linux 12 (bookworm)" /etc/os-release; then
distro="debian"
version="12"
package_update_command="${sudo_cmd} apt-get update"
package_install_command="${sudo_cmd} apt-get install -y"
cuda_version="12.0.0"
cuda_build="525.60.13"
gcc_version="12"
nvm_node=0
elif grep -q "PLATFORM_ID=\"platform:f39\"" /etc/os-release; then
distro="fedora"
version="39"
package_update_command="${sudo_cmd} dnf update -y"
package_install_command="${sudo_cmd} dnf install -y"
cuda_version="12.4.0"
cuda_build="550.54.14"
gcc_version="13"
nvm_node=0
elif grep -q "PLATFORM_ID=\"platform:f40\"" /etc/os-release; then
distro="fedora"
version="40"
package_update_command="${sudo_cmd} dnf update -y"
package_install_command="${sudo_cmd} dnf install -y"
cuda_version=
cuda_build=
gcc_version="13"
nvm_node=0
elif grep -q "Ubuntu 22.04" /etc/os-release; then
distro="ubuntu"
version="22.04"
package_update_command="${sudo_cmd} apt-get update"
package_install_command="${sudo_cmd} apt-get install -y"
cuda_version="11.8.0"
cuda_build="520.61.05"
gcc_version="11"
nvm_node=1
elif grep -q "Ubuntu 24.04" /etc/os-release; then
distro="ubuntu"
version="24.04"
package_update_command="${sudo_cmd} apt-get update"
package_install_command="${sudo_cmd} apt-get install -y"
cuda_version="11.8.0"
cuda_build="520.61.05"
gcc_version="11"
nvm_node=0
elif grep -q "opensuse-tumbleweed" /etc/os-release; then
distro="opensuse"
version="tumbleweed"
package_update_command="${sudo_cmd} zypper dup"
package_install_command="${sudo_cmd} zypper in -y"
else
echo "Unsupported Distro or Version"
exit 1
fi
architecture=$(uname -m)
echo "Detected Distro: $distro"
echo "Detected Version: $version"
echo "Detected Architecture: $architecture"
if [ "$architecture" != "x86_64" ] && [ "$architecture" != "aarch64" ]; then
echo "Unsupported Architecture"
exit 1
fi
# get directory of this script
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
build_dir="$script_dir/../build"
echo "Script Directory: $script_dir"
echo "Build Directory: $build_dir"
mkdir -p "$build_dir"
run_install