2022-04-18 15:37:35 +08:00
#!/usr/bin/env python3
import os
2026-07-17 20:55:26 -03:00
import glob
2022-10-21 17:24:07 +08:00
import pathlib
2022-04-18 15:37:35 +08:00
import platform
2022-05-28 18:42:38 +08:00
import zipfile
import urllib.request
import shutil
2022-04-18 15:37:35 +08:00
import hashlib
2026-07-21 00:31:12 -03:00
import subprocess
2022-05-28 18:42:38 +08:00
import argparse
2022-12-02 11:41:22 +08:00
import sys
2024-12-25 00:04:34 +08:00
from pathlib import Path
2022-04-18 15:37:35 +08:00
windows = platform . platform () . startswith ( 'Windows' )
2022-11-20 16:54:54 +08:00
osx = platform . platform () . startswith (
'Darwin' ) or platform . platform () . startswith ( "macOS" )
2022-04-18 15:37:35 +08:00
hbb_name = 'rustdesk' + ( '.exe' if windows else '' )
exe_path = 'target/release/' + hbb_name
2023-04-17 15:16:55 +08:00
if windows :
2026-06-18 16:37:15 +02:00
win_arch = 'arm64' if platform . machine () . lower () in ( 'arm64' , 'aarch64' ) else 'x64'
flutter_build_dir = f 'build/windows/ { win_arch } /runner/Release/'
2023-04-17 15:16:55 +08:00
elif osx :
flutter_build_dir = 'build/macos/Build/Products/Release/'
else :
flutter_build_dir = 'build/linux/x64/release/bundle/'
flutter_build_dir_2 = f 'flutter/ { flutter_build_dir } '
2022-11-21 17:10:38 +08:00
skip_cargo = False
2022-04-18 15:37:35 +08:00
2023-10-30 00:06:53 +08:00
2024-07-01 11:01:35 +08:00
def get_deb_arch () -> str :
custom_arch = os . environ . get ( "DEB_ARCH" )
2023-03-27 15:26:20 +08:00
if custom_arch is None :
return "amd64"
return custom_arch
2024-07-30 14:52:06 +08:00
def get_deb_extra_depends () -> str :
custom_arch = os . environ . get ( "DEB_ARCH" )
if custom_arch == "armhf" : # for arm32v7 libsciter-gtk.so
return ", libatomic1"
return ""
2023-10-30 00:06:53 +08:00
2023-02-27 20:28:55 +08:00
def system2 ( cmd ):
2024-04-14 16:52:27 +00:00
exit_code = os . system ( cmd )
if exit_code != 0 :
sys . stderr . write ( f "Error occurred when executing: ` { cmd } `. Exiting. \n " )
2022-12-02 11:41:22 +08:00
sys . exit ( - 1 )
2022-10-22 12:41:37 +08:00
2023-10-30 00:06:53 +08:00
2022-04-18 15:37:35 +08:00
def get_version ():
2022-11-01 16:03:47 +03:00
with open ( "Cargo.toml" , encoding = "utf-8" ) as fh :
2022-04-18 15:37:35 +08:00
for line in fh :
if line . startswith ( "version" ):
return line . replace ( "version" , "" ) . replace ( "=" , "" ) . replace ( '"' , '' ) . strip ()
return ''
2022-07-22 12:41:49 +08:00
def parse_rc_features ( feature ):
2024-07-20 23:49:40 +08:00
available_features = {}
2022-05-28 18:42:38 +08:00
apply_features = {}
if not feature :
2022-10-21 13:38:44 +08:00
feature = []
2023-04-17 14:49:58 +08:00
def platform_check ( platforms ):
if windows :
return 'windows' in platforms
elif osx :
return 'osx' in platforms
else :
return 'linux' in platforms
2023-08-01 00:36:19 +02:00
2023-04-17 19:01:12 +08:00
def get_all_features ():
features = []
2023-04-17 14:49:58 +08:00
for ( feat , feat_info ) in available_features . items ():
if platform_check ( feat_info [ 'platform' ]):
2023-04-17 19:01:12 +08:00
features . append ( feat )
return features
2023-08-01 00:36:19 +02:00
2023-04-17 19:01:12 +08:00
if isinstance ( feature , str ) and feature . upper () == 'ALL' :
return get_all_features ()
2022-05-28 18:42:38 +08:00
elif isinstance ( feature , list ):
2023-04-17 14:49:58 +08:00
if windows :
2024-02-26 02:24:00 +08:00
# download third party is deprecated, we use github ci instead.
# feature.append('PrivacyMode')
pass
2022-05-28 18:42:38 +08:00
for feat in feature :
if isinstance ( feat , str ) and feat . upper () == 'ALL' :
2023-04-17 19:01:12 +08:00
return get_all_features ()
2022-05-28 18:42:38 +08:00
if feat in available_features :
2023-04-17 14:49:58 +08:00
if platform_check ( available_features [ feat ][ 'platform' ]):
apply_features [ feat ] = available_features [ feat ]
2022-05-28 18:42:38 +08:00
else :
print ( f 'Unrecognized feature { feat } ' )
return apply_features
else :
raise Exception ( f 'Unsupported features param { feature } ' )
def make_parser ():
parser = argparse . ArgumentParser ( description = 'Build script.' )
parser . add_argument (
'-f' ,
'--feature' ,
dest = 'feature' ,
metavar = 'N' ,
type = str ,
nargs = '+' ,
default = '' ,
help = 'Integrate features, windows only.'
2024-07-20 23:49:40 +08:00
'Available: [Not used for now]. Special value is "ALL" and empty "". Default is empty.' )
2022-08-25 17:35:45 +08:00
parser . add_argument ( '--flutter' , action = 'store_true' ,
help = 'Build flutter package' , default = False )
2022-06-14 15:01:07 +08:00
parser . add_argument (
'--hwcodec' ,
action = 'store_true' ,
2022-10-22 12:41:37 +08:00
help = 'Enable feature hwcodec' + (
2024-12-04 17:10:10 +08:00
'' if windows or osx else ', need libva-dev.' )
2022-06-14 15:01:07 +08:00
)
2024-01-02 16:58:10 +08:00
parser . add_argument (
2024-04-12 17:26:24 +08:00
'--vram' ,
2024-01-02 16:58:10 +08:00
action = 'store_true' ,
2024-04-12 17:26:24 +08:00
help = 'Enable feature vram, only available on windows now.'
2024-01-02 16:58:10 +08:00
)
2022-09-21 11:28:28 +08:00
parser . add_argument (
'--portable' ,
action = 'store_true' ,
help = 'Build windows portable'
)
2023-10-30 00:06:53 +08:00
parser . add_argument (
'--unix-file-copy-paste' ,
action = 'store_true' ,
help = 'Build with unix file copy paste feature'
)
2026-07-17 20:55:26 -03:00
parser . add_argument (
'--drm' ,
action = 'store_true' ,
help = 'Linux only: build the DRM/KMS capture backend (bundles libdrmtap.so, '
'dlopen-ed in-process by the root service). Off by default.'
)
2022-11-21 17:10:38 +08:00
parser . add_argument (
'--skip-cargo' ,
action = 'store_true' ,
help = 'Skip cargo build process, only flutter version + Linux supported currently'
)
2024-02-26 02:20:37 +08:00
if windows :
parser . add_argument (
'--skip-portable-pack' ,
action = 'store_true' ,
help = 'Skip packing, only flutter version + Windows supported'
)
2023-03-27 15:26:20 +08:00
parser . add_argument (
"--package" ,
type = str
)
2024-11-23 18:41:27 +08:00
if osx :
parser . add_argument (
'--screencapturekit' ,
action = 'store_true' ,
help = 'Enable feature screencapturekit'
)
2022-05-28 18:42:38 +08:00
return parser
2022-10-22 12:41:37 +08:00
# Generate build script for docker
#
# it assumes all build dependencies are installed in environments
# Note: do not use it in bare metal, or may break build environments
def generate_build_script_for_docker ():
with open ( "/tmp/build.sh" , "w" ) as f :
f . write ( '''
#!/bin/bash
# environment
export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation: " | cut -d' ' -f4-)/include"
# flutter
pushd /opt
wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.0.5-stable.tar.xz
tar -xvf flutter_linux_3.0.5-stable.tar.xz
export PATH=`pwd`/flutter/bin:$PATH
popd
# flutter_rust_bridge
dart pub global activate ffigen --version 5.0.1
pushd /tmp && git clone https://github.com/SoLongAndThanksForAllThePizza/flutter_rust_bridge --depth=1 && popd
2026-05-26 11:44:51 +08:00
pushd /tmp/flutter_rust_bridge/frb_codegen && cargo install --path . --locked && popd
2022-10-22 12:41:37 +08:00
pushd flutter && flutter pub get && popd
~/.cargo/bin/flutter_rust_bridge_codegen --rust-input ./src/flutter_ffi.rs --dart-output ./flutter/lib/generated_bridge.dart
# install vcpkg
pushd /opt
export VCPKG_ROOT=`pwd`/vcpkg
git clone https://github.com/microsoft/vcpkg
vcpkg/bootstrap-vcpkg.sh
popd
2023-11-01 11:37:39 +02:00
$VCPKG_ROOT/vcpkg install --x-install-root="$VCPKG_ROOT/installed"
2022-10-22 12:41:37 +08:00
# build rustdesk
./build.py --flutter --hwcodec
''' )
2023-02-27 20:28:55 +08:00
system2 ( "chmod +x /tmp/build.sh" )
system2 ( "bash /tmp/build.sh" )
2022-10-22 12:41:37 +08:00
2022-11-20 16:54:54 +08:00
2024-02-26 02:24:00 +08:00
# Downloading third party resources is deprecated.
# We can use this function in an offline build environment.
# Even in an online environment, we recommend building third-party resources yourself.
2022-05-28 18:42:38 +08:00
def download_extract_features ( features , res_dir ):
2022-12-04 21:59:26 +08:00
import re
2022-10-22 12:41:37 +08:00
2022-12-04 21:59:26 +08:00
proxy = ''
2023-10-30 00:06:53 +08:00
2022-10-21 13:38:44 +08:00
def req ( url ):
if not proxy :
return url
else :
r = urllib . request . Request ( url )
r . set_proxy ( proxy , 'http' )
r . set_proxy ( proxy , 'https' )
return r
2022-05-28 18:42:38 +08:00
for ( feat , feat_info ) in features . items ():
2022-12-04 21:59:26 +08:00
includes = feat_info [ 'include' ] if 'include' in feat_info and feat_info [ 'include' ] else []
2023-10-30 00:06:53 +08:00
includes = [ re . compile ( p ) for p in includes ]
2022-12-04 21:59:26 +08:00
excludes = feat_info [ 'exclude' ] if 'exclude' in feat_info and feat_info [ 'exclude' ] else []
2023-10-30 00:06:53 +08:00
excludes = [ re . compile ( p ) for p in excludes ]
2022-12-04 21:59:26 +08:00
2022-05-28 18:42:38 +08:00
print ( f ' { feat } download begin' )
download_filename = feat_info [ 'zip_url' ] . split ( '/' )[ - 1 ]
2022-11-20 16:54:54 +08:00
checksum_md5_response = urllib . request . urlopen (
req ( feat_info [ 'checksum_url' ]))
2022-10-21 13:38:44 +08:00
for line in checksum_md5_response . read () . decode ( 'utf-8' ) . splitlines ():
if line . split ()[ 1 ] == download_filename :
checksum_md5 = line . split ()[ 0 ]
2022-10-22 12:41:37 +08:00
filename , _headers = urllib . request . urlretrieve ( feat_info [ 'zip_url' ],
download_filename )
2022-10-21 13:38:44 +08:00
md5 = hashlib . md5 ( open ( filename , 'rb' ) . read ()) . hexdigest ()
if checksum_md5 != md5 :
raise Exception ( f ' { feat } download failed' )
print ( f ' { feat } download end. extract bein' )
zip_file = zipfile . ZipFile ( filename )
zip_list = zip_file . namelist ()
for f in zip_list :
2022-12-04 21:59:26 +08:00
file_exclude = False
for p in excludes :
if p . match ( f ) is not None :
file_exclude = True
break
if file_exclude :
continue
file_include = False if includes else True
for p in includes :
if p . match ( f ) is not None :
file_include = True
break
if file_include :
print ( f 'extract file { f } ' )
zip_file . extract ( f , res_dir )
2022-10-21 13:38:44 +08:00
zip_file . close ()
os . remove ( download_filename )
print ( f ' { feat } extract end' )
2022-05-28 18:42:38 +08:00
2023-04-17 15:16:55 +08:00
def external_resources ( flutter , args , res_dir ):
2022-07-22 12:41:49 +08:00
features = parse_rc_features ( args . feature )
2022-10-21 17:24:07 +08:00
if not features :
2023-04-17 14:18:00 +08:00
return
2022-10-21 17:24:07 +08:00
print ( f 'Build with features { list ( features . keys ()) } ' )
if os . path . isdir ( res_dir ) and not os . path . islink ( res_dir ):
shutil . rmtree ( res_dir )
elif os . path . exists ( res_dir ):
raise Exception ( f 'Find file { res_dir } , not a directory' )
os . makedirs ( res_dir , exist_ok = True )
download_extract_features ( features , res_dir )
2023-04-17 15:16:55 +08:00
if flutter :
os . makedirs ( flutter_build_dir_2 , exist_ok = True )
for f in pathlib . Path ( res_dir ) . iterdir ():
print ( f ' { f } ' )
if f . is_file ():
shutil . copy2 ( f , flutter_build_dir_2 )
else :
shutil . copytree ( f , f ' { flutter_build_dir_2 }{ f . stem } ' )
2022-10-22 12:41:37 +08:00
2022-05-28 18:42:38 +08:00
2022-07-22 09:14:18 +08:00
def get_features ( args ):
2022-11-20 16:54:54 +08:00
features = [ 'inline' ] if not args . flutter else []
2022-07-22 09:14:18 +08:00
if args . hwcodec :
features . append ( 'hwcodec' )
2024-04-12 17:26:24 +08:00
if args . vram :
features . append ( 'vram' )
2022-08-25 17:35:45 +08:00
if args . flutter :
features . append ( 'flutter' )
2023-10-30 00:06:53 +08:00
if args . unix_file_copy_paste :
features . append ( 'unix-file-copy-paste' )
2026-07-17 20:55:26 -03:00
if not windows and not osx and args . drm :
features . append ( 'drm' )
2024-11-23 18:41:27 +08:00
if osx :
if args . screencapturekit :
features . append ( 'screencapturekit' )
2022-07-22 09:14:18 +08:00
print ( "features:" , features )
return features
2022-05-28 18:42:38 +08:00
2022-10-22 12:41:37 +08:00
2026-07-28 06:45:04 -03:00
def generate_control_file ( version ):
2022-09-18 11:50:23 +08:00
control_file_path = "../res/DEBIAN/control"
2023-02-27 20:28:55 +08:00
system2 ( '/bin/rm -rf %s ' % control_file_path )
2022-09-12 23:27:07 -07:00
2026-07-28 06:45:04 -03:00
content = """Package: rustdesk
2024-10-07 21:46:25 +08:00
Section: net
2024-10-07 22:08:17 +08:00
Priority: optional
2022-09-12 23:27:07 -07:00
Version: %s
2023-03-27 15:26:20 +08:00
Architecture: %s
2023-04-10 08:52:44 +08:00
Maintainer: rustdesk <info@rustdesk.com>
2022-09-12 23:27:07 -07:00
Homepage: https://rustdesk.com
2026-07-28 06:45:04 -03:00
Depends: libgtk-3-0t64 | libgtk-3-0, libxcb-randr0, libxdo3 | libxdo4, libxfixes3, libxcb-shape0, libxcb-xfixes0, libasound2t64 | libasound2, libsystemd0, curl, libva2, libva-drm2, libva-x11-2, libgstreamer-plugins-base1.0-0, libpam0g, gstreamer1.0-pipewire %s
2024-09-15 14:33:59 +08:00
Recommends: libayatana-appindicator3-1
2022-09-12 23:27:07 -07:00
Description: A remote control software.
2026-07-28 06:45:04 -03:00
""" % ( version , get_deb_arch (), get_deb_extra_depends ())
2022-09-12 23:27:07 -07:00
file = open ( control_file_path , "w" )
file . write ( content )
file . close ()
2022-08-25 18:36:44 +08:00
2022-10-22 12:41:37 +08:00
def ffi_bindgen_function_refactor ():
2022-10-11 20:34:58 -07:00
# workaround ffigen
2023-02-27 20:28:55 +08:00
system2 (
2022-10-22 12:41:37 +08:00
'sed -i "s/ffi.NativeFunction<ffi.Bool Function(DartPort/ffi.NativeFunction<ffi.Uint8 Function(DartPort/g" flutter/lib/generated_bridge.dart' )
2026-07-28 06:22:49 -03:00
# libdrmtap is fetched at build time from the rustdesk-org fork at a pinned
# commit — the same way rustdesk sources its other native build deps (vcpkg,
2026-07-21 18:02:50 -03:00
# flutter_rust_bridge, ...), rather than carrying a git submodule. It is the ONLY
# pin for the drm backend: rustdesk dlopens this .so at runtime and does not depend on
# the libdrmtap-sys crate (whose build.rs would statically link the C tree, a helper and
2026-07-28 06:22:49 -03:00
# libdrm/seccomp/cap). Override the repo via env (DRMTAP_REPO) for local testing
# or another fork.
# The commit is fetched directly by sha, so no branch or tag name takes part in the build: see
# build_libdrmtap_so(). This is the SINGLE source of truth for the pin, deliberately not duplicated in
# any workflow, so a bump is one edit here (plus the informational version comment in
# libs/scrap/Cargo.toml). This commit is libdrmtap v0.4.15.
2026-07-21 18:02:50 -03:00
LIBDRMTAP_REPO = os . environ . get ( 'DRMTAP_REPO' , 'https://github.com/rustdesk-org/libdrmtap' )
2026-07-24 08:41:46 -03:00
LIBDRMTAP_SHA = os . environ . get ( 'DRMTAP_SHA' , 'cbc5e6af5b353b6bc351072a27a5351d82ba66e3' )
2026-07-17 20:55:26 -03:00
def _single_real_so ( paths , where ):
# Return the one real libdrmtap.so.0.* object among `paths`, failing if there are zero or several.
# glob order is arbitrary, so silently taking [0] could ship a stale or wrong-arch object left
# over from an earlier build; a mismatch should fail the build loudly instead.
real = sorted ( p for p in paths if os . path . isfile ( p ) and not os . path . islink ( p ))
if len ( real ) != 1 :
raise Exception (
f 'expected exactly one real libdrmtap.so.0.* in { where } , found { len ( real ) } : { real } ' )
return real [ 0 ]
def build_libdrmtap_so ():
2026-07-28 06:22:49 -03:00
# Build libdrmtap.so from the rustdesk-org fork, fetched at the pinned LIBDRMTAP_SHA. The
2026-07-17 20:55:26 -03:00
# pivot dlopen-s this .so in-process in the root service (which already holds
# CAP_SYS_ADMIN) — no setcap helper, no privileged child. Only the shared
# library target is built (the source also carries a helper binary we do not
# ship). Returns the path to the built versioned .so (e.g. libdrmtap.so.0.4.x).
repo_root = os . path . dirname ( os . path . abspath ( __file__ ))
# Allow a caller (e.g. CI) to build the .so ahead of time and hand it in via
# DRMTAP_PREBUILT_DIR (must contain the real libdrmtap.so.0.* object).
prebuilt_dir = os . environ . get ( 'DRMTAP_PREBUILT_DIR' )
if prebuilt_dir :
# DRMTAP_PREBUILT_DIR explicitly names the artifact source, so honor it strictly: fail
# (rather than silently falling back to a source build) if it holds no single real .so.
prebuilt = glob . glob ( os . path . join ( prebuilt_dir , 'libdrmtap.so.0.*' ))
return _single_real_so ( prebuilt , f 'DRMTAP_PREBUILT_DIR= { prebuilt_dir } ' )
2026-07-28 06:22:49 -03:00
# Fetch the pinned source if it is not already present. third_party/libdrmtap is not a submodule
# anymore; it is git-ignored. The commit is fetched BY SHA rather than by cloning a branch:
# `clone --depth 1 --branch main` only ever fetches the tip, so the moment upstream pushes to
# `main` the pinned commit is not in the shallow clone at all and the build fails on an unreachable
# object. Fetching the sha needs no branch name, so it keeps working across every upstream push and
# is immune to a ref being moved or repointed.
2026-07-17 20:55:26 -03:00
src = os . path . join ( repo_root , 'third_party' , 'libdrmtap' )
if not os . path . exists ( os . path . join ( src , 'meson.build' )):
if os . path . isdir ( src ):
shutil . rmtree ( src )
2026-07-28 06:22:49 -03:00
os . makedirs ( src , exist_ok = True )
system2 ( f 'git -C { src } init -q' )
system2 ( f 'git -C { src } remote add origin { LIBDRMTAP_REPO } ' )
system2 ( f 'git -C { src } fetch --depth 1 origin { LIBDRMTAP_SHA } ' )
system2 ( f 'git -C { src } checkout -q FETCH_HEAD' )
# Verify the pin whenever the source is a GIT checkout. A fetch by sha cannot resolve to anything
# else, so this now guards the OTHER case: a reused checkout left by an earlier build at a
# different pin, which is what a bump leaves behind. Reject and remove it so the next run re-fetches
# cleanly. A NON-git tree placed here on purpose (a developer building unreleased local libdrmtap
# source) has nothing to verify and is used as-is.
2026-07-21 01:43:40 -03:00
if os . path . isdir ( os . path . join ( src , '.git' )):
2026-07-21 00:31:12 -03:00
got_sha = subprocess . check_output (
[ 'git' , '-C' , src , 'rev-parse' , 'HEAD' ]) . decode () . strip ()
2026-07-21 01:43:40 -03:00
if got_sha != LIBDRMTAP_SHA :
shutil . rmtree ( src , ignore_errors = True )
raise Exception (
2026-07-28 06:22:49 -03:00
f 'libdrmtap at { src } is { got_sha } , expected { LIBDRMTAP_SHA } '
f '(stale checkout from a different pin; removed, re-run to re-fetch)' )
2026-07-17 20:55:26 -03:00
build_dir = os . path . join ( src , 'build-pkg' )
if not os . path . exists ( os . path . join ( build_dir , 'build.ninja' )):
system2 ( f 'meson setup { build_dir } { src } --buildtype=release' )
2026-07-21 01:52:04 -03:00
# Build only the shared library, not the bundled helper binary or the static archive. Since
# libdrmtap 0.4.11 the project is `both_libraries` (a version-scripted .so + a static .a), so the
# bare `drmtap` target is ambiguous ("drmtap:shared_library" vs "drmtap:static_library"); ask for
# the shared one explicitly (rustdesk dlopens the .so and never needs the archive).
system2 ( f 'meson compile -C { build_dir } drmtap:shared_library' )
2026-07-17 20:55:26 -03:00
sos = glob . glob ( os . path . join ( build_dir , 'libdrmtap.so.0.*' ))
# keep the real object (libdrmtap.so.0.4.x), not the .so/.so.0 symlinks or meson's .p dir, and
# require exactly one so a stale object from an earlier build is never silently picked.
return _single_real_so ( sos , f 'the libdrmtap meson build dir { build_dir } ' )
2026-07-28 06:45:04 -03:00
DRM_PACKAGE_NAME = 'rustdesk-unattended-wayland'
def stage_libdrmtap_into_deb ( so_path ):
# Put the built libdrmtap object plus its soname symlink into the staged deb. Only the soname
# symlink is needed: libdrmtap is resolved by ABSOLUTE path (/usr/lib/rustdesk/libdrmtap.so.0) at
# the in-process dlopen site (drmtap_dl.rs), so the deb does NOT drop /usr/lib/rustdesk into the
# system-wide /etc/ld.so.conf.d search path, which would let this private library shadow a system
# library for every binary on the host (Debian Policy 10.2 forbids that). No ld.so.conf.d drop-in
# and no ldconfig trigger are shipped, so the stock postinst is used unchanged.
so_basename = os . path . basename ( so_path )
system2 ( 'mkdir -p tmpdeb/usr/lib/rustdesk' )
system2 ( f 'cp { so_path } tmpdeb/usr/lib/rustdesk/' )
system2 ( f 'ln -sf { so_basename } tmpdeb/usr/lib/rustdesk/libdrmtap.so.0' )
def retarget_control_to_drm_variant ():
# Rewrite the control file that generate_control_file just produced, instead of parameterizing that
# function: the stock packaging path stays exactly as upstream wrote it, and everything specific to
# this variant lives here. The variant installs the same files as the stock package, so it must
# conflict with and replace it: you install one or the other, never both. It also needs libdrmtap's
# own runtime deps, which the stock package has no reason to carry.
path = '../res/DEBIAN/control'
with open ( path ) as f :
lines = f . readlines ()
out = []
for line in lines :
if line . startswith ( 'Package: rustdesk' ):
out . append ( f 'Package: { DRM_PACKAGE_NAME } \n ' )
out . append ( 'Conflicts: rustdesk \n Replaces: rustdesk \n Provides: rustdesk \n ' )
elif line . startswith ( 'Depends:' ):
out . append ( line . rstrip ( ' \n ' ) + ', libdrm2, libegl1, libgles2 \n ' )
else :
out . append ( line )
body = '' . join ( out )
# Fail loudly rather than silently shipping a package that says `rustdesk`: a stock control file
# that stopped matching either anchor would otherwise produce a variant deb wearing the stock name.
if f 'Package: { DRM_PACKAGE_NAME } \n ' not in body or 'libegl1' not in body :
raise Exception ( f 'could not retarget { path } to the drm variant; upstream control layout changed' )
with open ( path , 'w' ) as f :
f . write ( body )
2026-07-17 20:55:26 -03:00
2022-10-22 12:41:37 +08:00
def build_flutter_deb ( version , features ):
2022-11-21 17:10:38 +08:00
if not skip_cargo :
2026-05-26 11:44:51 +08:00
system2 ( f 'cargo build --locked --features { features } --lib --release' )
2022-11-21 17:10:38 +08:00
ffi_bindgen_function_refactor ()
2022-08-25 18:36:44 +08:00
os . chdir ( 'flutter' )
2023-02-27 20:28:55 +08:00
system2 ( 'flutter build linux --release' )
system2 ( 'mkdir -p tmpdeb/usr/bin/' )
2024-12-21 14:53:28 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/rustdesk' )
2023-03-23 18:40:25 +08:00
system2 ( 'mkdir -p tmpdeb/etc/rustdesk/' )
system2 ( 'mkdir -p tmpdeb/etc/pam.d/' )
2023-02-27 20:28:55 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/' )
2023-08-01 19:33:06 +02:00
system2 ( 'mkdir -p tmpdeb/usr/share/icons/hicolor/256x256/apps/' )
system2 ( 'mkdir -p tmpdeb/usr/share/icons/hicolor/scalable/apps/' )
2023-02-27 20:28:55 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/applications/' )
system2 ( 'mkdir -p tmpdeb/usr/share/polkit-1/actions' )
system2 ( 'rm tmpdeb/usr/bin/rustdesk || true' )
system2 (
2024-12-21 14:53:28 +08:00
f 'cp -r { flutter_build_dir } /* tmpdeb/usr/share/rustdesk/' )
2023-02-27 20:28:55 +08:00
system2 (
2022-09-18 11:50:23 +08:00
'cp ../res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/' )
2023-02-27 20:28:55 +08:00
system2 (
2023-08-01 00:36:19 +02:00
'cp ../res/128x128@2x.png tmpdeb/usr/share/icons/hicolor/256x256/apps/rustdesk.png' )
2023-08-01 00:54:21 +02:00
system2 (
'cp ../res/scalable.svg tmpdeb/usr/share/icons/hicolor/scalable/apps/rustdesk.svg' )
2023-02-27 20:28:55 +08:00
system2 (
2022-09-18 11:50:23 +08:00
'cp ../res/rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop' )
2023-02-27 20:28:55 +08:00
system2 (
2022-10-11 19:52:03 +08:00
'cp ../res/rustdesk-link.desktop tmpdeb/usr/share/applications/rustdesk-link.desktop' )
2023-03-23 18:40:25 +08:00
system2 (
'cp ../res/startwm.sh tmpdeb/etc/rustdesk/' )
system2 (
'cp ../res/xorg.conf tmpdeb/etc/rustdesk/' )
system2 (
'cp ../res/pam.d/rustdesk.debian tmpdeb/etc/pam.d/rustdesk' )
2023-02-27 20:28:55 +08:00
system2 (
2022-10-22 12:41:37 +08:00
"echo \" #!/bin/sh \" >> tmpdeb/usr/share/rustdesk/files/polkit && chmod a+x tmpdeb/usr/share/rustdesk/files/polkit" )
2026-07-28 06:45:04 -03:00
# Bundle libdrmtap.so only when this build actually enabled the `drm` feature, so stock packages
# stay exactly what they were. The root service dlopens it in-process by absolute path.
2026-07-17 20:55:26 -03:00
ships_so = 'drm' in features
if ships_so :
2026-07-28 06:45:04 -03:00
stage_libdrmtap_into_deb ( build_libdrmtap_so ())
system2 ( 'mkdir -p tmpdeb/DEBIAN' )
generate_control_file ( version )
if ships_so :
retarget_control_to_drm_variant ()
system2 ( 'cp -a ../res/DEBIAN/* tmpdeb/DEBIAN/' )
md5_file_folder ( "tmpdeb/" )
system2 ( 'dpkg-deb -b tmpdeb rustdesk.deb;' )
system2 ( '/bin/rm -rf tmpdeb/' )
system2 ( '/bin/rm -rf ../res/DEBIAN/control' )
os . rename ( 'rustdesk.deb' , '../rustdesk- %s .deb' % version )
if ships_so :
# Named apart from the stock package so installing the consent-free variant is a deliberate act.
os . rename ( '../rustdesk- %s .deb' % version , f '../ { DRM_PACKAGE_NAME } - { version } .deb' )
2022-08-25 18:36:44 +08:00
os . chdir ( ".." )
2023-10-30 00:06:53 +08:00
2026-07-21 15:13:33 -03:00
def build_deb_from_folder ( version , binary_folder , want_drm = False ):
2023-03-27 15:26:20 +08:00
os . chdir ( 'flutter' )
system2 ( 'mkdir -p tmpdeb/usr/bin/' )
2024-12-21 14:53:28 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/rustdesk' )
2023-03-27 15:26:20 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/' )
2023-08-01 19:33:06 +02:00
system2 ( 'mkdir -p tmpdeb/usr/share/icons/hicolor/256x256/apps/' )
system2 ( 'mkdir -p tmpdeb/usr/share/icons/hicolor/scalable/apps/' )
2023-03-27 15:26:20 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/applications/' )
system2 ( 'mkdir -p tmpdeb/usr/share/polkit-1/actions' )
system2 ( 'rm tmpdeb/usr/bin/rustdesk || true' )
system2 (
2024-12-21 14:53:28 +08:00
f 'cp -r ../ { binary_folder } /* tmpdeb/usr/share/rustdesk/' )
2023-03-27 15:26:20 +08:00
system2 (
'cp ../res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/' )
system2 (
2023-08-01 00:36:19 +02:00
'cp ../res/128x128@2x.png tmpdeb/usr/share/icons/hicolor/256x256/apps/rustdesk.png' )
2023-08-01 00:54:21 +02:00
system2 (
'cp ../res/scalable.svg tmpdeb/usr/share/icons/hicolor/scalable/apps/rustdesk.svg' )
2023-03-27 15:26:20 +08:00
system2 (
'cp ../res/rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop' )
system2 (
'cp ../res/rustdesk-link.desktop tmpdeb/usr/share/applications/rustdesk-link.desktop' )
system2 (
"echo \" #!/bin/sh \" >> tmpdeb/usr/share/rustdesk/files/polkit && chmod a+x tmpdeb/usr/share/rustdesk/files/polkit" )
2026-07-17 20:55:26 -03:00
# A staged bundle (binary_folder) carries its own libdrmtap.so.0* for a --drm build, so we do
# not rebuild it here; the `cp -r` above placed it under usr/share/rustdesk/. Move it to the
# private lib dir, then finalize the deb the same way build_flutter_deb does.
bundled_glob = glob . glob ( 'tmpdeb/usr/share/rustdesk/libdrmtap.so.0.*' )
ships_so = any ( os . path . isfile ( p ) and not os . path . islink ( p ) for p in bundled_glob )
2026-07-21 15:13:33 -03:00
# The variant must be decided by the EXPLICIT --drm request, not merely by what happens
# to be staged. Cross-check the two and fail loudly on a mismatch: a drm binary staged
# WITHOUT its libdrmtap.so.0.* would otherwise be silently shipped as the stock
2026-07-21 18:11:58 -03:00
# `rustdesk` package (no drm deps, a dlopen that can never resolve), and a
2026-07-21 15:13:33 -03:00
# bundle that DOES carry the .so would be shipped as the consent-bypass variant even
# when --drm was never asked for.
if want_drm and not ships_so :
raise Exception (
'--drm was requested but no real libdrmtap.so.0.* is staged under '
'usr/share/rustdesk/ in the bundle; refusing to package a drm binary as the '
'stock rustdesk package (it would ship without the capture library or its deps)' )
if ships_so and not want_drm :
raise Exception (
'the staged bundle carries libdrmtap.so.0.* but --drm was not passed; refusing '
'to silently ship the consent-bypass unattended-wayland variant (pass --drm to '
'build it deliberately)' )
2026-07-17 20:55:26 -03:00
if ships_so :
so = _single_real_so ( bundled_glob , 'the staged --drm bundle' )
2026-07-28 06:45:04 -03:00
stage_libdrmtap_into_deb ( so )
system2 ( f 'rm -f { so } ' )
2026-07-17 20:55:26 -03:00
system2 ( 'rm -f tmpdeb/usr/share/rustdesk/libdrmtap.so tmpdeb/usr/share/rustdesk/libdrmtap.so.0' )
2026-07-28 06:45:04 -03:00
system2 ( 'mkdir -p tmpdeb/DEBIAN' )
generate_control_file ( version )
if ships_so :
retarget_control_to_drm_variant ()
system2 ( 'cp -a ../res/DEBIAN/* tmpdeb/DEBIAN/' )
md5_file_folder ( "tmpdeb/" )
system2 ( 'dpkg-deb -b tmpdeb rustdesk.deb;' )
system2 ( '/bin/rm -rf tmpdeb/' )
system2 ( '/bin/rm -rf ../res/DEBIAN/control' )
os . rename ( 'rustdesk.deb' , '../rustdesk- %s .deb' % version )
if ships_so :
os . rename ( '../rustdesk- %s .deb' % version , f '../ { DRM_PACKAGE_NAME } - { version } .deb' )
2023-03-27 15:26:20 +08:00
os . chdir ( ".." )
2022-08-25 18:36:44 +08:00
2023-10-30 00:06:53 +08:00
2022-11-20 16:40:59 +08:00
def build_flutter_dmg ( version , features ):
2022-11-21 17:10:38 +08:00
if not skip_cargo :
2023-01-06 10:23:46 +08:00
# set minimum osx build target, now is 10.14, which is the same as the flutter xcode project
2023-10-30 00:06:53 +08:00
system2 (
2026-05-26 11:44:51 +08:00
f 'MACOSX_DEPLOYMENT_TARGET=10.14 cargo build --locked --features { features } --release' )
2022-11-20 16:54:54 +08:00
# copy dylib
2023-02-27 20:28:55 +08:00
system2 (
2022-11-20 16:54:54 +08:00
"cp target/release/liblibrustdesk.dylib target/release/librustdesk.dylib" )
2022-11-20 16:40:59 +08:00
os . chdir ( 'flutter' )
2026-06-18 16:37:15 +02:00
# cargo builds a single-arch dylib for the host; restrict Xcode to the same arch
# so the universal-by-default ARCHS_STANDARD doesn't try to link a missing slice.
# FLUTTER_XCODE_* env vars are forwarded to xcodebuild as build settings.
mac_arch = 'arm64' if platform . machine () . lower () in ( 'arm64' , 'aarch64' ) else 'x86_64'
system2 (
f 'FLUTTER_XCODE_ARCHS= { mac_arch } FLUTTER_XCODE_ONLY_ACTIVE_ARCH=YES flutter build macos --release' )
2025-01-01 23:05:52 +08:00
system2 ( 'cp -rf ../target/release/service ./build/macos/Build/Products/Release/RustDesk.app/Contents/MacOS/' )
2024-03-24 14:04:05 +08:00
'''
2023-02-27 20:28:55 +08:00
system2(
2023-02-28 19:25:14 +08:00
"create-dmg --volname \" RustDesk Installer \" --window-pos 200 120 --window-size 800 400 --icon-size 100 --app-drop-link 600 185 --icon RustDesk.app 200 190 --hide-extension RustDesk.app rustdesk.dmg ./build/macos/Build/Products/Release/RustDesk.app")
2022-11-20 16:54:54 +08:00
os.rename("rustdesk.dmg", f"../rustdesk- {version} .dmg")
2024-03-24 14:04:05 +08:00
'''
2022-11-20 16:54:54 +08:00
os . chdir ( ".." )
2022-11-20 16:40:59 +08:00
2022-10-22 12:41:37 +08:00
def build_flutter_arch_manjaro ( version , features ):
2022-11-21 17:10:38 +08:00
if not skip_cargo :
2026-05-26 11:44:51 +08:00
system2 ( f 'cargo build --locked --features { features } --lib --release' )
2022-10-22 12:41:37 +08:00
ffi_bindgen_function_refactor ()
2022-08-25 18:36:44 +08:00
os . chdir ( 'flutter' )
2023-02-27 20:28:55 +08:00
system2 ( 'flutter build linux --release' )
2023-04-17 15:16:55 +08:00
system2 ( f 'strip { flutter_build_dir } /lib/librustdesk.so' )
2022-10-22 12:41:37 +08:00
os . chdir ( '../res' )
2023-02-27 20:28:55 +08:00
system2 ( 'HBB=`pwd`/.. FLUTTER=1 makepkg -f' )
2022-08-25 18:36:44 +08:00
2022-10-22 12:41:37 +08:00
2024-02-26 02:20:37 +08:00
def build_flutter_windows ( version , features , skip_portable_pack ):
2022-11-21 17:10:38 +08:00
if not skip_cargo :
2026-05-26 11:44:51 +08:00
system2 ( f 'cargo build --locked --features { features } --lib --release' )
2022-11-21 17:10:38 +08:00
if not os . path . exists ( "target/release/librustdesk.dll" ):
print ( "cargo build failed, please check rust source code." )
exit ( - 1 )
2022-09-21 11:28:28 +08:00
os . chdir ( 'flutter' )
2023-02-27 20:28:55 +08:00
system2 ( 'flutter build windows --release' )
2022-09-21 11:28:28 +08:00
os . chdir ( '..' )
2022-11-20 16:54:54 +08:00
shutil . copy2 ( 'target/release/deps/dylib_virtual_display.dll' ,
2023-04-17 15:16:55 +08:00
flutter_build_dir_2 )
2024-02-26 02:20:37 +08:00
if skip_portable_pack :
return
2022-10-21 17:24:07 +08:00
os . chdir ( 'libs/portable' )
2023-02-27 20:28:55 +08:00
system2 ( 'pip3 install -r requirements.txt' )
system2 (
2023-04-17 15:16:55 +08:00
f 'python3 ./generate.py -f ../../ { flutter_build_dir_2 } -o . -e ../../ { flutter_build_dir_2 } /rustdesk.exe' )
2022-10-21 17:24:07 +08:00
os . chdir ( '../..' )
if os . path . exists ( './rustdesk_portable.exe' ):
2022-11-20 16:54:54 +08:00
os . replace ( './target/release/rustdesk-portable-packer.exe' ,
'./rustdesk_portable.exe' )
2022-09-21 11:28:28 +08:00
else :
2022-11-20 16:54:54 +08:00
os . rename ( './target/release/rustdesk-portable-packer.exe' ,
'./rustdesk_portable.exe' )
print (
f 'output location: { os . path . abspath ( os . curdir ) } /rustdesk_portable.exe' )
2022-10-21 17:24:07 +08:00
os . rename ( './rustdesk_portable.exe' , f './rustdesk- { version } -install.exe' )
2022-11-20 16:54:54 +08:00
print (
f 'output location: { os . path . abspath ( os . curdir ) } /rustdesk- { version } -install.exe' )
2022-08-25 18:36:44 +08:00
2022-10-22 12:41:37 +08:00
2022-04-18 15:37:35 +08:00
def main ():
2022-11-21 17:10:38 +08:00
global skip_cargo
2022-05-28 18:42:38 +08:00
parser = make_parser ()
args = parser . parse_args ()
2022-04-18 15:37:35 +08:00
if os . path . exists ( exe_path ):
os . unlink ( exe_path )
if os . path . isfile ( '/usr/bin/pacman' ):
2023-02-27 20:28:55 +08:00
system2 ( 'git checkout src/ui/common.tis' )
2022-04-18 15:37:35 +08:00
version = get_version ()
2022-10-21 17:24:07 +08:00
features = ',' . join ( get_features ( args ))
2022-08-25 17:35:45 +08:00
flutter = args . flutter
2022-11-20 16:54:54 +08:00
if not flutter :
2023-02-27 20:28:55 +08:00
system2 ( 'python3 res/inline-sciter.py' )
2022-11-21 17:10:38 +08:00
print ( args . skip_cargo )
if args . skip_cargo :
skip_cargo = True
2022-09-21 11:28:28 +08:00
portable = args . portable
2023-03-27 15:26:20 +08:00
package = args . package
if package :
2026-07-21 15:13:33 -03:00
build_deb_from_folder ( version , package , args . drm )
2023-03-27 15:26:20 +08:00
return
2023-04-17 15:16:55 +08:00
res_dir = 'resources'
external_resources ( flutter , args , res_dir )
2022-04-18 15:37:35 +08:00
if windows :
2022-11-18 17:09:52 +08:00
# build virtual display dynamic library
os . chdir ( 'libs/virtual_display/dylib' )
2026-05-26 11:44:51 +08:00
system2 ( 'cargo build --locked --release' )
2022-11-18 17:09:52 +08:00
os . chdir ( '../../..' )
2023-03-07 20:42:40 +08:00
2022-10-11 14:52:46 +08:00
if flutter :
2024-02-26 02:20:37 +08:00
build_flutter_windows ( version , features , args . skip_portable_pack )
2022-09-21 11:28:28 +08:00
return
2026-05-26 11:44:51 +08:00
system2 ( 'cargo build --locked --release --features ' + features )
2023-02-27 20:28:55 +08:00
# system2('upx.exe target/release/rustdesk.exe')
system2 ( 'mv target/release/rustdesk.exe target/release/RustDesk.exe' )
2022-05-01 23:39:03 +08:00
pa = os . environ . get ( 'P' )
if pa :
2024-02-19 23:23:00 +08:00
# https://certera.com/kb/tutorial-guide-for-safenet-authentication-client-for-code-signing/
2023-02-27 20:28:55 +08:00
system2 (
2022-10-22 12:41:37 +08:00
f 'signtool sign /a /v /p { pa } /debug /f . \\ cert.pfx /t http://timestamp.digicert.com '
'target \\ release \\ rustdesk.exe' )
2022-05-01 23:39:03 +08:00
else :
2022-05-28 18:42:38 +08:00
print ( 'Not signed' )
2026-06-18 16:37:15 +02:00
os . makedirs ( res_dir , exist_ok = True )
2023-02-27 20:28:55 +08:00
system2 (
2023-04-17 15:16:55 +08:00
f 'cp -rf target/release/RustDesk.exe { res_dir } ' )
os . chdir ( 'libs/portable' )
system2 ( 'pip3 install -r requirements.txt' )
system2 (
2023-04-17 15:26:50 +08:00
f 'python3 ./generate.py -f ../../ { res_dir } -o . -e ../../ { res_dir } /rustdesk- { version } -win7-install.exe' )
2026-04-28 09:08:10 +02:00
system2 ( f 'mv ../../ { res_dir } /rustdesk- { version } -win7-install.exe ../..' )
2022-10-05 18:32:20 +08:00
elif os . path . isfile ( '/usr/bin/pacman' ):
2022-09-12 19:17:46 +08:00
# pacman -S -needed base-devel
2023-02-27 20:28:55 +08:00
system2 ( "sed -i 's/pkgver=.*/pkgver= %s /g' res/PKGBUILD" % version )
2022-08-25 17:35:45 +08:00
if flutter :
2022-10-22 12:41:37 +08:00
build_flutter_arch_manjaro ( version , features )
2022-08-25 17:35:45 +08:00
else :
2026-05-26 11:44:51 +08:00
system2 ( 'cargo build --locked --release --features ' + features )
2023-02-27 20:28:55 +08:00
system2 ( 'git checkout src/ui/common.tis' )
system2 ( 'strip target/release/rustdesk' )
system2 ( 'ln -s res/pacman_install && ln -s res/PKGBUILD' )
system2 ( 'HBB=`pwd` makepkg -f' )
system2 ( 'mv rustdesk- %s -0-x86_64.pkg.tar.zst rustdesk- %s -manjaro-arch.pkg.tar.zst' % (
2022-11-20 16:54:54 +08:00
version , version ))
2022-09-12 19:17:46 +08:00
# pacman -U ./rustdesk.pkg.tar.zst
2022-05-23 11:59:56 +08:00
elif os . path . isfile ( '/usr/bin/yum' ):
2026-05-26 11:44:51 +08:00
system2 ( 'cargo build --locked --release --features ' + features )
2023-02-27 20:28:55 +08:00
system2 ( 'strip target/release/rustdesk' )
system2 (
2022-11-20 16:54:54 +08:00
"sed -i 's/Version: .*/Version: %s /g' res/rpm.spec" % version )
2023-02-27 20:28:55 +08:00
system2 ( 'HBB=`pwd` rpmbuild -ba res/rpm.spec' )
system2 (
2022-10-22 12:41:37 +08:00
'mv $HOME/rpmbuild/RPMS/x86_64/rustdesk- %s -0.x86_64.rpm ./rustdesk- %s -fedora28-centos8.rpm' % (
version , version ))
2022-05-23 11:59:56 +08:00
# yum localinstall rustdesk.rpm
elif os . path . isfile ( '/usr/bin/zypper' ):
2026-05-26 11:44:51 +08:00
system2 ( 'cargo build --locked --release --features ' + features )
2023-02-27 20:28:55 +08:00
system2 ( 'strip target/release/rustdesk' )
system2 (
2022-11-20 16:54:54 +08:00
"sed -i 's/Version: .*/Version: %s /g' res/rpm-suse.spec" % version )
2023-02-27 20:28:55 +08:00
system2 ( 'HBB=`pwd` rpmbuild -ba res/rpm-suse.spec' )
system2 (
2022-10-22 12:41:37 +08:00
'mv $HOME/rpmbuild/RPMS/x86_64/rustdesk- %s -0.x86_64.rpm ./rustdesk- %s -suse.rpm' % (
2022-11-20 16:54:54 +08:00
version , version ))
2022-05-23 11:59:56 +08:00
# yum localinstall rustdesk.rpm
2022-04-18 15:37:35 +08:00
else :
2022-08-25 18:36:44 +08:00
if flutter :
if osx :
2022-11-20 16:40:59 +08:00
build_flutter_dmg ( version , features )
2022-08-25 18:36:44 +08:00
pass
2022-05-01 23:39:03 +08:00
else :
2023-02-27 20:28:55 +08:00
# system2(
2022-11-21 17:10:38 +08:00
# 'mv target/release/bundle/deb/rustdesk*.deb ./flutter/rustdesk.deb')
2022-10-22 12:41:37 +08:00
build_flutter_deb ( version , features )
2022-04-18 15:37:35 +08:00
else :
2026-05-26 11:44:51 +08:00
system2 ( 'cargo --locked bundle --release --features ' + features )
2022-08-25 18:36:44 +08:00
if osx :
2023-02-27 20:28:55 +08:00
system2 (
2022-08-25 18:36:44 +08:00
'strip target/release/bundle/osx/RustDesk.app/Contents/MacOS/rustdesk' )
2023-02-27 20:28:55 +08:00
system2 (
2022-08-25 18:36:44 +08:00
'cp libsciter.dylib target/release/bundle/osx/RustDesk.app/Contents/MacOS/' )
# https://github.com/sindresorhus/create-dmg
2023-02-27 20:28:55 +08:00
system2 ( '/bin/rm -rf *.dmg' )
2022-08-25 18:36:44 +08:00
pa = os . environ . get ( 'P' )
if pa :
2023-02-27 20:28:55 +08:00
system2 ( '''
2022-08-25 18:36:44 +08:00
# buggy: rcodesign sign ... path/*, have to sign one by one
2023-01-05 21:04:40 +08:00
# install rcodesign via cargo install apple-codesign
2022-08-25 18:36:44 +08:00
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./target/release/bundle/osx/RustDesk.app/Contents/MacOS/rustdesk
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./target/release/bundle/osx/RustDesk.app/Contents/MacOS/libsciter.dylib
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./target/release/bundle/osx/RustDesk.app
# goto "Keychain Access" -> "My Certificates" for below id which starts with "Developer ID Application:"
codesign -s "Developer ID Application: {0} " --force --options runtime ./target/release/bundle/osx/RustDesk.app/Contents/MacOS/*
codesign -s "Developer ID Application: {0} " --force --options runtime ./target/release/bundle/osx/RustDesk.app
''' . format ( pa ))
2023-10-30 00:06:53 +08:00
system2 (
'create-dmg "RustDesk %s .dmg" "target/release/bundle/osx/RustDesk.app"' % version )
2022-08-25 18:36:44 +08:00
os . rename ( 'RustDesk %s .dmg' %
version , 'rustdesk- %s .dmg' % version )
if pa :
2023-02-27 20:28:55 +08:00
system2 ( '''
2023-01-05 17:45:41 +08:00
# https://pyoxidizer.readthedocs.io/en/apple-codesign-0.14.0/apple_codesign.html
# https://pyoxidizer.readthedocs.io/en/stable/tugger_code_signing.html
# https://developer.apple.com/developer-id/
# goto xcode and login with apple id, manager certificates (Developer ID Application and/or Developer ID Installer) online there (only download and double click (install) cer file can not export p12 because no private key)
2022-08-25 18:36:44 +08:00
#rcodesign sign --p12-file ~/.p12/rustdesk-developer-id.p12 --p12-password-file ~/.p12/.cert-pass --code-signature-flags runtime ./rustdesk- {1} .dmg
codesign -s "Developer ID Application: {0} " --force --options runtime ./rustdesk- {1} .dmg
2023-01-05 17:45:41 +08:00
# https://appstoreconnect.apple.com/access/api
2023-06-24 02:59:50 +08:00
# https://gregoryszorc.com/docs/apple-codesign/stable/apple_codesign_getting_started.html#apple-codesign-app-store-connect-api-key
# p8 file is generated when you generate api key (can download only once)
rcodesign notary-submit --api-key-path ../.p12/api-key.json --staple rustdesk- {1} .dmg
2022-08-25 18:36:44 +08:00
# verify: spctl -a -t exec -v /Applications/RustDesk.app
2023-06-24 02:59:50 +08:00
''' . format ( pa , version ))
2022-08-25 18:36:44 +08:00
else :
print ( 'Not signed' )
else :
2023-10-28 10:57:50 +02:00
# build deb package
2023-02-27 20:28:55 +08:00
system2 (
2022-08-25 18:36:44 +08:00
'mv target/release/bundle/deb/rustdesk*.deb ./rustdesk.deb' )
2023-02-27 20:28:55 +08:00
system2 ( 'dpkg-deb -R rustdesk.deb tmpdeb' )
system2 ( 'mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/' )
2023-08-01 19:33:06 +02:00
system2 ( 'mkdir -p tmpdeb/usr/share/icons/hicolor/256x256/apps/' )
system2 ( 'mkdir -p tmpdeb/usr/share/icons/hicolor/scalable/apps/' )
2023-02-27 20:28:55 +08:00
system2 (
2022-09-18 11:50:23 +08:00
'cp res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/' )
2023-02-27 20:28:55 +08:00
system2 (
2023-08-01 00:36:19 +02:00
'cp res/128x128@2x.png tmpdeb/usr/share/icons/hicolor/256x256/apps/rustdesk.png' )
2023-08-01 00:54:21 +02:00
system2 (
'cp res/scalable.svg tmpdeb/usr/share/icons/hicolor/scalable/apps/rustdesk.svg' )
2023-02-27 20:28:55 +08:00
system2 (
2022-09-18 11:50:23 +08:00
'cp res/rustdesk.desktop tmpdeb/usr/share/applications/rustdesk.desktop' )
2023-02-27 20:28:55 +08:00
system2 (
2022-10-11 19:52:03 +08:00
'cp res/rustdesk-link.desktop tmpdeb/usr/share/applications/rustdesk-link.desktop' )
2023-03-23 18:40:25 +08:00
os . system ( 'mkdir -p tmpdeb/etc/rustdesk/' )
os . system ( 'cp -a res/startwm.sh tmpdeb/etc/rustdesk/' )
os . system ( 'mkdir -p tmpdeb/etc/X11/rustdesk/' )
os . system ( 'cp res/xorg.conf tmpdeb/etc/X11/rustdesk/' )
os . system ( 'cp -a DEBIAN/* tmpdeb/DEBIAN/' )
os . system ( 'mkdir -p tmpdeb/etc/pam.d/' )
os . system ( 'cp pam.d/rustdesk.debian tmpdeb/etc/pam.d/rustdesk' )
2023-02-27 20:28:55 +08:00
system2 ( 'strip tmpdeb/usr/bin/rustdesk' )
2024-12-21 14:53:28 +08:00
system2 ( 'mkdir -p tmpdeb/usr/share/rustdesk' )
system2 ( 'mv tmpdeb/usr/bin/rustdesk tmpdeb/usr/share/rustdesk/' )
system2 ( 'cp libsciter-gtk.so tmpdeb/usr/share/rustdesk/' )
2024-12-25 00:04:34 +08:00
md5_file_folder ( "tmpdeb/" )
2023-02-27 20:28:55 +08:00
system2 ( 'dpkg-deb -b tmpdeb rustdesk.deb; /bin/rm -rf tmpdeb/' )
2022-08-25 18:36:44 +08:00
os . rename ( 'rustdesk.deb' , 'rustdesk- %s .deb' % version )
2022-04-18 15:37:35 +08:00
def md5_file ( fn ):
md5 = hashlib . md5 ( open ( 'tmpdeb/' + fn , 'rb' ) . read ()) . hexdigest ()
2024-12-25 00:04:34 +08:00
system2 ( 'echo " %s / %s " >> tmpdeb/DEBIAN/md5sums' % ( md5 , fn ))
def md5_file_folder ( base_dir ):
base_path = Path ( base_dir )
for file in base_path . rglob ( '*' ):
if file . is_file () and 'DEBIAN' not in file . parts :
relative_path = file . relative_to ( base_path )
md5_file ( str ( relative_path ))
2022-04-18 15:37:35 +08:00
if __name__ == "__main__" :
main ()