Make pointer integer type language-dependent, instead of intptr_t
[ldk-java] / genbindings.sh
index 25c8ffbe91c0b4774a4fb4051158ce33e703ecaa..0c2a8982a1fe43a5205388d1f23e6b41fea79bb5 100755 (executable)
@@ -6,6 +6,7 @@ usage() {
        echo "debug should either be true, false, or leaks"
        echo "debug of leaks turns on leak tracking on an optimized release bianry"
        echo "android_web should either be true or false and indicates if we build for android (Java) or web (WASM)"
        echo "debug should either be true, false, or leaks"
        echo "debug of leaks turns on leak tracking on an optimized release bianry"
        echo "android_web should either be true or false and indicates if we build for android (Java) or web (WASM)"
+       echo "Note that web currently generates the same results as !web (ie Node.JS)"
        exit 1
 }
 [ "$1" = "" ] && usage
        exit 1
 }
 [ "$1" = "" ] && usage
@@ -35,6 +36,14 @@ else
        sed -i "s/TransactionOutputs/C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ/g" ./lightning.h
 fi
 
        sed -i "s/TransactionOutputs/C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ/g" ./lightning.h
 fi
 
+if [ "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" = "" ]; then
+       export LDK_GARBAGECOLLECTED_GIT_OVERRIDE=$(git describe --tag --dirty)
+fi
+if [ "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:0:1}" != "v" ]; then
+       echo "Version tag should start with a v" > /dev/stderr
+       exit 1
+fi
+
 if [ "$2" != "wasm" ]; then
        TARGET_STRING="$LDK_TARGET"
        if [ "$TARGET_STRING" = "" ]; then
 if [ "$2" != "wasm" ]; then
        TARGET_STRING="$LDK_TARGET"
        if [ "$TARGET_STRING" = "" ]; then
@@ -61,14 +70,6 @@ if [ "$2" != "wasm" ]; then
                LDK_TARGET_CPU="sandybridge"
        fi
 
                LDK_TARGET_CPU="sandybridge"
        fi
 
-       if [ "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" = "" ]; then
-               export LDK_GARBAGECOLLECTED_GIT_OVERRIDE=$(git describe --tag --dirty)
-       fi
-       if [ "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:0:1}" != "v" ]; then
-               echo "Version tag should start with a v" > /dev/stderr
-               exit 1
-       fi
-
        if [ "$(rustc --version --verbose | grep "host:")" = "host: x86_64-apple-darwin" ]; then
                # OSX sed is for some reason not compatible with GNU sed
                sed -i '' "s/^    <version>.*<\/version>/    <version>${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}<\/version>/g" pom.xml
        if [ "$(rustc --version --verbose | grep "host:")" = "host: x86_64-apple-darwin" ]; then
                # OSX sed is for some reason not compatible with GNU sed
                sed -i '' "s/^    <version>.*<\/version>/    <version>${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}<\/version>/g" pom.xml
@@ -203,13 +204,13 @@ else
        # 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=
        # 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=
-       [ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free"
+       [ "$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
        if [ "$3" = "true" ]; then
                WASM_FILE=liblightningjs_debug.wasm
-               $COMPILE -o liblightningjs_debug.wasm -g -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/debug/libldk.a $EXTRA_LINK
+               $COMPILE -o liblightningjs_debug.wasm -g -O1 -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/debug/libldk.a $EXTRA_LINK
        else
                WASM_FILE=liblightningjs_release.wasm
        else
                WASM_FILE=liblightningjs_release.wasm
-               $COMPILE -o liblightningjs_release.wasm -s -Os -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/release/libldk.a $EXTRA_LINK
+               $COMPILE -o liblightningjs_release.wasm -s -Oz -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/release/libldk.a $EXTRA_LINK
        fi
 
        if [ -x "$(which tsc)" ]; then
        fi
 
        if [ -x "$(which tsc)" ]; then
@@ -219,18 +220,14 @@ else
                        mv $F.tmp $F
                done
                rm imports.mts.part
                        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
-                               fi
+               tsc --types node --typeRoots .
+               cp ../$WASM_FILE liblightningjs.wasm
+               cp ../README.md README.md
+               echo Ready to publish!
+               if [ -x "$(which node)" ]; then
+                       NODE_V="$(node --version)"
+                       if [ "${NODE_V:1:2}" -gt 14 ]; then
+                               node test/node.mjs
                        fi
                fi
        fi
                        fi
                fi
        fi