cmake,emscripten: explicitly set stack size

The default was changed from 5MB to 64KB in 3.1.27 [1] causing image
decodes to fail. This restores the old default. In testing, 1536KB was
enough for the sample image, 1024KB was not.

[1]: https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#3127---112922

Bug: webp:614
Change-Id: I1ff7afc72fa49d88d2efe88d2a04dfadbea3b1a5
Fixed: webp:614
Test: emcc 3.1.18 & 3.1.41
This commit is contained in:
James Zern 2023-06-12 17:32:45 -07:00
parent 59a2b1f9e3
commit ebb6f949f4

View File

@ -651,6 +651,16 @@ if(WEBP_BUILD_EXTRAS)
endif() endif()
if(WEBP_BUILD_WEBP_JS) if(WEBP_BUILD_WEBP_JS)
# The default stack size changed from 5MB to 64KB in 3.1.27. See
# https://crbug.com/webp/614.
if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "3.1.27")
# TOTAL_STACK size was renamed to STACK_SIZE in 3.1.27. The old name was
# kept for compatibility, but prefer the new one in case it is removed in
# the future.
set(emscripten_stack_size "-sSTACK_SIZE=5MB")
else()
set(emscripten_stack_size "-sTOTAL_STACK=5MB")
endif()
# wasm2js does not support SIMD. # wasm2js does not support SIMD.
if(NOT WEBP_ENABLE_SIMD) if(NOT WEBP_ENABLE_SIMD)
# JavaScript version # JavaScript version
@ -660,7 +670,7 @@ if(WEBP_BUILD_WEBP_JS)
set(WEBP_HAVE_SDL 1) set(WEBP_HAVE_SDL 1)
set_target_properties( set_target_properties(
webp_js webp_js
PROPERTIES LINK_FLAGS "-sWASM=0 \ PROPERTIES LINK_FLAGS "-sWASM=0 ${emscripten_stack_size} \
-sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \ -sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \
-sEXPORTED_RUNTIME_METHODS=cwrap") -sEXPORTED_RUNTIME_METHODS=cwrap")
set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp) set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp)
@ -673,7 +683,7 @@ if(WEBP_BUILD_WEBP_JS)
target_include_directories(webp_wasm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(webp_wasm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties( set_target_properties(
webp_wasm webp_wasm
PROPERTIES LINK_FLAGS "-sWASM=1 \ PROPERTIES LINK_FLAGS "-sWASM=1 ${emscripten_stack_size} \
-sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \ -sEXPORTED_FUNCTIONS=_WebPToSDL -sINVOKE_RUN=0 \
-sEXPORTED_RUNTIME_METHODS=cwrap") -sEXPORTED_RUNTIME_METHODS=cwrap")
target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL) target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)