add WASM/Emscripten build support via shim window port#1489
Open
apowers313 wants to merge 2 commits intoNetHack:NetHack-3.6from
Open
add WASM/Emscripten build support via shim window port#1489apowers313 wants to merge 2 commits intoNetHack:NetHack-3.6from
apowers313 wants to merge 2 commits intoNetHack:NetHack-3.6from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of the WASM/Emscripten cross-compilation support from 3.7
(#385, #1331, #1328) to the 3.6 branch so the current production
release can run in the browser or Node.js.
Same approach as 3.7: a shim window port (win/shim/winshim.c) bridges
the C engine to JavaScript via an async callback, and a library main
(sys/libnh/libnhmain.c) replaces unixmain.c. A hints file
(sys/unix/hints/linux-wasm) wires up the Emscripten flags.
The one wrinkle specific to 3.6 is a cross-compilation data mismatch.
On LP64 hosts (Linux/macOS x86_64) unsigned long is 8 bytes, but in
WASM it's 4. The binary data files (dungeon, levels, quest text) are
written by native utilities and read by the WASM game, so the struct
layouts have to agree. A CROSS_TO_WASM guard in include/global.h
typedefs the relevant types to int/unsigned int when building for WASM
and leaves them as long/unsigned long otherwise. This doesn't come up
in 3.7 because the data file format was reworked there.
Build instructions and API docs are in sys/libnh/README.md.
I've also published this as npm packages for anyone who wants to embed
NetHack in a JS project without setting up the C toolchain:
@neth4ck/wasm-367 -- https://www.npmjs.com/package/@neth4ck/wasm-367
@neth4ck/neth4ck -- https://www.npmjs.com/package/@neth4ck/neth4ck