Skip to content

Commit 20545e5

Browse files
committed
Update and document Emscripten link-time options
Set INITIAL_HEAP=1MB and ALLOW_MEMORY_GROWTH=1 to reduce starting memory usage of plugins, but allow the heap to grow. Explicitly set STACK_SIZE (previously named TOTAL_STACK) to 1MiB. This is a middle ground between Emscripten's default value prior to 3.1.27 of 5MiB and its default value since then of 64KiB. Also add comments documenting the purpose of each link-time option. Signed-off-by: Michael Warres <[email protected]>
1 parent 6b3dc93 commit 20545e5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

bazel/defs.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,25 @@ def proxy_wasm_cc_binary(
8989
"@proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js",
9090
],
9191
linkopts = linkopts + [
92+
# Setting to indicate module is a "reactor library" without a main() entry point:
93+
# https://emscripten.org/docs/tools_reference/settings_reference.html#standalone-wasm
9294
"--no-entry",
95+
# File listing additional functions that Emscripten should expect to be implemented by the host:
96+
# https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#implement-c-in-javascript
9397
"--js-library=$(location @proxy_wasm_cpp_sdk//:proxy_wasm_intrinsics_js)",
98+
# Emit Wasm module that can run without JavaScript
9499
"-sSTANDALONE_WASM",
100+
# Give host code access to Emscripten's _malloc() function
95101
"-sEXPORTED_FUNCTIONS=_malloc",
102+
# Allow allocating memory past initial heap size
103+
"-sALLOW_MEMORY_GROWTH=1",
104+
# Total stack size (fixed). Emscripten default stack size changed from 5MiB to 64KiB in
105+
# 3.1.27: https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md,
106+
# https://github.com/emscripten-core/emscripten/pull/18191. We pick 1MiB somewhat
107+
# arbitrarily, since it is gives a little more room and is easy to remember.
108+
"-sSTACK_SIZE=1MB",
109+
# Initial amount of heap memory
110+
"-sINITIAL_HEAP=1MB",
96111
],
97112
tags = tags + [
98113
"manual",

0 commit comments

Comments
 (0)