Merge pull request #150 from TheBlueMatt/main
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 13 Mar 2024 14:57:01 +0000 (14:57 +0000)
committerGitHub <noreply@github.com>
Wed, 13 Mar 2024 14:57:01 +0000 (14:57 +0000)
Ensure bindings statics run before enums try to call native init

csharp_strings.py
genbindings.sh
java_strings.py

index e1c2708e82e32ebcce0ea8dabe509c012675397a..a73ee2035d310be2568fa48f71b94ab9994ea3e4 100644 (file)
@@ -576,12 +576,12 @@ int CS_LDK_register_{fn_suffix}_invoker(invoker_{fn_suffix} invoker) {{
         return "InternalUtils.getArrayLength(" + arr_name + ")"
 
     def get_java_arr_elem(self, elem_ty, arr_name, idx):
-        if elem_ty.c_ty == "int64_t" or elem_ty.c_ty == "uint64_t" or elem_ty.c_ty.endswith("Array") or elem_ty.c_ty == "uintptr_t":
+        if elem_ty.c_ty == "int64_t" or elem_ty.c_ty == "uint64_t":
+            return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
+        elif elem_ty.c_ty.endswith("Array") or elem_ty.c_ty == "uintptr_t" or elem_ty.rust_obj == "LDKStr":
             return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
         elif elem_ty.rust_obj == "LDKU5":
             return "InternalUtils.getU8ArrayElem(" + arr_name + ", " + idx + ")"
-        elif elem_ty.rust_obj == "LDKStr":
-            return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
         else:
             assert False
 
index 24aafa79367ab356cd9cf184bb45956bd6a1a1e6..3b66af440420d208c87464b6da9210e56bfda000 100755 (executable)
@@ -37,6 +37,9 @@ IS_WIN=false
 IS_APPLE_CLANG=false
 [ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true
 
+STRIP=llvm-strip
+[ "$IS_APPLE_CLANG" = "true" ] && STRIP=echo
+
 case "$TARGET_STRING" in
        "x86_64-pc-linux"*)
                LDK_TARGET_SUFFIX="_Linux-amd64"
@@ -66,6 +69,8 @@ case "$TARGET_STRING" in
                CS_PLATFORM_NAME="win-x64"
                LDK_JAR_TARGET=true
                IS_WIN=true
+               # llvm-strip currently corrupts DLLs - https://github.com/llvm/llvm-project/issues/63081
+               STRIP=echo
                ;;
        *)
                LDK_TARGET_SUFFIX="_${TARGET_STRING}"
@@ -171,7 +176,7 @@ if [ "$2" = "c_sharp" ]; then
                # so we have to build with faketime.
                faketime -f "2021-01-01 00:00:00" $COMPILE -o bindings.o -c -O3 -I"$1"/lightning-c-bindings/include/ c_sharp/bindings.c
                faketime -f "2021-01-01 00:00:00" $COMPILE $LINK -o libldkcsharp_release$LDK_TARGET_SUFFIX.so -O3 bindings.o $LDK_LIB -lm
-               [ "$IS_APPLE_CLANG" != "true" ] && llvm-strip -R .llvmbc -R .llvmcmd libldkcsharp_release$LDK_TARGET_SUFFIX.so
+               $STRIP -R .llvmbc -R .llvmcmd libldkcsharp_release$LDK_TARGET_SUFFIX.so
 
                if [ "$LDK_JAR_TARGET" = "true" ]; then
                        # Copy resulting native binary for inclusion in release nuget zip
@@ -225,7 +230,7 @@ elif [ "$2" = "python" ]; then
        else
                $COMPILE -o bindings.o -c -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
                $COMPILE $LINK -o liblightningpython_release$LDK_TARGET_SUFFIX.so -Wl,--version-script=python/libcode.version -flto -O3 -Wl,--lto-O3 -Wl,-O3 -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
-               [ "$IS_APPLE_CLANG" != "true" ] && llvm-strip -R .llvmbc -R .llvmcmd liblightningpython_release$LDK_TARGET_SUFFIX.so
+               $STRIP -R .llvmbc -R .llvmcmd liblightningpython_release$LDK_TARGET_SUFFIX.so
        fi
 elif [ "$2" = "wasm" ]; then
        echo "Creating TS bindings..."
@@ -341,7 +346,7 @@ else
 
                $COMPILE -o bindings.o -c -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c
                $COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -O3 $2 bindings.o $LDK_LIB -lm
-               [ "$IS_APPLE_CLANG" != "true" ] && llvm-strip -R .llvmbc -R .llvmcmd liblightningjni_release$LDK_TARGET_SUFFIX.so
+               $STRIP -R .llvmbc -R .llvmcmd 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\|3\)\(\.\|)\)" | grep -v "GLIBC_2.\(3\.4\|14\|17\|18\|25\|28\|29\|32\|33\|34\|\))" || echo)"
index fe3b498181ebf1d67ee054c3f16c47605ea3ebc5..b0c100e7fa6fc82e89eb1823593e7dbdab4305a2 100644 (file)
@@ -72,6 +72,7 @@ public class bindings {
                // Fetching the LDK versions from C also checks that the header and binaries match
                System.err.println("Loaded LDK-Java Bindings " + version.get_ldk_java_bindings_version() + " with LDK " + get_ldk_version() + " and LDK-C-Bindings " + get_ldk_c_bindings_version());
        }
+       public static void run_statics() { /* Useful to force the statics to run */ }
        static native void init(java.lang.Class c);
        static native void init_class_cache();
        static native String get_lib_version_string();
@@ -861,7 +862,7 @@ import javax.annotation.Nullable;
             out_c = out_c + "\t\tcase %d: return %s;\n" % (ord_v, var)
             ord_v = ord_v + 1
         out_java_enum = out_java_enum + "\t; static native void init();\n"
-        out_java_enum = out_java_enum + "\tstatic { init(); }\n"
+        out_java_enum = out_java_enum + "\tstatic { org.ldk.impl.bindings.run_statics(); init(); }\n"
         out_java_enum = out_java_enum + "}"
         out_java = out_java + "\tstatic { " + struct_name + ".values(); /* Force enum statics to run */ }\n"
         out_c += "\t}\n"