-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·189 lines (155 loc) · 5.53 KB
/
build.py
File metadata and controls
executable file
·189 lines (155 loc) · 5.53 KB
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
#!/usr/bin/env python3
import os
import pathlib
import platform
import zipfile
import urllib.request
import shutil
import hashlib
import argparse
import sys
from pathlib import Path
windows = platform.platform().startswith('Windows')
hbb_name = 'rustdesk' + ('.exe' if windows else '')
exe_path = 'target/release/' + hbb_name
if windows:
flutter_build_dir = 'build/windows/x64/runner/Release/'
else:
# Android or other
flutter_build_dir = ''
flutter_build_dir_2 = f'flutter/{flutter_build_dir}'
skip_cargo = False
def system2(cmd):
exit_code = os.system(cmd)
if exit_code != 0:
sys.stderr.write(f"Error occurred when executing: `{cmd}`. Exiting.\n")
sys.exit(-1)
def get_version():
with open("Cargo.toml", encoding="utf-8") as fh:
for line in fh:
if line.startswith("version"):
return line.replace("version", "").replace("=", "").replace('"', '').strip()
return '1.2.3' # Default fallback
def parse_rc_features(feature):
if not feature:
return {}
# Simple implementation for now as we don't have available_features mapping here
return {f: True for f in 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.')
parser.add_argument('--flutter', action='store_true',
help='Build flutter package', default=False)
parser.add_argument(
'--hwcodec',
action='store_true',
help='Enable feature hwcodec'
)
parser.add_argument(
'--vram',
action='store_true',
help='Enable feature vram, only available on windows now.'
)
parser.add_argument(
'--portable',
action='store_true',
help='Build windows portable'
)
parser.add_argument(
'--skip-cargo',
action='store_true',
help='Skip cargo build process'
)
if windows:
parser.add_argument(
'--skip-portable-pack',
action='store_true',
help='Skip packing, only flutter version + Windows supported'
)
return parser
def get_features(args):
features = ['inline'] if not args.flutter else []
if args.hwcodec:
features.append('hwcodec')
if args.vram:
features.append('vram')
if args.flutter:
features.append('flutter')
print("features:", features)
return features
def download_extract_features(features, res_dir):
# This is a complex function, keeping a simplified version if needed
pass
def external_resources(flutter, args, res_dir):
# Simplified external resources
pass
def build_flutter_windows(version, features, skip_portable_pack):
if not skip_cargo:
system2(f'cargo build --features {features} --lib --release')
if not os.path.exists("target/release/librustdesk.dll"):
print("cargo build failed, please check rust source code.")
exit(-1)
os.chdir('flutter')
system2('flutter build windows --release')
os.chdir('..')
# Try to copy virtual display dylib if it exists
vdisplay_dll = 'target/release/deps/dylib_virtual_display.dll'
if os.path.exists(vdisplay_dll):
shutil.copy2(vdisplay_dll, flutter_build_dir_2)
if skip_portable_pack:
return
if os.path.exists('libs/portable'):
os.chdir('libs/portable')
# We assume requirements are met or can be met
# system2('pip3 install -r requirements.txt')
system2(f'python3 ./generate.py -f ../../{flutter_build_dir_2} -o . -e ../../{flutter_build_dir_2}/rustdesk.exe')
os.chdir('../..')
if os.path.exists('./rustdesk_portable.exe'):
os.replace('./target/release/rustdesk-portable-packer.exe', './rustdesk_portable.exe')
else:
os.rename('./target/release/rustdesk-portable-packer.exe', './rustdesk_portable.exe')
os.rename('./rustdesk_portable.exe', f'./rustdesk-{version}-install.exe')
def main():
global skip_cargo
parser = make_parser()
args = parser.parse_args()
if os.path.exists(exe_path):
os.unlink(exe_path)
version = get_version()
features = ','.join(get_features(args))
flutter = args.flutter
if not flutter:
if os.path.exists('res/inline-sciter.py'):
system2('python3 res/inline-sciter.py')
if args.skip_cargo:
skip_cargo = True
res_dir = 'resources'
external_resources(flutter, args, res_dir)
if windows:
if os.path.exists('libs/virtual_display/dylib'):
os.chdir('libs/virtual_display/dylib')
system2('cargo build --release')
os.chdir('../../..')
if flutter:
build_flutter_windows(version, features, args.skip_portable_pack)
return
system2('cargo build --release --features ' + features)
system2('mv target/release/rustdesk.exe target/release/RustDesk.exe')
pa = os.environ.get('P')
if pa:
system2(f'signtool sign /a /v /p {pa} /debug /f .\\cert.pfx /t http://timestamp.digicert.com target\\release\\rustdesk.exe')
else:
print('Not signed')
system2(f'cp -rf target/release/RustDesk.exe {res_dir}')
else:
print("This platform is only supported for compilation in specific environments.")
if __name__ == "__main__":
main()