Skip to content

Commit 4c72c04

Browse files
committed
Avoid generating libc struct info with em++
Since internal musl code refuses to be compiled with em++.
1 parent 7474977 commit 4c72c04

3 files changed

Lines changed: 44 additions & 31 deletions

File tree

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,5 @@
4545
"global_locale"
4646
]
4747
}
48-
},
49-
{
50-
"file": "cxa_exception.h",
51-
"structs": {
52-
"__cxxabiv1::__cxa_exception": [
53-
"exceptionDestructor",
54-
"referenceCount",
55-
"exceptionType",
56-
"caught",
57-
"rethrown"
58-
]
59-
}
6048
}
6149
]

src/struct_info_libcxx.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
// ===========================================
3+
// libcxx - internal
4+
// ===========================================
5+
{
6+
"file": "cxa_exception.h",
7+
"structs": {
8+
"__cxxabiv1::__cxa_exception": [
9+
"exceptionDestructor",
10+
"referenceCount",
11+
"exceptionType",
12+
"caught",
13+
"rethrown"
14+
]
15+
}
16+
}
17+
]

tools/gen_struct_info.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def gen_inspect_code(path, struct, code):
196196
c_ascent(code)
197197

198198

199-
def inspect_headers(headers, cflags):
199+
def inspect_headers(headers, cflags, cxx=False):
200200
code = ['#include <stdio.h>', '#include <stddef.h>']
201201
for header in headers:
202202
code.append('#include "' + header['name'] + '"')
@@ -254,18 +254,18 @@ def inspect_headers(headers, cflags):
254254
show('Compiling generated code...')
255255

256256
# -Oz optimizes enough to avoid warnings on code size/num locals
257-
cmd = [shared.EMXX] + cflags + ['-o', js_file[1], src_file[1],
258-
'-O0',
259-
'-Werror',
260-
'-Wno-format',
261-
'-nostdlib',
262-
compiler_rt,
263-
'-s', 'BOOTSTRAPPING_STRUCT_INFO=1',
264-
'-s', 'LLD_REPORT_UNDEFINED=1',
265-
'-s', 'STRICT',
266-
# Use SINGLE_FILE=1 so there is only a single
267-
# file to cleanup.
268-
'-s', 'SINGLE_FILE']
257+
cmd = [shared.EMXX if cxx else shared.EMCC] + cflags + ['-o', js_file[1], src_file[1],
258+
'-O0',
259+
'-Werror',
260+
'-Wno-format',
261+
'-nostdlib',
262+
compiler_rt,
263+
'-s', 'BOOTSTRAPPING_STRUCT_INFO=1',
264+
'-s', 'LLD_REPORT_UNDEFINED=1',
265+
'-s', 'STRICT',
266+
# Use SINGLE_FILE=1 so there is only a single
267+
# file to cleanup.
268+
'-s', 'SINGLE_FILE']
269269

270270
# Default behavior for emcc is to warn for binaryen version check mismatches
271271
# so we should try to match that behavior.
@@ -311,13 +311,13 @@ def merge_info(target, src):
311311
target['structs'][key] = value
312312

313313

314-
def inspect_code(headers, cflags):
314+
def inspect_code(headers, cflags, cxx=False):
315315
if not DEBUG:
316-
info = inspect_headers(headers, cflags)
316+
info = inspect_headers(headers, cflags, cxx)
317317
else:
318318
info = {'defines': {}, 'structs': {}}
319319
for header in headers:
320-
merge_info(info, inspect_headers([header], cflags))
320+
merge_info(info, inspect_headers([header], cflags, cxx))
321321
return info
322322

323323

@@ -375,7 +375,8 @@ def main(args):
375375

376376
default_json_files = [
377377
shared.path_from_root('src', 'struct_info.json'),
378-
shared.path_from_root('src', 'struct_info_internal.json')
378+
shared.path_from_root('src', 'struct_info_libc.json'),
379+
shared.path_from_root('src', 'struct_info_libcxx.json')
379380
]
380381
parser = argparse.ArgumentParser(description='Generate JSON infos for structs.')
381382
parser.add_argument('json', nargs='*',
@@ -411,6 +412,9 @@ def main(args):
411412
internal_cflags = [
412413
'-I' + shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal'),
413414
'-I' + shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'include'),
415+
]
416+
417+
internal_cxxflags = [
414418
'-I' + shared.path_from_root('system', 'lib', 'libcxxabi', 'src'),
415419
'-D__USING_EMSCRIPTEN_EXCEPTIONS__',
416420
]
@@ -421,12 +425,16 @@ def main(args):
421425
for f in args.json:
422426
# This is a JSON file, parse it.
423427
header_files = parse_json(f)
428+
cxx = False
424429
# Inspect all collected structs.
425-
if 'internal' in f:
430+
if 'libcxx' in f:
431+
use_cflags = cflags + internal_cxxflags
432+
cxx = True
433+
elif 'libc' in f:
426434
use_cflags = cflags + internal_cflags
427435
else:
428436
use_cflags = cflags
429-
info_fragment = inspect_code(header_files, use_cflags)
437+
info_fragment = inspect_code(header_files, use_cflags, cxx)
430438
merge_info(info, info_fragment)
431439

432440
output_json(info, args.output)

0 commit comments

Comments
 (0)