From bcb5c4c4bdabc3ea8cc0a671e1580ff1e43fc4a6 Mon Sep 17 00:00:00 2001 From: juj Date: Wed, 6 May 2020 17:18:59 +0300 Subject: [PATCH] Fix SINGLE_FILE+MINIMAL_RUNTIME+WASM build in fastcomp (#10928) * Fix SINGLE_FILE+MINIMAL_RUNTIME+WASM build in fastcomp * Add test file * Fix test * Update minimal runtime code size expectations --- emcc.py | 2 +- src/runtime_functions.js | 2 ++ .../code_size/random_printf_fastcomp_wasm.json | 8 ++++---- tests/single_file_static_initializer.cpp | 18 ++++++++++++++++++ tests/test_browser.py | 17 ++++++++++++++++- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 tests/single_file_static_initializer.cpp diff --git a/emcc.py b/emcc.py index 4f8965f80..208112421 100755 --- a/emcc.py +++ b/emcc.py @@ -2552,7 +2552,7 @@ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR P else: return '' - if shared.Settings.MINIMAL_RUNTIME and (shared.Settings.MEM_INIT_METHOD == 0 or shared.Settings.SINGLE_FILE): + if shared.Settings.MINIMAL_RUNTIME and (shared.Settings.MEM_INIT_METHOD == 0 or (shared.Settings.SINGLE_FILE and not shared.Settings.WASM)): # In MINIMAL_RUNTIME emit the base64 memory initializer directly into a HEAPU8.set() statement. mem_init_data = re.search(shared.JS.memory_initializer_pattern, open(final).read()) src = open(final).read().replace('{{{ BASE64_MEMORY_INITIALIZER }}}', base64_encode(bytearray(parse_mem_bytes(mem_init_data.group(1))))) diff --git a/src/runtime_functions.js b/src/runtime_functions.js index 7525d30f6..e5dba00f8 100644 --- a/src/runtime_functions.js +++ b/src/runtime_functions.js @@ -163,7 +163,9 @@ function addFunctionWasm(func, sig) { if (!(err instanceof TypeError)) { throw err; } +#if ASSERTIONS assert(typeof sig !== 'undefined', 'Missing signature argument to addFunction'); +#endif var wrapped = convertJsFunctionToWasm(func, sig); table.set(ret, wrapped); } diff --git a/tests/code_size/random_printf_fastcomp_wasm.json b/tests/code_size/random_printf_fastcomp_wasm.json index 8a24ea646..7888546f7 100644 --- a/tests/code_size/random_printf_fastcomp_wasm.json +++ b/tests/code_size/random_printf_fastcomp_wasm.json @@ -1,6 +1,6 @@ { - "a.html": 13347, - "a.html.gz": 7076, - "total": 13347, - "total_gz": 7076 + "a.html": 14059, + "a.html.gz": 7504, + "total": 14059, + "total_gz": 7504 } diff --git a/tests/single_file_static_initializer.cpp b/tests/single_file_static_initializer.cpp new file mode 100644 index 000000000..0048b5e3e --- /dev/null +++ b/tests/single_file_static_initializer.cpp @@ -0,0 +1,18 @@ +// Copyright 2016 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. + +#include +#include +#include + +const char *str = "this is static data"; + +int main() { +#ifdef REPORT_RESULT + REPORT_RESULT(strlen(str + + // throw off optimization + (int)(emscripten_get_now() / 10000.0))); +#endif +} diff --git a/tests/test_browser.py b/tests/test_browser.py index b9e199039..b4b899e31 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -4679,10 +4679,25 @@ window.close = function() { # Tests that SINGLE_FILE works as intended in generated HTML (with and without Worker) def test_single_file_html(self): - self.btest('emscripten_main_loop_setimmediate.cpp', '1', args=['-s', 'SINGLE_FILE=1', '-s', 'WASM=1'], also_proxied=True) + self.btest('single_file_static_initializer.cpp', '19', args=['-s', 'SINGLE_FILE=1', '-s', 'WASM=1'], also_proxied=True) self.assertExists('test.html') self.assertNotExists('test.js') self.assertNotExists('test.worker.js') + self.assertNotExists('test.wasm') + self.assertNotExists('test.mem') + + # Tests that SINGLE_FILE works as intended in generated HTML with MINIMAL_RUNTIME + def test_minimal_runtime_single_file_html(self): + for wasm in [0, 1]: + for opts in [[], ['-O3']]: + self.btest('single_file_static_initializer.cpp', '19', args=opts + ['-s', 'MINIMAL_RUNTIME=1', '-s', 'SINGLE_FILE=1', '-s', 'WASM=' + str(wasm)]) + self.assertExists('test.html') + self.assertNotExists('test.js') + self.assertNotExists('test.wasm') + self.assertNotExists('test.asm.js') + self.assertNotExists('test.mem') + self.assertNotExists('test.js') + self.assertNotExists('test.worker.js') # Tests that SINGLE_FILE works when built with ENVIRONMENT=web and Closure enabled (#7933) def test_single_file_in_web_environment_with_closure(self):