summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 1c8975c5870a38ad407e0dc13fab1d43545f8d77 (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
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
# Maintainer: taotieren <admin@taotieren.com>
# Maintainer: Ataraxy
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Contributor: Rojikku <RojikkuNoKami at gmail dot com>
# Contributor: Tech <technetium1337 at gmail dot com>

# 0 for PKGBUILD commands which may go out of date
# 1 for build.py which should stay current
_opt_BUILD_PY=0

# 0 for download vcpkg, set _opt_VCPKG_COMMIT_ID
# 1 for system vcpkg, ignore _opt_VCPKG_COMMIT_ID
_opt_SYS_VCPKG=0
#_opt_VCPKG_COMMIT_ID='#commit=14e7bb4ae24616ec54ff6b2f6ef4e8659434ea44'
_opt_VCPKG_COMMIT_ID=''

# 0 for Sciter
# 1 for Flutter
# Flutter has more advanced UI
_opt_FLUTTER=1

# 0 for package flutter, version checked
# 1 for system flutter, version warned
_opt_SYS_FLUTTER=0

set -u
_pkgname='rustdesk'
pkgname="${_pkgname}"
pkgname+="-git"
pkgver=1.2.5.r9318.g74c24ca
pkgrel=1
pkgdesc='Yet another remote desktop software, written in Rust. Works out of the box, no configuration required. Great alternative to TeamViewer and AnyDesk!'
arch=('x86_64')
url='https://rustdesk.com/'
_giturl='https://github.com/rustdesk/rustdesk'
license=('AGPL-3.0-only')
_dpr=('gtk3' 'xdotool' 'libxcb' 'libxfixes' 'alsa-lib' 'libva' 'libvdpau' 'libappindicator-gtk3' 'pam' 'gst-plugins-base' 'gst-plugin-pipewire') # from res/PKGBUILD/depends
depends=("${_dpr[@]}" 'pulse-native-provider' 'gst-plugins-base-libs')
depends+=('hicolor-icon-theme' 'xdg-utils')
depends+=('xdg-user-dirs')
depends+=('glibc' 'gcc-libs' 'glib2' 'libxtst' 'libepoxy' 'gdk-pixbuf2' 'cairo' 'at-spi2-core' 'dbus' 'gstreamer' 'pango' 'libx11' 'fontconfig' 'libxkbcommon' 'libpulse')
_mdp=('unzip' 'git' 'cmake' 'gcc' 'curl' 'wget' 'yasm' 'nasm' 'zip' 'make' 'pkg-config' 'clang') # from Readme.MD
makedepends=("${_mdp[@]}" 'rust' 'python' 'python-yaml' 'python-toml')
makedepends+=('ninja') # vcpkg build can use the latest ninja
provides=("${_pkgname}=${pkgver%.r*}")
conflicts=("${_pkgname}")
options=('!makeflags' '!lto')
install="${pkgname}.install"
_srcdir="${_pkgname}"
source=(
  "git+${_giturl}.git"
)
_vcs=(
  #'https://cmake.org/files/v3.18/cmake-3.18.4-Linux-x86_64.tar.gz'
  #'ninja-linux-1.10.1.zip::https://github.com/ninja-build/ninja/releases/download/v1.10.1/ninja-linux.zip'
  #'webmproject-libvpx-v1.11.0.tar.gz::https://github.com/webmproject/libvpx/archive/v1.11.0.tar.gz'
)
if [ "${_opt_SYS_VCPKG}" -ne 0 ]; then
  makedepends+=('vcpkg')
  _vcs+=(
    #'libjpeg-turbo-libjpeg-turbo-2.1.4.tar.gz::https://github.com/libjpeg-turbo/libjpeg-turbo/archive/2.1.4.tar.gz'
    #'webmproject-libvpx-v1.12.0.tar.gz::https://github.com/webmproject/libvpx/archive/v1.12.0.tar.gz'
  )
else
  source+=("git+https://github.com/microsoft/vcpkg${_opt_VCPKG_COMMIT_ID}")
fi
source+=("${_vcs[@]}")
if [ "${_opt_FLUTTER}" -eq 0 ]; then
  source+=("https://raw.github.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so")
else
  if [ "${_opt_SYS_FLUTTER}" -eq 0 ]; then
    _FLUVER='3.19.6'
    source+=(
      "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${_FLUVER}-stable.tar.xz"
      #"flutter_rust_bridge-${_FRBVER}.tar.gz::https://pub.dev/packages/flutter_rust_bridge/versions/${_FRBVER}.tar.gz" # bad packaging
      #"git+https://github.com/SoLongAndThanksForAllThePizza/flutter_rust_bridge.git"
    )
  else
    makedepends+=('flutter')
  fi
  if :; then
    _FRBVER='1.80.0'
    source+=(
      "flutter_rust_bridge-${_FRBVER}.tar.gz::https://github.com/fzyzcjy/flutter_rust_bridge/archive/refs/tags/v${_FRBVER}.tar.gz"
    )
  fi
fi
md5sums=('SKIP'
         'SKIP'
         '74dc171bf2cfc1ada56b6e284adabca8'
         'a63659fb966758db9fe95e5aae89757a')
sha256sums=('SKIP'
            'SKIP'
            'db6742a20626d0d2a089eb41ad61b9b2138b996679911e9c8268c1f896191f97'
            'b3a05ffca1f57afa48bd006d732969146dafa164c71390070623ba569977f9d3')
_vcs=("${_vcs[@]%%::*}")
_vcs=("${_vcs[@]##*/}")
noextract=("${_vcs[@]}")

pkgver() {
  set -u
  cd "${_srcdir}"
  local _ver
  local _pyver="
import toml
new_toml_string = toml.load('Cargo.toml')
#print(new_toml_string.keys())
print(new_toml_string.get('package').get('version'))
"
  _ver="$(python -c "${_pyver}")"
  #_ver="$(sed -E -n -e 's/^  VERSION: "([^"]+)"$/\1/p' '.github/workflows/flutter-nightly.yml')" # '
  #local _ver2
  #_ver2="$(git describe --long --tags | sed -E -e 's/([^-]*-g)/r&/' -e 's/^.+r/r/g' -e 's/-/./g')"
  printf '%s.r%s.g%s\n' "${_ver}" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)" # sometimes they reset the release counter
  set +u
}

