summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: aabcc24027722631a5ef50bcadc93aeb72aed0f8 (plain)
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
# Edit on github: https://github.com/LizardByte/Sunshine/blob/master/packaging/linux/Arch/PKGBUILD
# Reference: https://wiki.archlinux.org/title/PKGBUILD

## options
: "${_run_unit_tests:=false}"  # if set to true; unit tests will be executed post build; useful in CI
: "${_support_headless_testing:=false}"
: "${_use_cuda:=detect}" # nvenc

: "${_commit:=63d35f702ee9e362e43263742981836ec0710384}"

pkgname='sunshine'
pkgver=2026.914.233613
pkgrel=3
pkgdesc="Self-hosted game stream host for Moonlight"
arch=('x86_64' 'aarch64')
url=https://app.lizardbyte.dev/Sunshine
license=('GPL-3.0-only')
install=sunshine.install

# this variable remains for future cases where we need an older version of gcc for cuda compatibility
_gcc_version=15
_versioned_gcc=false  # set to true if we need a versioned gcc, e.g. gcc14

_gcc_dep_suffix=""
_gcc_env_suffix=""
if [ "${_versioned_gcc}" == true ]; then
  _gcc_dep_suffix="${_gcc_version}"
  _gcc_env_suffix="-${_gcc_version}"
fi

depends=(
  'avahi'
  'curl'
  'gcc-libs'
  'gtk3'
  'hicolor-icon-theme'
  'libayatana-appindicator'
  'libcap'
  'libdrm'
  'libevdev'
  'libmfx'
  'libpipewire'
  'libpulse'
  'libva'
  'libx11'
  'libxcb'
  'libxfixes'
  'libxrandr'
  'libxtst'
  'miniupnpc'
  'numactl'
  'openssl'
  'opus'
  'qt6-base'
  'qt6-svg'
  'udev'
  'vulkan-icd-loader'
  'which'
)

makedepends=(
  'appstream'
  'appstream-glib'
  'cmake'
  'desktop-file-utils'
  "gcc${_gcc_dep_suffix}"
  'git'
  'make'
  'nodejs'
  'npm'
  'python-jinja'  # required by the glad OpenGL/EGL loader generator
  'shaderc'
)

checkdepends=(
  'gcovr'
  'imagemagick'
)

optdepends=(
  'libva-mesa-driver: AMD GPU encoding support'
)

provides=()
conflicts=()

source=(
  "$pkgname::git+https://github.com/LizardByte/Sunshine.git#commit=${_commit}"
  '2026.914.233613-dac66dfd-openssl-4.1-signature-length.patch'
  '2026.914.233613-6005-openssl-crypto-tests.patch'
  '2026.914.233613-357bd98c-update-metainfo-urls.patch'
  'https://github.com/boostorg/boost/releases/download/boost-1.89.0/boost-1.89.0-cmake.tar.xz'
  'boost-1.89.0-locale-cmake-4.5.patch'
)
sha256sums=(
  'SKIP'
  '0a31ccdf628f13fcdc30dac2283f565b3ab6df295b3c21c7a7514f2925549eb8'
  'b311d1aaab26503232bd3439ec2073cedb1d83db946ca1c8fe3e894a7729270d'
  '3208f0e7ec1a748e5f5e5a0994f62c5479aea6e94804983876313a0734efb98c'
  '67acec02d0d118b5de9eb441f5fb707b3a1cdd884be00ca24b9a73c995511f74'
  '16657a0edcf998137ce7afb532c451dc90fce5811478a0878639bdd1c207d85e'
)

# Options Handling
if [[ "${_use_cuda::1}" == "d" ]] && pacman -Qi cuda &> /dev/null; then
  _use_cuda=true
fi

if [[ "${_use_cuda::1}" == "t" ]]; then
  optdepends+=(
    'cuda: Nvidia GPU encoding support'
  )
fi

if [[ "${_support_headless_testing::1}" == "t" ]]; then
  optdepends+=(
    'xorg-server-xvfb: Virtual X server for headless testing'
  )
fi

# Ensure makedepends, checkdepends, optdepends are sorted
if [ -n "${makedepends+x}" ]; then
  mapfile -t tmp_array < <(printf '%s\n' "${makedepends[@]}" | sort)
  makedepends=("${tmp_array[@]}")
  unset tmp_array
fi

if [ -n "${optdepends+x}" ]; then
  mapfile -t tmp_array < <(printf '%s\n' "${optdepends[@]}" | sort)
  optdepends=("${tmp_array[@]}")
  unset tmp_array
fi

prepare() {
    cd "$pkgname"
    git submodule update --recursive --init --depth 1

    # Backport https://github.com/SunshineStream/Sunshine/commit/dac66dfdd200c5f1bb4b31b4e34227690ca8c565
    patch -Np1 -i "${srcdir}/2026.914.233613-dac66dfd-openssl-4.1-signature-length.patch"

    # Backport the regression test and supported subject-name API from:
    # https://github.com/SunshineStream/Sunshine/pull/6005
    patch -Np1 -i "${srcdir}/2026.914.233613-6005-openssl-crypto-tests.patch"

    # Backport the metainfo changes from:
    # https://github.com/SunshineStream/Sunshine/commit/357bd98cb1e203dbacbd831dbc6ddfac76d22ac0
    patch -Np1 -i "${srcdir}/2026.914.233613-357bd98c-update-metainfo-urls.patch"

    # Backport Boost.Locale's CMake 4.5 source grouping fixes:
    # https://github.com/boostorg/locale/commit/1d070743d98469809a92c5bb3fca4720bd2bd782
    # https://github.com/boostorg/locale/commit/f51b58cd34a2a0e3a1ce974287ec0ede0fc9d1fe
    patch -Np1 -d "${srcdir}/boost-1.89.0" -i "${srcdir}/boost-1.89.0-locale-cmake-4.5.patch"
}

