forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embuilder.py
executable file
·286 lines (244 loc) · 8.08 KB
/
embuilder.py
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
#!/usr/bin/env python3
# Copyright 2014 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.
"""Tool to manage building of system libraries and ports.
In general emcc will build them automatically on demand, so you do not
strictly need to use this tool, but it gives you more control over the
process (in particular, if emcc does this automatically, and you are
running multiple build commands in parallel, confusion can occur).
"""
import argparse
import logging
import sys
import time
from contextlib import contextmanager
from tools import cache
from tools import shared
from tools import system_libs
from tools import ports
from tools.settings import settings
from tools.system_libs import USE_NINJA
# Minimal subset of targets used by CI systems to build enough to useful
MINIMAL_TASKS = [
'libbulkmemory',
'libcompiler_rt',
'libcompiler_rt-wasm-sjlj',
'libc',
'libc-debug',
'libc_optz',
'libc_optz-debug',
'libc++abi',
'libc++abi-except',
'libc++abi-noexcept',
'libc++abi-debug',
'libc++abi-debug-except',
'libc++abi-debug-noexcept',
'libc++',
'libc++-except',
'libc++-noexcept',
'libal',
'libdlmalloc',
'libdlmalloc-noerrno',
'libdlmalloc-tracing',
'libdlmalloc-debug',
'libembind',
'libembind-rtti',
'libemmalloc',
'libemmalloc-debug',
'libemmalloc-memvalidate',
'libemmalloc-verbose',
'libemmalloc-memvalidate-verbose',
'libGL',
'libhtml5',
'libsockets',
'libstubs',
'libstubs-debug',
'libstandalonewasm',
'crt1',
'crt1_proxy_main',
'libunwind-except',
'libnoexit',
'sqlite3',
'sqlite3-mt',
]
# Additional tasks on top of MINIMAL_TASKS that are necessary for PIC testing on
# CI (which has slightly more tests than other modes that want to use MINIMAL)
MINIMAL_PIC_TASKS = MINIMAL_TASKS + [
'libcompiler_rt-mt',
'libc-mt',
'libc-mt-debug',
'libc_optz-mt',
'libc_optz-mt-debug',
'libc++abi-mt',
'libc++abi-mt-noexcept',
'libc++abi-debug-mt',
'libc++abi-debug-mt-noexcept',
'libc++-mt',
'libc++-mt-noexcept',
'libdlmalloc-mt',
'libGL-emu',
'libGL-emu-webgl2',
'libGL-mt',
'libGL-mt-emu',
'libGL-mt-emu-webgl2',
'libGL-mt-emu-webgl2-ofb',
'libsockets_proxy',
'libsockets-mt',
'crtbegin',
'libsanitizer_common_rt',
'libubsan_rt',
'libwasm_workers_stub-debug',
'libwebgpu_cpp',
'libfetch',
'libfetch-mt',
'libwasmfs',
'giflib',
]
PORTS = sorted(list(ports.ports_by_name.keys()) + list(ports.port_variants.keys()))
temp_files = shared.get_temp_files()
logger = logging.getLogger('embuilder')
legacy_prefixes = {
'libgl': 'libGL',
}
def get_help():
all_tasks = get_system_tasks()[1] + PORTS
all_tasks.sort()
return '''
Available targets:
build / clear %s
Issuing 'embuilder build ALL' causes each task to be built.
''' % '\n '.join(all_tasks)
@contextmanager
def get_port_variant(name):
if name in ports.port_variants:
name, extra_settings = ports.port_variants[name]
old_settings = settings.dict().copy()
for key, value in extra_settings.items():
setattr(settings, key, value)
else:
old_settings = None
yield name
if old_settings:
settings.dict().update(old_settings)
def clear_port(port_name):
with get_port_variant(port_name) as port_name:
ports.clear_port(port_name, settings)
def build_port(port_name):
with get_port_variant(port_name) as port_name:
ports.build_port(port_name, settings)
def get_system_tasks():
system_libraries = system_libs.Library.get_all_variations()
system_tasks = list(system_libraries.keys())
return system_libraries, system_tasks
def main():
all_build_start_time = time.time()
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=get_help())
parser.add_argument('--lto', action='store_const', const='full', help='build bitcode object for LTO')
parser.add_argument('--lto=thin', dest='lto', action='store_const', const='thin', help='build bitcode object for ThinLTO')
parser.add_argument('--pic', action='store_true',
help='build relocatable objects for suitable for dynamic linking')
parser.add_argument('--force', action='store_true',
help='force rebuild of target (by removing it first)')
parser.add_argument('--verbose', action='store_true',
help='show build commands')
parser.add_argument('--wasm64', action='store_true',
help='use wasm64 architecture')
parser.add_argument('operation', choices=['build', 'clear', 'rebuild'])
parser.add_argument('targets', nargs='*', help='see below')
args = parser.parse_args()
if args.operation != 'rebuild' and len(args.targets) == 0:
shared.exit_with_error('no build targets specified')
if args.operation == 'rebuild' and not USE_NINJA:
shared.exit_with_error('"rebuild" operation is only valid when using Ninja')
# process flags
# Check sanity so that if settings file has changed, the cache is cleared here.
# Otherwise, the cache will clear in an emcc process, which is invoked while building
# a system library into the cache, causing trouble.
shared.check_sanity()
if args.lto:
settings.LTO = args.lto
if args.verbose:
shared.PRINT_STAGES = True
if args.pic:
settings.RELOCATABLE = 1
if args.wasm64:
settings.MEMORY64 = 2
MINIMAL_TASKS[:] = [t for t in MINIMAL_TASKS if 'emmalloc' not in t]
do_build = args.operation == 'build'
do_clear = args.operation == 'clear'
if args.force:
do_clear = True
# process tasks
auto_tasks = False
tasks = args.targets
system_libraries, system_tasks = get_system_tasks()
if 'SYSTEM' in tasks:
tasks = system_tasks
auto_tasks = True
elif 'USER' in tasks:
tasks = PORTS
auto_tasks = True
elif 'MINIMAL' in tasks:
tasks = MINIMAL_TASKS
auto_tasks = True
elif 'MINIMAL_PIC' in tasks:
tasks = MINIMAL_PIC_TASKS
auto_tasks = True
elif 'ALL' in tasks:
tasks = system_tasks + PORTS
auto_tasks = True
if auto_tasks:
# There are some ports that we don't want to build as part
# of ALL since the are not well tested or widely used:
skip_tasks = ['cocos2d']
tasks = [x for x in tasks if x not in skip_tasks]
print('Building targets: %s' % ' '.join(tasks))
for what in tasks:
for old, new in legacy_prefixes.items():
if what.startswith(old):
what = what.replace(old, new)
if do_build:
logger.info('building ' + what)
else:
logger.info('clearing ' + what)
start_time = time.time()
if what in system_libraries:
library = system_libraries[what]
if do_clear:
library.erase()
if do_build:
if USE_NINJA:
library.generate()
else:
library.build(deterministic_paths=True)
elif what == 'sysroot':
if do_clear:
cache.erase_file('sysroot_install.stamp')
if do_build:
system_libs.ensure_sysroot()
elif what in PORTS:
if do_clear:
clear_port(what)
if do_build:
build_port(what)
else:
logger.error('unfamiliar build target: ' + what)
return 1
time_taken = time.time() - start_time
logger.info('...success. Took %s(%.2fs)' % (('%02d:%02d mins ' % (time_taken // 60, time_taken % 60) if time_taken >= 60 else ''), time_taken))
if USE_NINJA and not do_clear:
system_libs.build_deferred()
if len(tasks) > 1 or USE_NINJA:
all_build_time_taken = time.time() - all_build_start_time
logger.info('Built %d targets in %s(%.2fs)' % (len(tasks), ('%02d:%02d mins ' % (all_build_time_taken // 60, all_build_time_taken % 60) if all_build_time_taken >= 60 else ''), all_build_time_taken))
return 0
if __name__ == '__main__':
try:
sys.exit(main())
except KeyboardInterrupt:
logger.warning("KeyboardInterrupt")
sys.exit(1)