aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2021-04-03 08:42:04 +0100
committerSimon Tatham <anakin@pobox.com>2021-04-03 09:22:49 +0100
commitf6434e84964d840160eeff518bc812392c13160f (patch)
tree56916c500b5f0ed07c97f6c093c039cab068e86c /cmake
parente1b9047b55199f3f5b8569029c5830104ddfae09 (diff)
downloadpuzzles-f6434e84964d840160eeff518bc812392c13160f.zip
puzzles-f6434e84964d840160eeff518bc812392c13160f.tar.gz
puzzles-f6434e84964d840160eeff518bc812392c13160f.tar.bz2
puzzles-f6434e84964d840160eeff518bc812392c13160f.tar.xz
Update web puzzles to current WASM-based Emscripten.
I presume this will improve performance. Also, if I've understood correctly, WASM-based compiled web code is capable of automatically growing its memory, which the previous asm.js build of the puzzles could not do, and occasionally caused people to complain that if they tried to play a _really big_ game in their browser, the JS would eventually freeze because the emulated memory ran out. I've been putting off doing this for ages because my previous Emscripten build setup was so finicky that I didn't like to meddle with it. But now that the new cmake system in this source tree makes things generally easier, and particularly since I've just found out that the up-to-date Emscripten is available as a Docker image (namely "emscripten/emsdk"), this seemed like a good moment to give it a try. The source and build changes required for this update weren't too onerous. I was half expecting a huge API upheaval, and indeed there was _some_ change, but very little: - in the JS initPuzzle function, move the call to Module.callMain() into Module.onRuntimeInitialized instead of doing it at the top level, because New Emscripten's .js output likes to load the accompanying .wasm file asynchronously, so you can't call the WASM main() until it actually exists. - in the JS-side library code, replace all uses of Emscripten's Pointer_stringify() function with the new name UTF8ToString(). (The new version also has an ASCIIToString(), so I guess the reason for the name change is that now you get to choose which character set you meant. I need to use UTF-8, so that the × and ÷ signs in Keen will work.) - set EXTRA_EXPORTED_RUNTIME_METHODS=[cwrap,callMain] on the emcc link command line, otherwise they aren't available for my JS setup code to call. - (removed -s ASM_JS=1 from the link options, though I'm not actually sure it made any difference one way or the other in the new WASM world) - be prepared for a set of .wasm files to show up as build products alongside the .js ones. - stop building with -DCMAKE_BUILD_TYPE=Release! I'm not sure why that was needed, but if I leave that flag on my cmake command line, the output .js file fails to embed my emccpre.js, so the initial call to initPuzzle() fails from the HTML wrapper page, meaning nothing at all happens.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/platforms/emscripten.cmake4
1 files changed, 3 insertions, 1 deletions
diff --git a/cmake/platforms/emscripten.cmake b/cmake/platforms/emscripten.cmake
index d923083..89223a5 100644
--- a/cmake/platforms/emscripten.cmake
+++ b/cmake/platforms/emscripten.cmake
@@ -29,7 +29,9 @@ set(emcc_export_list
list(TRANSFORM emcc_export_list PREPEND \")
list(TRANSFORM emcc_export_list APPEND \")
string(JOIN "," emcc_export_string ${emcc_export_list})
-set(CMAKE_C_LINK_FLAGS "-s ASM_JS=1 -s EXPORTED_FUNCTIONS='[${emcc_export_string}]'")
+set(CMAKE_C_LINK_FLAGS "\
+-s EXPORTED_FUNCTIONS='[${emcc_export_string}]' \
+-s EXTRA_EXPORTED_RUNTIME_METHODS='[cwrap,callMain]'")
set(build_cli_programs FALSE)