Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1856,14 +1856,21 @@ addToLibrary({
},

#if DYNCALLS || !WASM_BIGINT
#if MINIMAL_RUNTIME
$dynCalls: '[]',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was {} before, and it does seem to be used more like a map than an array - why was this changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops you are right... it should be {}

#endif
$dynCallLegacy__deps: [
#if MAIN_MODULE == 1
$dynCallLegacy__deps: ['$createDyncallWrapper'],
'$createDyncallWrapper'
#endif
#if MINIMAL_RUNTIME
'$dynCalls',
#endif
],
$dynCallLegacy: (sig, ptr, args) => {
sig = sig.replace(/p/g, {{{ MEMORY64 ? "'j'" : "'i'" }}})
#if ASSERTIONS
#if MINIMAL_RUNTIME
assert(typeof dynCalls != 'undefined', 'Global dynCalls dictionary was not generated in the build! Pass -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$dynCall linker flag to include it!');
assert(sig in dynCalls, `bad function pointer type - sig is not in dynCalls: '${sig}'`);
#else
assert(('dynCall_' + sig) in Module, `bad function pointer type - dynCall function not found for sig '${sig}'`);
Expand Down
10 changes: 10 additions & 0 deletions test/code_size/embind_hello_wasm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 10171,
"a.js.gz": 4395,
"a.wasm": 7820,
"a.wasm.gz": 3526,
"total": 18543,
"total_gz": 8301
}
17 changes: 17 additions & 0 deletions test/code_size/embind_hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <string>
#include <emscripten/emscripten.h>
#include <emscripten/bind.h>

using namespace emscripten;

int main() {
EM_ASM(out(Module.getString()));
}

std::string getString() {
return "Hello, world";
}

EMSCRIPTEN_BINDINGS(typeOf) {
function("getString", &getString);
}
3 changes: 3 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -10904,6 +10904,7 @@ def test_function_exports_are_small(self, args, opt, closure):
'math': ('math', False),
'hello_wasm_worker': ('hello_wasm_worker', False, True),
'hello_embind_val': ('embind_val', False),
'hello_embind': ('embind_hello', False),
})
@crossplatform
def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False):
Expand Down Expand Up @@ -10945,6 +10946,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False)
'-sMODULARIZE']
hello_webgl2_sources = hello_webgl_sources + ['-sMAX_WEBGL_VERSION=2']
hello_wasm_worker_sources = [test_file('wasm_worker/wasm_worker_code_size.c'), '-sWASM_WORKERS', '-sENVIRONMENT=web,worker']
embind_hello_sources = [test_file('code_size/embind_hello_world.cpp'), '-lembind']
embind_val_sources = [test_file('code_size/embind_val_hello_world.cpp'),
'-lembind',
'-fno-rtti',
Expand All @@ -10959,6 +10961,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False)
'hello_webgl2': hello_webgl2_sources,
'hello_wasm_worker': hello_wasm_worker_sources,
'embind_val': embind_val_sources,
'embind_hello': embind_hello_sources,
}[test_name]

def print_percent(actual, expected):
Expand Down
4 changes: 0 additions & 4 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ def compute_minimal_runtime_initializer_and_exports(post, exports, receiving):

exports = [asmjs_mangle(x) for x in exports if x != building.WASM_CALL_CTORS]

# Decide whether we should generate the global dynCalls dictionary for the dynCall() function?
if settings.DYNCALLS and '$dynCall' in settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE and len([x for x in exports if x.startswith('dynCall_')]) > 0:
exports += ['dynCalls = {}']

declares = 'var ' + ',\n '.join(exports) + ';'
post = shared.do_replace(post, '<<< WASM_MODULE_EXPORTS_DECLARES >>>', declares)

Expand Down