Update auto-generated TypeScript Bindings
[ldk-java] / genbindings.sh
index 6c7f6501210dd816317a58b0150488c48680b791..5576b8dba3f17c93d7bf958aa02417de3dcbd60e 100755 (executable)
@@ -180,7 +180,7 @@ if [ "$2" != "wasm" ]; then
 else
        echo "Creating TS bindings..."
        mkdir -p ts/{enums,structs}
-       rm -f ts/{enums,structs,}/*.{mjs,mts}
+       rm -f ts/{enums,structs,}/*.{mjs,mts,mts.part}
        if [ "$4" = "false" ]; then
                ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript node
        else
@@ -199,7 +199,7 @@ else
        cat ts/bindings.c.body >> ts/bindings.c
 
        echo "Building TS bindings..."
-       COMPILE="$COMMON_COMPILE -flto -Wl,--no-entry -Wl,--export-dynamic -Wl,-allow-undefined -nostdlib --target=wasm32-wasi"
+       COMPILE="$COMMON_COMPILE -flto -Wl,--no-entry -nostdlib --target=wasm32-wasi -Wl,-z -Wl,stack-size=$((8*1024*1024)) -Wl,--initial-memory=$((16*1024*1024)) -Wl,--max-memory=$((1024*1024*1024)) -Wl,--global-base=4096"
        # We only need malloc and assert/abort, but for now just use WASI for those:
        #EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a
        EXTRA_LINK=
@@ -214,18 +214,21 @@ else
 
        if [ -x "$(which tsc)" ]; then
                cd ts
-       rm -r structs # TODO: Make the human-types compile
+               for F in structs/*; do
+                       cat imports.mts.part | grep -v " $(basename -s .mts $F)[ ,]" | cat - $F > $F.tmp
+                       mv $F.tmp $F
+               done
+               rm imports.mts.part
                if [ "$4" = "true" ]; then
                        tsc
                else
                        tsc --types node --typeRoots .
-                       cd ..
                        if [ -x "$(which node)" ]; then
                                NODE_V="$(node --version)"
                                if [ "${NODE_V:1:2}" -gt 14 ]; then
                                        rm -f liblightningjs.wasm
-                                       ln -s $WASM_FILE liblightningjs.wasm
-                                       node ts/test/node.mjs
+                                       ln -s "$(pwd)"/../$WASM_FILE liblightningjs.wasm
+                                       node test/node.mjs
                                fi
                        fi
                fi