Skip to content

Commit ee88864

Browse files
committed
Run more of out tests with -sNO_DEFAULT_TO_CXX
We were previously only applying this flag to tests that use `self.build` (i.e. most test). Now we apply it to and even larger set. The code size changes here only occur in debug builds where we enumerate all known JS symbols, and there are come JS symbols are the C++ only.
1 parent 946c850 commit ee88864

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

test/common.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ def setUp(self):
833833
self.js_engines = config.JS_ENGINES.copy()
834834
self.settings_mods = {}
835835
self.emcc_args = ['-Wclosure', '-Werror', '-Wno-limited-postlink-optimizations']
836+
# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
837+
# For historical reasons emcc compiles and links as C++ by default.
838+
# However we want to run our tests in a more strict manner. We can
839+
# remove this if the issue above is ever fixed.
840+
self.set_setting('NO_DEFAULT_TO_CXX')
836841
self.ldflags = []
837842
# Increate stack trace limit to maximise usefulness of test failure reports
838843
self.node_args = ['--stack-trace-limit=50']
@@ -954,9 +959,13 @@ def has_changed_setting(self, key):
954959
def clear_setting(self, key):
955960
self.settings_mods.pop(key, None)
956961

957-
def serialize_settings(self):
962+
def serialize_settings(self, ldflags=True):
958963
ret = []
964+
# Incomplete list of link-only settings
965+
link_only_settings = ['NO_DEFAULT_TO_CXX']
959966
for key, value in self.settings_mods.items():
967+
if not ldflags and key in link_only_settings:
968+
continue
960969
if value == 1:
961970
ret.append(f'-s{key}')
962971
elif type(value) is list:
@@ -994,7 +1003,7 @@ def get_emcc_args(self, main_file=False, ldflags=True):
9941003
def is_ldflag(f):
9951004
return any(f.startswith(s) for s in ['-sENVIRONMENT=', '--pre-js=', '--post-js='])
9961005

997-
args = self.serialize_settings() + self.emcc_args
1006+
args = self.serialize_settings(ldflags) + self.emcc_args
9981007
if ldflags:
9991008
args += self.ldflags
10001009
else:
@@ -1034,12 +1043,6 @@ def build(self, filename, libraries=None, includes=None, force_c=False, js_outfi
10341043
filename = test_file(filename)
10351044
suffix = '.js' if js_outfile else '.wasm'
10361045
compiler = [compiler_for(filename, force_c)]
1037-
if compiler[0] == EMCC:
1038-
# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
1039-
# For historical reasons emcc compiles and links as C++ by default.
1040-
# However we want to run our tests in a more strict manner. We can
1041-
# remove this if the issue above is ever fixed.
1042-
compiler.append('-sNO_DEFAULT_TO_CXX')
10431046

10441047
if force_c:
10451048
assert shared.suffix(filename) != '.c', 'force_c is not needed for source files ending in .c'
@@ -2106,7 +2109,7 @@ def reftest(self, expected, manually_trigger=False):
21062109
setupRefTest();
21072110
''' % (reporting, basename, int(manually_trigger)))
21082111

2109-
def compile_btest(self, args, reporting=Reporting.FULL):
2112+
def compile_btest(self, args, reporting=Reporting.FULL, compiler=EMCC):
21102113
# Inject support code for reporting results. This adds an include a header so testcases can
21112114
# use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
21122115
# contains the implementation of REPORT_RESULT (we can't just include that implementation in
@@ -2123,7 +2126,7 @@ def compile_btest(self, args, reporting=Reporting.FULL):
21232126
test_file('report_result.c')]
21242127
if EMTEST_BROWSER == 'node':
21252128
args.append('-DEMTEST_NODE')
2126-
self.run_process([EMCC] + self.get_emcc_args() + args)
2129+
self.run_process([compiler] + self.get_emcc_args() + args)
21272130

21282131
def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
21292132
"""Special case of btest that reports its result solely via exiting
@@ -2169,7 +2172,7 @@ def btest(self, filename, expected=None, reference=None,
21692172
args += [filename, '-o', outfile]
21702173
# print('all args:', args)
21712174
utils.delete_file(outfile)
2172-
self.compile_btest(args, reporting=reporting)
2175+
self.compile_btest(args, reporting=reporting, compiler=compiler_for(filename))
21732176
self.assertExists(outfile)
21742177
if post_build:
21752178
post_build()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8420
1+
8389
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23089
1+
23004
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7250
1+
7217
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19713
1+
19628

test/test_other.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,7 +3108,7 @@ def test_embind_tsgen_val(self):
31083108
self.assertExists('embind_tsgen_val.d.ts')
31093109

31103110
def test_embind_tsgen_bigint(self):
3111-
args = [EMCC, test_file('other/embind_tsgen_bigint.cpp'), '-lembind', '--embind-emit-tsd', 'embind_tsgen_bigint.d.ts']
3111+
args = [EMXX, test_file('other/embind_tsgen_bigint.cpp'), '-lembind', '--embind-emit-tsd', 'embind_tsgen_bigint.d.ts']
31123112
# Check that TypeScript generation fails when code contains bigints but their support is not enabled
31133113
stderr = self.expect_fail(args)
31143114
self.assertContained("Missing primitive type to TS type for 'int64_t", stderr)
@@ -3118,14 +3118,14 @@ def test_embind_tsgen_bigint(self):
31183118

31193119
def test_embind_tsgen_memory64(self):
31203120
# Check that when memory64 is enabled longs & unsigned longs are mapped to bigint in the generated TS bindings
3121-
self.run_process([EMCC, test_file('other/embind_tsgen_memory64.cpp'),
3121+
self.run_process([EMXX, test_file('other/embind_tsgen_memory64.cpp'),
31223122
'-lembind', '--embind-emit-tsd', 'embind_tsgen_memory64.d.ts', '-sMEMORY64', '-Wno-experimental'] +
31233123
self.get_emcc_args())
31243124
self.assertFileContents(test_file('other/embind_tsgen_memory64.d.ts'), read_file('embind_tsgen_memory64.d.ts'))
31253125

31263126
def test_embind_tsgen_exceptions(self):
31273127
# Check that when Wasm exceptions and assertions are enabled bindings still generate.
3128-
self.run_process([EMCC, test_file('other/embind_tsgen.cpp'),
3128+
self.run_process([EMXX, test_file('other/embind_tsgen.cpp'),
31293129
'-lembind', '--embind-emit-tsd', 'embind_tsgen.d.ts', '-fwasm-exceptions', '-sASSERTIONS'])
31303130
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), read_file('embind_tsgen.d.ts'))
31313131

0 commit comments

Comments
 (0)