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
This commit is contained in:
juj 2020-05-06 17:18:59 +03:00 коммит произвёл GitHub
Родитель cb197393ee
Коммит bcb5c4c4bd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 41 добавлений и 6 удалений

Просмотреть файл

@ -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)))))

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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
}

18
tests/single_file_static_initializer.cpp поставляемый Normal file
Просмотреть файл

@ -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 <assert.h>
#include <memory.h>
#include <emscripten.h>
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
}

17
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):