_vcpkg=(libvpx libyuv opus aom)

_prepare_vc() {
  msg '_prepare_vc'
  set -u
  if [ "${_opt_SYS_VCPKG}" -ne 0 ] && [ ! -d 'vcpkg' ]; then
    local _vcp='/opt/vcpkg'
    if [ ! -d "${_vcp}" ]; then
      _vcp='/usr/lib/vcpkg'
    fi
    set +u; msg2 "Copy ${_vcp}"; set -u
    cp -pr "${_vcp}" .
  fi
  mkdir -p 'vcpkg/downloads'
  if [ "${#_vcs[@]}" -gt 0 ]; then
    cp -p "${_vcs[@]}" 'vcpkg/downloads'
  fi

  # Check commit ID
  if [ "${_opt_SYS_VCPKG}" -eq 0 ] && [ ! -z "${_opt_VCPKG_COMMIT_ID}" ]; then
    local _vcc
    local _pyvcc="
import yaml
import io
with open('rustdesk/.github/workflows/flutter-build.yml', 'r') as stream:
    data_loaded = yaml.safe_load(stream)
#print(data_loaded.get('env').keys())
print(data_loaded.get('env').get('VCPKG_COMMIT_ID'))
"
    _vcc="$(python -c "${_pyvcc}")"
    if [ "${_vcc}" != "${_opt_VCPKG_COMMIT_ID#*=}" ]; then
      echo "Flag package out of date: _opt_VCPKG_COMMIT_ID must be changed to ${_vcc}"
      set +u
      false
    fi
  fi

  local _vcpkgnew
  _vcpkgnew="$(sed -E -n -e '/Linux.+: vcpkg / s:^.+install ::p' 'rustdesk/README.md')"
  if [ "${_vcpkg[*]}" != "${_vcpkgnew}" ]; then
    printf 'Flag package out of date: _vcpkg=(%s)\n' "${_vcpkgnew}"
    set +u
    false
  fi
  set +u
}

# Same elements in same order
_dpr_check() {
  msg '_dpr_check'
  set -u
  pushd "${_srcdir}" > /dev/null
  (
    source 'res/PKGBUILD'
    if [ "${#_dpr[@]}" -ne "${#depends[@]}" ]; then
      echo 'Flag package out of date: Update _dpr from res/PKGBUILD/depends=()'
      false
    fi
    for((f=0; f<"${#_dpr[@]}"; f++)); do
      if [ "${_dpr[f]}" != "${depends[f]}" ]; then
        echo 'Flag package out of date: Update _dpr from res/PKGBUILD/depends=()'
        set +u
        false
      fi
    done
  )
  popd > /dev/null
  set +u
}

