Merge pull request #107 from TheBlueMatt/main
[ldk-java] / genbindings.sh
index 253b8aad94abb4ba912df8f0ce3a0db85d37c685..8034337dc22b4ddd25194e063eec30e1f91d0fcf 100755 (executable)
@@ -144,7 +144,7 @@ if [ "$2" != "wasm" ]; then
                                echo "Archive contained non-object files!"
                                exit 1
                        fi
-                       if [ "$(ar t "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a | grep ldk.ldk.*-cgu.*.rcgu.o | wc -l)" != "1" ]; then
+                       if [ "$(ar t "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a | grep ldk.*-cgu.*.rcgu.o | wc -l)" != "1" ]; then
                                echo "Archive contained more than one LDK object file"
                                exit 1
                        fi
@@ -152,14 +152,14 @@ if [ "$2" != "wasm" ]; then
                        rm -f tmp/*
                        ar x --output=tmp "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a
                        pushd tmp
-                       llvm-dis ldk.ldk.*-cgu.*.rcgu.o
-                       sed -i 's/br i1 icmp eq (i8\* @__cxa_thread_atexit_impl, i8\* null)/br i1 icmp eq (i8* null, i8* null)/g' ldk.ldk.*-cgu.*.rcgu.o.ll
-                       llvm-as ldk.ldk.*-cgu.*.rcgu.o.ll -o ./libldk.bc
+                       llvm-dis ldk*-cgu.*.rcgu.o
+                       sed -i 's/br i1 icmp eq (i8\* @__cxa_thread_atexit_impl, i8\* null)/br i1 icmp eq (i8* null, i8* null)/g' ldk*-cgu.*.rcgu.o.ll
+                       llvm-as ldk*-cgu.*.rcgu.o.ll -o ./libldk.bc
                        ar q libldk.a *.o
                        popd
                        LDK_LIB="tmp/libldk.bc tmp/libldk.a"
                fi
-               $COMPILE -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c $LDK_LIB -lm
+               $COMPILE -o liblightningjni_release$LDK_TARGET_SUFFIX.so -s -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c $LDK_LIB -lm
                if [ "$IS_MAC" = "false" -a "$4" = "false" ]; then
                        GLIBC_SYMBS="$(objdump -T liblightningjni_release$LDK_TARGET_SUFFIX.so | grep GLIBC_ | grep -v "GLIBC_2\.2\." | grep -v "GLIBC_2\.3\(\.\| \)" | grep -v "GLIBC_2.\(14\|17\) " || echo)"
                        if [ "$GLIBC_SYMBS" != "" ]; then
@@ -189,6 +189,9 @@ else
                ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript browser
        fi
        rm -f ts/bindings.c
+       sed -i 's/^  "version": .*/  "version": "'${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}'",/g' ts/package.json
+       sed -i 's/^  "version": .*/  "version": "'${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}'",/g' node-net/package.json
+       sed -i 's/^    "lightningdevkit": .*/    "lightningdevkit": "'${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}'"/g' node-net/package.json
        if [ "$3" = "true" ]; then
                echo "#define LDK_DEBUG_BUILD" > ts/bindings.c
        elif [ "$3" = "leaks" ]; then
@@ -203,8 +206,7 @@ else
        echo "Building TS bindings..."
        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=
+       EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a
        [ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,aligned_alloc -Wl,-wrap,free"
        if [ "$3" = "true" ]; then
                WASM_FILE=liblightningjs_debug.wasm
@@ -224,11 +226,16 @@ else
                tsc --types node --typeRoots .
                cp ../$WASM_FILE liblightningjs.wasm
                cp ../README.md README.md
+               cd ../node-net
+               tsc --types node --typeRoots .
                echo Ready to publish!
                if [ -x "$(which node)" ]; then
                        NODE_V="$(node --version)"
                        if [ "${NODE_V:1:2}" -gt 14 ]; then
+                               cd ../ts
                                node test/node.mjs
+                               cd ../node-net
+                               node test/test.mjs
                        fi
                fi
        fi