]> git.bitcoin.ninja Git - ldk-java/commitdiff
[C#,Java] Fix building on OSX due to bug in latest ld64.lld/clang
authorMatt Corallo <git@bluematt.me>
Fri, 13 Jan 2023 20:22:06 +0000 (20:22 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 13 Jan 2023 20:40:01 +0000 (20:40 +0000)
genbindings.sh

index 2868d4c6b7518f7dd213f2071e2237453c6ed267..de0df2e8041d779ad886b86fc0c1184464ba7ccc 100755 (executable)
@@ -108,18 +108,21 @@ if [ "$2" = "c_sharp" ]; then
        mv ./-out:csharpldk.dll csharpldk.dll # Mono is braindead, apparently
 
        echo "Building C# bindings..."
-       COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -ldl -shared -fPIC"
+       COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC"
+       LINK="-ldl -shared"
        [ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--no-undefined"
        [ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
-       [ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && COMPILE="$COMPILE -fuse-ld=lld"
+       [ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
        [ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
        [ "$IS_MAC" = "false" -a "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
 
        exit 0 # Sadly compilation doesn't currently work
        if [ "$3" = "true" ]; then
-               $COMPILE -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
+               $COMPILE $LINK -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
        else
-               $COMPILE -o liblightningjni_release$LDK_TARGET_SUFFIX.so -s -flto -O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
+               $COMPILE -o bindings.o -c -flto -O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
+               $COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -O3 -Wl,--lto-O3 -Wl,-O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
+               llvm-strip liblightningjni_release$LDK_TARGET_SUFFIX.so
        fi
 elif [ "$2" = "wasm" ]; then
        echo "Creating TS bindings..."
@@ -244,14 +247,15 @@ else
        [ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true
 
        echo "Building Java bindings..."
-       COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -ldl -shared -fPIC"
+       COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC"
+       LINK="-ldl -shared"
        [ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--no-undefined"
        [ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
-       [ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && COMPILE="$COMPILE -fuse-ld=lld"
+       [ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
        [ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
        [ "$IS_MAC" = "false" -a "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
        if [ "$3" = "true" ]; then
-               $COMPILE -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
+               $COMPILE $LINK -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
        else
                LDK_LIB="$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a
                if [ "$IS_MAC" = "false" -a "$4" = "false" ]; then
@@ -296,7 +300,9 @@ else
                        popd
                        LDK_LIB="tmp/libldk.bc tmp/libldk.a"
                fi
-               $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
+               $COMPILE -o bindings.o -c -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c
+               $COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -Wl,--lto-O3 -Wl,-O3 -O3 -I"$1"/lightning-c-bindings/include/ $2 bindings.o $LDK_LIB -lm
+               llvm-strip liblightningjni_release$LDK_TARGET_SUFFIX.so
                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