_flutter_check() {
  set +u; msg '_flutter_check'; set -u
  if [ "${_opt_FLUTTER}" -ne 0 ]; then
    local _FLUTTER_VERSION
    local _pyfv="
import yaml
import io
with open('.github/workflows/flutter-build.yml', 'r') as stream:
    data_loaded = yaml.safe_load(stream)
#print(data_loaded.get('env').keys())
print(data_loaded.get('env').get('FLUTTER_VERSION'))
"
    _FLUTTER_VERSION="$(python -c "${_pyfv}")"
    if [ "${_opt_SYS_FLUTTER}" -ne 0 ]; then
      local _FLUVER
      _FLUVER="$(pacman -Q flutter)"
      _FLUVER="${_FLUVER##* }"
      _FLUVER="${_FLUVER%%-*}"
    fi
    if [ "${_FLUTTER_VERSION}" != "${_FLUVER}" ]; then
      if [ "${_opt_SYS_FLUTTER}" -ne 0 ]; then
        set +u; msg2 "Warning: expected Flutter version is ${_FLUTTER_VERSION}"; set -u
        _FLUTTER_VERSION="${_FLUVER}"
      else
        printf 'Flutter version has changed to %s\n' "${_FLUTTER_VERSION}"
        set +u
        false
      fi
    fi
    set +u; msg2 "FLUTTER_VERSION=${_FLUTTER_VERSION}"; set -u
    local _flutter_rust_bridge
    local _pyfrb="
import toml
new_toml_string = toml.load('Cargo.toml')
#print(new_toml_string.keys())
print(new_toml_string.get('dependencies').get('flutter_rust_bridge').get('version'))
"
    _flutter_rust_bridge="$(python -c "${_pyfrb}")"
    _flutter_rust_bridge="${_flutter_rust_bridge#=}"
    if [ "$(vercmp "${_flutter_rust_bridge}" "${_FRBVER%.0}")" -gt 0 ]; then
      printf 'flutter_rust_bridge version has changed to %s\n' "${_flutter_rust_bridge}"
      set +u
      false
    fi
    set +u; msg2 "flutter_rust_bridge=${_flutter_rust_bridge}"; set -u
  fi
}

_mod_py() {
  if [ "$(grep -c -F -e 'os.system' 'build.py')" -gt 1 ]; then
    local _lf=$'\n'
    local _nc='
def systemecho(cmd):
    print(cmd)
    return os.system(cmd)

'
    _nc="${_nc//${_lf}/\\n}"
    sed -e '# echo all system commands' \
        -e 's:os.system:systemecho:g' \
        -e "s/^def get_version/${_nc}&/g" \
        -e '# Disable makepkg' \
        -e 's:makepkg:true &:g' \
        -e '/pkg.tar.zst/ s:mv:true &:g' \
        -i 'build.py'
  fi
  if [ "${source[0]#git}" = "${source[0]}" ]; then
    sed -e 's:git checkout:true &:g' -i 'build.py'
  fi
}

prepare() {
  _dpr_check
  #rm -rf ~/'.cache/vcpkg/archives' ~/'.vcpkg'
  _prepare_vc
  set -u
  if [ "${_opt_FLUTTER}" -ne 0 ]; then
    if [ "${_opt_SYS_FLUTTER}" -ne 0 ]; then
      set +u; msg2 'Copy /opt/flutter'; set -u
      rm -rf 'flutter'
      if [ -d '/opt/flutter' ]; then
        cp -pr '/opt/flutter' .
      else
        cp -pr '/usr/lib/flutter' .
      fi
    fi
    if [ ! -d 'flutter_rust_bridge' ]; then
      ln -s "flutter_rust_bridge-${_FRBVER}" 'flutter_rust_bridge'
      test -d 'flutter_rust_bridge'
    fi
  fi
  cd "${_srcdir}"
  _flutter_check
  _mod_py

  local _pt
  for _pt in "${source[@]}"; do
    if [[ "${_pt}" =~ *@(*).patch ]]; then
      set +u; msg2 "Patch ${_pt}"; set -u
      patch -d "${BASH_REMATCH[1]}" -Nup1 -i "${srcdir}/${_p}"
    fi
  done
  #cd ..; cp -pr 'rustdesk' 'a'; ln -s 'rustdesk' 'b'; false
  # diff -pNaru5 'a' 'b' > 0000-$RANDOM@foobar.patch
  set +u
}

