Merge branch 'wasm-bug-fixes' of https://github.com/apowers313/NetHack into wasm-pr403

This commit is contained in:
nhmall
2020-10-31 09:22:55 -04:00
7 changed files with 40 additions and 26 deletions
+1 -1
View File
@@ -630,10 +630,10 @@ clearlocks()
#endif #endif
#ifndef NO_SIGNAL #ifndef NO_SIGNAL
(void) signal(SIGINT, SIG_IGN); (void) signal(SIGINT, SIG_IGN);
#endif
#if defined(UNIX) || defined(VMS) #if defined(UNIX) || defined(VMS)
sethanguphandler((void FDECL((*), (int) )) SIG_IGN); sethanguphandler((void FDECL((*), (int) )) SIG_IGN);
#endif #endif
#endif /* NO_SIGNAL */
/* can't access maxledgerno() before dungeons are created -dlc */ /* can't access maxledgerno() before dungeons are created -dlc */
for (x = (g.n_dgns ? maxledgerno() : 0); x >= 0; x--) for (x = (g.n_dgns ? maxledgerno() : 0); x >= 0; x--)
delete_levelfile(x); /* not all levels need be present */ delete_levelfile(x); /* not all levels need be present */
+1 -1
View File
@@ -101,10 +101,10 @@ dosave0()
return 0; return 0;
fq_save = fqname(g.SAVEF, SAVEPREFIX, 1); /* level files take 0 */ fq_save = fqname(g.SAVEF, SAVEPREFIX, 1); /* level files take 0 */
#ifndef NO_SIGNAL
#if defined(UNIX) || defined(VMS) #if defined(UNIX) || defined(VMS)
sethanguphandler((void FDECL((*), (int) )) SIG_IGN); sethanguphandler((void FDECL((*), (int) )) SIG_IGN);
#endif #endif
#ifndef NO_SIGNAL
(void) signal(SIGINT, SIG_IGN); (void) signal(SIGINT, SIG_IGN);
#endif #endif
+4 -4
View File
@@ -555,11 +555,11 @@ whoami()
return FALSE; return FALSE;
} }
#ifndef NO_SIGNAL
void void
sethanguphandler(handler) sethanguphandler(handler)
void FDECL((*handler), (int)); void FDECL((*handler), (int));
{ {
#ifndef NO_SIGNAL
#ifdef SA_RESTART #ifdef SA_RESTART
/* don't want reads to restart. If SA_RESTART is defined, we know /* don't want reads to restart. If SA_RESTART is defined, we know
* sigaction exists and can be used to ensure reads won't restart. * sigaction exists and can be used to ensure reads won't restart.
@@ -581,8 +581,8 @@ void FDECL((*handler), (int));
(void) signal(SIGXCPU, (SIG_RET_TYPE) handler); (void) signal(SIGXCPU, (SIG_RET_TYPE) handler);
#endif #endif
#endif /* ?SA_RESTART */ #endif /* ?SA_RESTART */
#endif /* !NO_SIGNAL */
} }
#endif /* !NO_SIGNAL */
#ifdef PORT_HELP #ifdef PORT_HELP
void void
@@ -1003,7 +1003,8 @@ void js_constants_init() {
// copyright // copyright
SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_A); SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_A);
SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_B); SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_B);
SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_C); // XXX: not set for cross-compile
//SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_C);
SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_D); SET_CONSTANT_STRING("COPYRIGHT", COPYRIGHT_BANNER_D);
// glyphs // glyphs
@@ -1071,7 +1072,6 @@ void create_global (char *name, void *ptr, char *type);
void js_globals_init() { void js_globals_init() {
// int i; // int i;
// char buf[BUFSZ]; // char buf[BUFSZ];
printf("js_globals_init\n");
EM_ASM({ EM_ASM({
globalThis.nethackGlobal = globalThis.nethackGlobal || {}; globalThis.nethackGlobal = globalThis.nethackGlobal || {};
+2 -2
View File
@@ -4,9 +4,9 @@
"description": "The original NetHack rogue-like game built as a WebAssembly module", "description": "The original NetHack rogue-like game built as a WebAssembly module",
"main": "src/nethackShim.js", "main": "src/nethackShim.js",
"scripts": { "scripts": {
"test": "node test/test.js", "test": "npm run build && node test/test.js",
"clean": "rm ./build/nethack.js; rm ./build/nethack.wasm; true", "clean": "rm ./build/nethack.js; rm ./build/nethack.wasm; true",
"build": "cp ../../../src/nethack.js ../../../src/nethack.wasm ./build", "build": "mkdir build; cp ../../../targets/wasm/nethack.js ../../../targets/wasm/nethack.wasm ./build",
"prepack": "npm run build" "prepack": "npm run build"
}, },
"keywords": [ "keywords": [
+12 -8
View File
@@ -2,11 +2,13 @@
if [ x$1 == "xlib" ]; then if [ x$1 == "xlib" ]; then
echo Doing lib... echo Doing lib...
make spotless if [ -f Makefile ]; then
cd sys/lib make spotless
fi
cd sys/unix
./setup.sh hints/macOS.2020 ./setup.sh hints/macOS.2020
cd ../.. cd ../..
make make WANT_LIBNH=1
fi fi
if [ x$1 == "xrunlib" ]; then if [ x$1 == "xrunlib" ]; then
@@ -19,15 +21,17 @@ fi
if [ x$1 == "xwasm" ]; then if [ x$1 == "xwasm" ]; then
echo Doing wasm... echo Doing wasm...
make spotless if [ -f Makefile ]; then
cd sys/lib make spotless
./setup.sh hints/wasm fi
cd sys/unix
./setup.sh hints/macOS.2020
cd ../.. cd ../..
make make CROSS_TO_WASM=1
fi fi
if [ x$1 == "xrunwasm" ]; then if [ x$1 == "xrunwasm" ]; then
cd sys/lib/npm-package && node test/test.js cd sys/lib/npm-package && npm run build && node test/test.js
fi fi
if [ x$1 == "xbin" ]; then if [ x$1 == "xbin" ]; then
+17 -8
View File
@@ -29,6 +29,8 @@ endif
ifdef CROSS_TO_WASM ifdef CROSS_TO_WASM
CROSS=1 CROSS=1
BUILD_TARGET_LUA=1 BUILD_TARGET_LUA=1
HACKDIR=/
PREFIX=
override TARGET = wasm override TARGET = wasm
override TARGETDIR=../targets/$(TARGET) override TARGETDIR=../targets/$(TARGET)
override TARGETPFX = $(TARGETDIR)/ override TARGETPFX = $(TARGETDIR)/
@@ -298,36 +300,43 @@ ifdef CROSS_TO_WASM
# originally from https://github.com/NetHack/NetHack/pull/385 # originally from https://github.com/NetHack/NetHack/pull/385
#===============-================================================= #===============-=================================================
# #
WASM_DEBUG = 1
WASM_DATA_DIR = $(TARGETPFX)wasm-data WASM_DATA_DIR = $(TARGETPFX)wasm-data
WASM_TARGET = $(TARGETPFX)nethack.js WASM_TARGET = $(TARGETPFX)nethack.js
EMCC_LFLAGS = EMCC_LFLAGS =
#EMCC_LFLAGS += -s SINGLE_FILE=1 #EMCC_LFLAGS += -s SINGLE_FILE=1
EMCC_LFLAGS += -DHACKDIR=\"$(HACKDIR)\"
EMCC_LFLAGS += -s WASM=1 EMCC_LFLAGS += -s WASM=1
EMCC_LFLAGS += -s ALLOW_TABLE_GROWTH EMCC_LFLAGS += -s ALLOW_TABLE_GROWTH
EMCC_LFLAGS += -s ASYNCIFY -s ASYNCIFY_IMPORTS='["local_callback"]' EMCC_LFLAGS += -s ASYNCIFY -s ASYNCIFY_IMPORTS='["local_callback"]'
EMCC_LFLAGS += -O3 EMCC_LFLAGS += -O3
EMCC_LFLAGS += -s MODULARIZE EMCC_LFLAGS += -s MODULARIZE
EMCC_LFLAGS += -s EXPORTED_FUNCTIONS='["_main", "_shim_graphics_set_callback"]' EMCC_LFLAGS += -s EXPORTED_FUNCTIONS='["_main", "_shim_graphics_set_callback", "_mapglyph", "_display_inventory"]'
EMCC_LFLAGS += -s EXPORTED_RUNTIME_METHODS='["cwrap", "ccall", "addFunction", \ EMCC_LFLAGS += -s EXPORTED_RUNTIME_METHODS='["cwrap", "ccall", "addFunction", \
"removeFunction", "UTF8ToString", "getValue", "setValue"]' "removeFunction", "UTF8ToString", "getValue", "setValue"]'
EMCC_LFLAGS += -s ERROR_ON_UNDEFINED_SYMBOLS=0 EMCC_LFLAGS += -s ERROR_ON_UNDEFINED_SYMBOLS=0
EMCC_LFLAGS += --embed-file $(WASM_DATA_DIR) # XXX: the "@/" at the end of "--embed-file" tells emscripten to embed the files
# in the root directory, otherwise they will end up in the $(WASM_DATA_DIR) path
EMCC_LFLAGS += --embed-file $(WASM_DATA_DIR)@/
# For a list of EMCC settings: # For a list of EMCC settings:
# https://github.com/emscripten-core/emscripten/blob/master/src/settings.js # https://github.com/emscripten-core/emscripten/blob/master/src/settings.js
# #
# WASM C flags # WASM C flags
EMCC_CFLAGS= EMCC_CFLAGS =
EMCC_CFLAGS += -Wall EMCC_CFLAGS += -Wall
#EMCC_CFLAGS += -Werror EMCC_CFLAGS += -Werror
EMCC_CFLAGS += -DNO_SIGNAL
#EMCC_CFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 #EMCC_CFLAGS += -s DISABLE_EXCEPTION_CATCHING=0
EMCC_DEBUG_CFLAGS += -s ASSERTIONS=1 #EMCC_DEBUG_CFLAGS += -s ASSERTIONS=1
#EMCC_DEBUG_CFLAGS += -s ASSERTIONS=2 EMCC_DEBUG_CFLAGS += -s ASSERTIONS=2
EMCC_DEBUG_CFLAGS += -s STACK_OVERFLOW_CHECK=2 EMCC_DEBUG_CFLAGS += -s STACK_OVERFLOW_CHECK=2
EMCC_DEBUG_CFLAGS += -s SAFE_HEAP=1 EMCC_DEBUG_CFLAGS += -s SAFE_HEAP=1
EMCC_DEBUG_CFLAGS += -s LLD_REPORT_UNDEFINED=1 EMCC_DEBUG_CFLAGS += -s LLD_REPORT_UNDEFINED=1
#EMCC_DEBUG_CFLAGS += -s EXCEPTION_DEBUG=1 EMCC_DEBUG_CFLAGS += -s EXCEPTION_DEBUG=1
#EMCC_DEBUG_CFLAGS += -fsanitize=undefined -fsanitize=address -fsanitize=leak #EMCC_DEBUG_CFLAGS += -fsanitize=undefined -fsanitize=address -fsanitize=leak
#EMCC_DEBUG_CFLAGS += -s EXIT_RUNTIME EMCC_DEBUG_CFLAGS += -s EXIT_RUNTIME=1
# XXX: if --profiling isn't included then any error dumps 10MB of WASM to the screen rather than a useful message
EMCC_DEBUG_CFLAGS += --profiling
EMCC_PROD_CFLAGS += -O3 EMCC_PROD_CFLAGS += -O3
ifdef WASM_DEBUG ifdef WASM_DEBUG
EMCC_CFLAGS += $(EMCC_DEBUG_CFLAGS) EMCC_CFLAGS += $(EMCC_DEBUG_CFLAGS)
+1
View File
@@ -294,6 +294,7 @@ VARDIR=$(HACKDIR)
#-INCLUDE cross-pre.2020 #-INCLUDE cross-pre.2020
# #
#-POST #-POST
ifdef WANT_LIBNH ifdef WANT_LIBNH
libnh.a: $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a libnh.a: $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a
$(AR) rcs $@ $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a $(AR) rcs $@ $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a