summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: ff08ebe32a699f4b15fff959c09e350adea888e3 (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
# Maintainer:

## options
: ${_build_cuda=false} # nvenc

: ${_commit=8b21db64fb8e8ffb9c24a412dbc66b7410699211}

_pkgname="sunshine"
pkgname="$_pkgname"
pkgver=0.23.1
pkgrel=5
pkgdesc="A self-hosted GameStream host for Moonlight"
url="https://github.com/LizardByte/Sunshine"
license=('GPL-3.0-only')
arch=('x86_64' 'aarch64')

depends=(
  'avahi'
  'boost-libs'
  'curl'
  'libayatana-appindicator'
  'libcap'
  'libdrm'
  'libevdev'
  'libmfx'
  'libnotify'
  'libpulse'
  'libva'
  'libvdpau'
  'libx11'
  'libxcb'
  'libxfixes'
  'libxrandr'
  'libxtst'
  'libminiupnpc.so' # miniupnpc
  'numactl'
  'openssl'
  'opus'
  'udev'
)
makedepends=(
  'boost'
  'cmake'
  'git'
  'ninja'
  'npm'
)
optdepends=(
  'cuda: Nvidia GPU encoding support'
  'intel-media-driver: Intel GPU encoding support'
  'libva-mesa-driver: AMD GPU encoding support'
)

if [[ "${_build_cuda::1}" == "t" ]]; then
  makedepends+=('cuda')
fi

install="sunshine.install"

_source_main() {
  _pkgsrc="$_pkgname"
  source=("$_pkgsrc"::"git+$url.git#commit=$_commit")
  sha256sums=('b9ac221ca53c86010d02d7144c289053e7055c537d7313a8ff3063ec59477e4d')
}

_source_sunshine() {
  source+=(
    'eidheim.simple-web-server'::'git+https://gitlab.com/eidheim/Simple-Web-Server.git'
    'ffmpeg.nv-codec-headers'::'git+https://github.com/FFmpeg/nv-codec-headers.git'
    #'flathub.org.flatpak.builder.baseapp'::'git+https://github.com/flathub/org.flatpak.Builder.BaseApp.git'
    #'flathub.shared-modules'::'git+https://github.com/flathub/shared-modules.git'
    #'google.googletest'::'git+https://github.com/google/googletest.git'
    'lizardbyte.build-deps'::'git+https://github.com/LizardByte/build-deps.git'
    'lizardbyte.nvapi-open-source-sdk'::'git+https://github.com/LizardByte/nvapi-open-source-sdk.git'
    'lizardbyte.tray'::'git+https://github.com/LizardByte/tray.git'
    'lizardbyte.virtual-gamepad-emulation-client'::'git+https://github.com/LizardByte/Virtual-Gamepad-Emulation-Client.git'
    'michaeltyson.tpcircularbuffer'::'git+https://github.com/michaeltyson/TPCircularBuffer.git'
    'moonlight-stream.moonlight-common-c'::'git+https://github.com/moonlight-stream/moonlight-common-c.git'
    'sleepybishop.nanors'::'git+https://github.com/sleepybishop/nanors.git'
    'wayland.wayland-protocols'::'git+https://gitlab.freedesktop.org/wayland/wayland-protocols.git'
    'wlroots.wlr-protocols'::'git+https://gitlab.freedesktop.org/wlroots/wlr-protocols.git'
  )
  sha256sums+=(
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
  )
}

_source_moonlight_common_c() {
  source+=(
    'cgutman.enet'::'git+https://github.com/cgutman/enet.git'
  )
  sha256sums+=(
    'SKIP'
  )

}

_prepare_sunshine() (
  cd "$srcdir/$_pkgsrc"
  local _submodules=(
    'eidheim.simple-web-server'::'third-party/Simple-Web-Server'
    'ffmpeg.nv-codec-headers'::'third-party/nv-codec-headers'
    #'flathub.org.flatpak.builder.baseapp'::'packaging/linux/flatpak/deps/org.flatpak.Builder.BaseApp'
    #'flathub.shared-modules'::'packaging/linux/flatpak/deps/shared-modules'
    #'google.googletest'::'third-party/googletest'
    'lizardbyte.build-deps'::'third-party/build-deps'
    'lizardbyte.nvapi-open-source-sdk'::'third-party/nvapi-open-source-sdk'
    'lizardbyte.tray'::'third-party/tray'
    'lizardbyte.virtual-gamepad-emulation-client'::'third-party/ViGEmClient'
    'michaeltyson.tpcircularbuffer'::'third-party/TPCircularBuffer'
    'moonlight-stream.moonlight-common-c'::'third-party/moonlight-common-c'
    'sleepybishop.nanors'::'third-party/nanors'
    'wayland.wayland-protocols'::'third-party/wayland-protocols'
    'wlroots.wlr-protocols'::'third-party/wlr-protocols'
  )
  _submodule_update
)

_prepare_moonlight_common_c() (
  cd "$srcdir/$_pkgsrc"
  cd 'third-party/moonlight-common-c'
  local _submodules=(
    'cgutman.enet'::'enet'
  )
  _submodule_update
)

_source_main
_source_sunshine
_source_moonlight_common_c

prepare() {
  _submodule_update() {
    local _module
    for _module in "${_submodules[@]}"; do
      git submodule init "${_module##*::}"
      git submodule set-url "${_module##*::}" "$srcdir/${_module%::*}"
      git -c protocol.file.allow=always submodule update "${_module##*::}"
      echo
    done
  }
  _prepare_sunshine
  _prepare_moonlight_common_c

  # cherry-pick
  sed -E \
    -e '/#include <string>/s&$&\n\n#include <boost/core/noncopyable.hpp>&' \
    -i "$_pkgsrc/src/platform/common.h"

  git -C "$_pkgsrc" add .
  git -c user.email="makepkg@example.com" -c user.name="makepkg" \
    -C "$_pkgsrc" commit -m "prepare for cherry-pick"

  local _cherrypick=(
    a940cdb394055139ca6a964289f414da562452e3 # miniupnpc
    45265fb10387d329dc813a0dd7778c5998b787cd # boost
  )
  for i in ${_cherrypick[@]}; do
    git -C "$_pkgsrc" cherry-pick -n -m1 $i
  done

  # force features enabled
  sed -E \
    -e 's&(LIBCAP_FOUND) OFF&\1 ON&' \
    -e 's&(LIBDRM_FOUND) OFF&\1 ON&' \
    -e 's&(LIBVA_FOUND) OFF&\1 ON&' \
    -e 's&(WAYLAND_FOUND) OFF&\1 ON&' \
    -e 's&(X11_FOUND) OFF&\1 ON&' \
    -i "$_pkgsrc/cmake/compile_definitions/linux.cmake"

  # force cuda enabled
  if [[ "${_build_cuda::1}" == "t" ]]; then
    sed -E \
      -e 's&(CUDA_FOUND) OFF&\1 ON&' \
      -i "$_pkgsrc/cmake/compile_definitions/linux.cmake"
  fi
}

build() (
  export BRANCH="master"
  export BUILD_VERSION="${pkgver}"
  export COMMIT="$(git -C "$_pkgsrc" rev-parse HEAD)"

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

  export CUDA_PATH=/opt/cuda
  export NVCC_CCBIN='/usr/bin/g++-13'

  local _cmake_options=(
    -B build
    -S "$_pkgsrc"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX='/usr'
    -DSUNSHINE_ASSETS_DIR="share/sunshine"
    -DSUNSHINE_EXECUTABLE_PATH='/usr/bin/sunshine'
    -DSUNSHINE_ENABLE_CUDA=ON
    -DSUNSHINE_ENABLE_X11=ON
    -DBUILD_TESTS=OFF
    -Wno-dev
  )

  pushd "$_pkgsrc"
  npm install --force --no-audit --no-fund --cache "$srcdir/npm-cache"
  popd

  cmake "${_cmake_options[@]}"
  cmake --build build
)

package() {
  DESTDIR="$pkgdir" cmake --install build
}