build() {
  msg2 'Build vcpkg'
  set -u
  if [ ! -x vcpkg/vcpkg ]; then
    vcpkg/bootstrap-vcpkg.sh
  fi
  export VCPKG_ROOT="${PWD}/vcpkg"
  nice vcpkg/vcpkg install "${_vcpkg[@]}"

  cd "${_srcdir}"
  if [ "${_opt_FLUTTER}" -eq 0 ]; then
    set +u; msg2 'Build rustdesk Sciter'; set -u
    if [ "${_opt_BUILD_PY}" -ne 0 ]; then
      nice ./build.py --hwcodec
    else
      set -x
      git checkout src/ui/common.tis
      python3 res/inline-sciter.py
      # RUSTUP_TOOLCHAIN=stable cargo build --release --locked --all-features --target-dir=target
      nice cargo build --release --features 'inline,hwcodec'
      set +x
    fi
  else
    set +u; msg2 'Build rustdesk Flutter'; set -u
    set -x
    export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation: " | cut -d' ' -f4-)/include"
    export PATH="${srcdir}/flutter/bin:$PATH"
    dart pub global activate ffigen --version 5.0.1
    pushd "${srcdir}/flutter_rust_bridge/frb_codegen"; nice cargo install --path . ; popd
    pushd flutter ; flutter clean; flutter pub get ; popd
    local _CGdefault=~/.cargo
    "${CARGO_HOME:-${_CGdefault}}"/bin/flutter_rust_bridge_codegen --rust-input ./src/flutter_ffi.rs --dart-output ./flutter/lib/generated_bridge.dart
    if [ "${_opt_BUILD_PY}" -ne 0 ]; then
      nice ./build.py --hwcodec --flutter
    else
      git checkout src/ui/common.tis
      #if ! \
      nice cargo build --features hwcodec,flutter --lib --release
      #then
      #  set +u; msg2 'Move patch, get out the way (dynamic fix for unnecessary __builtin_va_list)'; set -u
      #  sed -E -e '/__builtin_va_list/ s:^:// :g' -i target/release/build/pam-sys-*/out/bindings.rs
      #  nice cargo build --features hwcodec,flutter --lib --release
      #fi
      pushd flutter
      nice flutter build linux --release
      popd
    fi
    set +x
  fi
  set +u
}

# This rebuilds the entire package
check_disabled() {
  cd "${_srcdir}"
  nice cargo test --release
}

package() {
  set -u
  cd "${_srcdir}"

  if [ "${_opt_FLUTTER}" -eq 0 ]; then
    # install rustdesk
    install -Dpm0755 -t "${pkgdir}/usr/bin" "target/release/${_pkgname}"
    install -Dm755 -t "${pkgdir}/usr/lib/${_pkgname}" '../libsciter-gtk.so'
  else
    install -d "${pkgdir}/usr/lib/"
    cp -pr 'flutter/build/linux/x64/release/bundle' "${pkgdir}/usr/lib/"
    mv "${pkgdir}/usr/lib/"{bundle,${_pkgname}}
    # False alarm from ldd
    if ! :; then
      install -Dm0755 /dev/stdin "${pkgdir}/usr/bin/${_pkgname}" << EOF
#!/usr/bin/bash
LD_LIBRARY_PATH=/usr/lib/${_pkgname}/lib/
exec "/usr/lib/${_pkgname}/${_pkgname}" "\$@"
EOF
    else
      install -d "${pkgdir}/usr/bin/"
      ln -s -t "${pkgdir}/usr/bin/" "/usr/lib/${_pkgname}/${_pkgname}"
    fi
  fi

  install -Dm0644 "res/${_pkgname}.service" -t "${pkgdir}/usr/lib/systemd/system/"

  install -Dm0644 'res/32x32.png' "${pkgdir}/usr/share/icons/hicolor/32x32/apps/${_pkgname}.png"
  install -Dm0644 'res/128x128.png' "${pkgdir}/usr/share/icons/hicolor/128x128/apps/${_pkgname}.png"
  install -Dm0644 'res/128x128@2x.png' "${pkgdir}/usr/share/icons/hicolor/256x256/apps/${_pkgname}.png"

  install -Dm0644 /dev/stdin "${pkgdir}/usr/share/applications/${_pkgname}.desktop" << EOF
[Desktop Entry]
Version=${pkgver%.r*}
Name=RustDesk
GenericName=Remote Desktop
GenericName[zh_CN]=远程桌面
Comment=Remote Desktop
Comment[zh_CN]=远程桌面
Exec=${_pkgname} %u
Icon=${_pkgname}.svg
Terminal=false
Type=Application
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
Categories=Network;RemoteAccess;GTK;
Keywords=internet;
Actions=new-window;

X-Desktop-File-Install-Version=0.23

[Desktop Action new-window]
Name=Open a New Window
EOF
  install -Dm644 'LICENCE' -t "${pkgdir}/usr/share/licenses/${_pkgname}"
  set +u
}
set +u