TooTallNate / switch-tools

Web app to create "NSP forwarders" for your modded Nintendo Switch
https://nsp-forwarder.n8.io
47 stars 9 forks source link

How did you compile hacbrewpack to wasm? #12

Closed acheronfail closed 5 months ago

acheronfail commented 5 months ago

Hey @TooTallNate, any chance you can share how you compiled hacbrewpack to wasm? I'm trying to compile it myself for wasm, but struggling to find the right combination of options that will get it to run properly...

Currently I have this:

# in addition to the default config.mk.template:
CC = emcc
CFLAGS += -flto -Os
LDFLAGS += -s ENVIRONMENT='web,webview,worker,node'
LDFLAGS += -s MODULARIZE=1 -s "EXPORT_NAME='hacbrewpack'"
LDFLAGS += -s EXPORTED_RUNTIME_METHODS='callMain'
LDFLAGS += -s EXPORT_ES6=1

However, when I run it from JS I get these errors:

warn: renderer.ts:46 Stack overflow detected.  You can try increasing -sSTACK_SIZE (currently set to 65536)

error: hacbrewpack.wasm:0x10d9 Uncaught (in promise) RuntimeError: memory access out of bounds
    at hacbrewpack.wasm:0x10d9
    at hacbrewpack.wasm:0x973d
    at hacbrewpack.js:653:12
    at Object.callMain (hacbrewpack.js:4910:15)
    at renderer.ts:48:36
here's my JS ```js import loadHacBrewPack from './public/hacbrewpack'; loadHacBrewPack({ print(v) { console.log(v); }, printErr(v) { console.warn(v); }, }).then((wasm) => console.log(wasm.callMain(["wasm", "--help"]))); ```
acheronfail commented 5 months ago

Nevermind, I managed to fix it by adding -s TOTAL_STACK=… to the config.mk!