build() {
    export BRANCH="master"
    export BUILD_VERSION="2026.914.233613"
    export COMMIT="${_commit}"

    export CC="gcc${_gcc_env_suffix}"
    export CXX="g++${_gcc_env_suffix}"

    export CFLAGS="${CFLAGS/-Werror=format-security/}"
    export CXXFLAGS="${CXXFLAGS/-Werror=format-security/}"

    export MAKEFLAGS="${MAKEFLAGS:--j$(nproc)}"

    local _cmake_options=(
      -S "$pkgname"
      -B build
      -Wno-dev
      -D BUILD_DOCS=OFF
      -D BUILD_WERROR=ON
      -D CMAKE_INSTALL_PREFIX=/usr
      # Use the Boost sources patched in prepare() instead of downloading another copy.
      -D FETCHCONTENT_SOURCE_DIR_BOOST="${srcdir}/boost-1.89.0"
      -D SUNSHINE_EXECUTABLE_PATH=/usr/bin/sunshine
      -D SUNSHINE_ASSETS_DIR="share/sunshine"
      -D SUNSHINE_PUBLISHER_NAME='LizardByte'
      -D SUNSHINE_PUBLISHER_WEBSITE='https://app.lizardbyte.dev'
      -D SUNSHINE_PUBLISHER_ISSUE_URL='https://app.lizardbyte.dev/support'
    )

    if [[ "${_use_cuda::1}" != "t" ]]; then
      _cmake_options+=(-DSUNSHINE_ENABLE_CUDA=OFF -DCUDA_FAIL_ON_MISSING=OFF)
    else
      # If cuda has just been installed, its variables will not be available in the environment
      # therefore, set them manually to the expected values on Arch Linux
      if [ -z "${CUDA_PATH:-}" ] && pacman -Qi cuda &> /dev/null; then
        local _cuda_gcc_version
        _cuda_gcc_version="$(LC_ALL=C pacman -Si cuda | grep -Pom1 '^Depends On\s*:.*\bgcc\K[0-9]+\b' || true)"

        export CUDA_PATH=/opt/cuda
        if [ -n "$_cuda_gcc_version" ]; then
          export NVCC_CCBIN="/usr/bin/g++-${_cuda_gcc_version}"
        else
          export NVCC_CCBIN="/usr/bin/g++"
        fi
      fi
    fi

    if [[ "${_run_unit_tests::1}" != "t" ]]; then
      _cmake_options+=(-DBUILD_TESTS=OFF)
    fi

    if [[ -z "${GITHUB_ACTIONS}" ]]; then
	    _appstreamcli_arguments=(--no-net)
    fi

    cmake "${_cmake_options[@]}"

    appstreamcli validate "${_appstreamcli_arguments[@]}" "build/dev.lizardbyte.app.Sunshine.metainfo.xml"
    appstream-util validate "build/dev.lizardbyte.app.Sunshine.metainfo.xml"
    desktop-file-validate "build/dev.lizardbyte.app.Sunshine.desktop"
    desktop-file-validate "build/dev.lizardbyte.app.Sunshine.terminal.desktop"

    cmake --build build
}

check() {
    if [[ "${_run_unit_tests::1}" == "t" ]]; then
      export CC="gcc${_gcc_env_suffix}"
      export CXX="g++${_gcc_env_suffix}"

      cd "${srcdir}/build/tests"
      # Do not silently upload misleading coverage if the gcov runtime cannot
      # write profile data, such as when its version differs from the compiler.
      GCOV_EXIT_AT_ERROR=1 ./test_sunshine --gtest_color=yes --gtest_output=xml:test_results.xml

      # Generate coverage report
      # Run gcovr from the build directory (where all .gcda/.gcno files are)
      # This matches the pattern used in ci-linux.yml
      cd "${srcdir}/build"

      # Dynamically find the gcov executable from the selected compiler.
      # This ensures we use the same gcov version that produced the .gcno files.
      local gcov_path
      local gcc_lib_dir

      gcc_lib_dir="$("$CC" -print-libgcc-file-name)"
      gcc_lib_dir="${gcc_lib_dir%/*}"
      gcov_path="${gcc_lib_dir}/gcov"

      if [ ! -x "$gcov_path" ]; then
        gcov_path="$("$CC" -print-prog-name=gcov)"
      fi

      if [ -n "$gcov_path" ] && command -v "$gcov_path" > /dev/null 2>&1; then
        gcov_path="$(command -v "$gcov_path")"
      else
        gcov_path="$(command -v "gcov${_gcc_env_suffix}" || command -v gcov || true)"
      fi

      if [ -z "$gcov_path" ]; then
        echo "Unable to find gcov for ${CC}" >&2
        return 1
      fi

      echo "Using gcov at: $gcov_path"

      # Use the actual relative path to the source directory
      # From ${srcdir}/build, the source is at ../${pkgname}/src
      gcovr --gcov-executable "$gcov_path" . -r "../${pkgname}/src" \
        --exclude-noncode-lines \
        --exclude-throw-branches \
        --exclude-unreachable-branches \
        --verbose \
        --xml-pretty \
        -o coverage.xml

      # Post-process the coverage XML to strip the absolute path and show only 'src'
      sed -i "s|${srcdir}/${pkgname}/src|src|g" coverage.xml
    fi

    cd "${srcdir}/build"
    ./sunshine --version
}

package() {
    export MAKEFLAGS="${MAKEFLAGS:--j$(nproc)}"
    DESTDIR="$pkgdir" cmake --install build
}