X Tutup
Skip to content

add WASM/Emscripten build support via shim window port#1489

Open
apowers313 wants to merge 2 commits intoNetHack:NetHack-3.6from
apowers313:wasm-3.6.7
Open

add WASM/Emscripten build support via shim window port#1489
apowers313 wants to merge 2 commits intoNetHack:NetHack-3.6from
apowers313:wasm-3.6.7

Conversation

@apowers313
Copy link
Contributor

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

@nhmall nhmall added the 3.6 label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup