Skip to content

Commit ee93f57

Browse files
authored
Split out C++ code in of gen_struct_info.py. NFC (#14704)
This was split out from #13006 since the newer musl internal headers don't parse in C++ mode.
1 parent 19e5242 commit ee93f57

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

src/struct_info_cxx.json

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

src/struct_info_internal.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,5 @@
4040
"global_locale"
4141
]
4242
}
43-
},
44-
{
45-
"file": "cxa_exception.h",
46-
"structs": {
47-
"__cxxabiv1::__cxa_exception": [
48-
"exceptionDestructor",
49-
"referenceCount",
50-
"exceptionType",
51-
"caught",
52-
"rethrown"
53-
]
54-
}
5543
}
5644
]

tools/gen_struct_info.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,24 @@ def inspect_headers(headers, cflags):
253253
# Compile the program.
254254
show('Compiling generated code...')
255255

256+
if any('libcxxabi' in f for f in cflags):
257+
compiler = shared.EMXX
258+
else:
259+
compiler = shared.EMCC
260+
256261
# -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']
262+
cmd = [compiler] + cflags + ['-o', js_file[1], src_file[1],
263+
'-O0',
264+
'-Werror',
265+
'-Wno-format',
266+
'-nostdlib',
267+
compiler_rt,
268+
'-s', 'BOOTSTRAPPING_STRUCT_INFO=1',
269+
'-s', 'LLD_REPORT_UNDEFINED=1',
270+
'-s', 'STRICT',
271+
# Use SINGLE_FILE=1 so there is only a single
272+
# file to cleanup.
273+
'-s', 'SINGLE_FILE']
269274

270275
# Default behavior for emcc is to warn for binaryen version check mismatches
271276
# so we should try to match that behavior.
@@ -375,7 +380,8 @@ def main(args):
375380

376381
default_json_files = [
377382
shared.path_from_root('src', 'struct_info.json'),
378-
shared.path_from_root('src', 'struct_info_internal.json')
383+
shared.path_from_root('src', 'struct_info_internal.json'),
384+
shared.path_from_root('src', 'struct_info_cxx.json'),
379385
]
380386
parser = argparse.ArgumentParser(description='Generate JSON infos for structs.')
381387
parser.add_argument('json', nargs='*',
@@ -410,6 +416,9 @@ def main(args):
410416

411417
internal_cflags = [
412418
'-I' + shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal'),
419+
]
420+
421+
cxxflags = [
413422
'-I' + shared.path_from_root('system', 'lib', 'libcxxabi', 'src'),
414423
'-D__USING_EMSCRIPTEN_EXCEPTIONS__',
415424
]
@@ -423,6 +432,8 @@ def main(args):
423432
# Inspect all collected structs.
424433
if 'internal' in f:
425434
use_cflags = cflags + internal_cflags
435+
elif 'cxx' in f:
436+
use_cflags = cflags + cxxflags
426437
else:
427438
use_cflags = cflags
428439
info_fragment = inspect_code(header_files, use_cflags)

0 commit comments

Comments
 (0)