mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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.
This commit is contained in:
25
Buildscr
25
Buildscr
@ -131,19 +131,28 @@ endif
|
||||
# delegation.
|
||||
ifneq "$(NOJS)" yes then
|
||||
delegate emscripten
|
||||
in puzzles do emcmake cmake -B build-emscripten -DCMAKE_BUILD_TYPE=Release $(web_unfinished_option) .
|
||||
in puzzles do emcmake cmake -B build-emscripten $(web_unfinished_option) .
|
||||
in puzzles/build-emscripten do make -j$(nproc) VERBOSE=1
|
||||
return puzzles/build-emscripten/*.js
|
||||
return puzzles/build-emscripten/*.wasm
|
||||
return puzzles/build-emscripten/unfinished/group.js
|
||||
return puzzles/build-emscripten/unfinished/group.wasm
|
||||
enddelegate
|
||||
|
||||
# Build a set of wrapping HTML pages for easy testing of the
|
||||
# Javascript puzzles. These aren't quite the same as the versions that
|
||||
# will go on my live website, because those ones will substitute in a
|
||||
# different footer, and not have to link to the .js files with the
|
||||
# ../js/ prefix. But these ones should be good enough to just open
|
||||
# using a file:// URL in a browser after running a build, and make
|
||||
# sure the main functionality works.
|
||||
# Javascript puzzles.
|
||||
#
|
||||
# These aren't quite the same as the HTML pages that will go on my
|
||||
# live website. The live ones will substitute in a different footer
|
||||
# that links back to the main puzzles page, and they'll have a
|
||||
# different filesystem layout so that ther links to the .js files
|
||||
# won't need the ../js/ prefix used below.
|
||||
#
|
||||
# But these test pages should be good enough to just open after
|
||||
# running a build, to make sure the main functionality works.
|
||||
# Unfortunately, due to some kind of WASM loading restriction, this
|
||||
# can't be done using a file:// URL; you have to actually point an
|
||||
# HTTP or HTTPS server at the build output directory.
|
||||
in puzzles do mkdir jstest
|
||||
in puzzles/jstest do ../html/jspage.pl --jspath=../js/ /dev/null ../html/*.html
|
||||
endif
|
||||
@ -182,7 +191,9 @@ ifneq "$(NOJAVA)" yes then
|
||||
endif
|
||||
ifneq "$(NOJS)" yes then
|
||||
deliver puzzles/build-emscripten/*.js js/$@
|
||||
deliver puzzles/build-emscripten/*.wasm js/$@
|
||||
deliver puzzles/build-emscripten/unfinished/*.js js/$@
|
||||
deliver puzzles/build-emscripten/unfinished/*.wasm js/$@
|
||||
deliver puzzles/jstest/*.html jstest/$@
|
||||
deliver puzzles/html/*.html html/$@
|
||||
deliver puzzles/html/*.pl html/$@
|
||||
|
Reference in New Issue
Block a user