]> git.bitcoin.ninja Git - ldk-java/commitdiff
Re-generate auto-generated bindings + add Mac OS generated bindings
authorMatt Corallo <git@bluematt.me>
Tue, 15 Jun 2021 23:18:12 +0000 (23:18 +0000)
committerMatt Corallo <git-ldk-build@bluematt.me>
Wed, 16 Jun 2021 18:40:18 +0000 (18:40 +0000)
liblightningjni_debug.so [deleted file]
liblightningjni_release.so [deleted file]
src/main/java/org/ldk/impl/bindings.java
src/main/java/org/ldk/structs/CommonBase.java
src/main/jni/bindings.c
src/main/jni/bindings.c.body
src/main/resources/liblightningjni_Linux-amd64.nativelib [new file with mode: 0755]
src/main/resources/liblightningjni_MacOSX-aarch64.nativelib [new file with mode: 0755]
src/main/resources/liblightningjni_MacOSX-x86_64.nativelib [new file with mode: 0755]

diff --git a/liblightningjni_debug.so b/liblightningjni_debug.so
deleted file mode 100755 (executable)
index 8f58fe0..0000000
Binary files a/liblightningjni_debug.so and /dev/null differ
diff --git a/liblightningjni_release.so b/liblightningjni_release.so
deleted file mode 100755 (executable)
index e30297b..0000000
Binary files a/liblightningjni_release.so and /dev/null differ
index 511f6839d654b27c996e47797530406319463a2a..49f921d2deef9cb8a24e88cc4683bb69dd874e28 100644 (file)
@@ -1,5 +1,11 @@
 package org.ldk.impl;
 import org.ldk.enums.*;
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
 
 public class bindings {
        public static class VecOrSliceDef {
@@ -11,7 +17,24 @@ public class bindings {
                }
        }
        static {
-               System.loadLibrary("lightningjni");
+               try {
+                       // Try to load natively first, this works on Android and in testing.
+                       System.loadLibrary("lightningjni");
+               } catch (UnsatisfiedLinkError _ignored) {
+                       // Otherwise try to load from the library jar.
+                       File tmpdir = new File(System.getProperty("java.io.tmpdir"), "ldk-java-nativelib");
+                       tmpdir.mkdir(); // If it fails to create, assume it was there already
+                       tmpdir.deleteOnExit();
+                       String libname = "liblightningjni_" + System.getProperty("os.name").replaceAll(" ", "") +
+                               "-" + System.getProperty("os.arch").replaceAll(" ", "") + ".nativelib";
+                       try (InputStream is = bindings.class.getResourceAsStream("/" + libname)) {
+                               Path libpath = new File(tmpdir.toPath().toString(), "liblightningjni.so").toPath();
+                               Files.copy(is, libpath, StandardCopyOption.REPLACE_EXISTING);
+                               Runtime.getRuntime().load(libpath.toString());
+                       } catch (IOException e) {
+                               throw new IllegalArgumentException(e);
+                       }
+               }
                init(java.lang.Enum.class, VecOrSliceDef.class);
                init_class_cache();
                if (!get_lib_version_string().equals(get_ldk_java_bindings_version()))
@@ -25,7 +48,7 @@ public class bindings {
        static native String get_lib_version_string();
 
        public static String get_ldk_java_bindings_version() {
-               return "v0.0.98.1";
+               return "v0.0.98.2";
        }
        public static native String get_ldk_c_bindings_version();
        public static native String get_ldk_version();
index acff6661da49875fe3379c8c4dab9052827246ab..1794158b79f8e19164e3c2a838a0926c7fd13d62 100644 (file)
@@ -4,5 +4,4 @@ class CommonBase {
        long ptr;
        LinkedList<Object> ptrs_to = new LinkedList();
        protected CommonBase(long ptr) { this.ptr = ptr; }
-       public long _test_only_get_ptr() { return this.ptr; }
 }
index 4d1fdc889cd1581fa311fa447acc85377b1e796f..68b11b177756f43799db67a96cb041b397c18d47 100644 (file)
@@ -1,5 +1,8 @@
 #define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ
 #define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free
+#include <jni.h>
+// On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
+#define int64_t jlong
 #include "org_ldk_impl_bindings.h"
 #include <lightning.h>
 #include <string.h>
@@ -130,7 +133,7 @@ static inline LDKStr java_to_owned_str(JNIEnv *env, jstring str) {
 }
 
 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1lib_1version_1string(JNIEnv *env, jclass _c) {
-       return str_ref_to_java(env, "v0.0.98.1", strlen("v0.0.98.1"));
+       return str_ref_to_java(env, "v0.0.98.2", strlen("v0.0.98.2"));
 }
 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1ldk_1c_1bindings_1version(JNIEnv *env, jclass _c) {
        return str_ref_to_java(env, check_get_ldk_bindings_version(), strlen(check_get_ldk_bindings_version()));
index 95ae6d52afd2d554cf56da72af27a197751d4ec8..e3fe4d198790c9cda3d0085c41aaad73c4a2c6ab 100644 (file)
@@ -1,3 +1,6 @@
+#include <jni.h>
+// On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
+#define int64_t jlong
 #include "org_ldk_impl_bindings.h"
 #include <lightning.h>
 #include <string.h>
@@ -128,7 +131,7 @@ static inline LDKStr java_to_owned_str(JNIEnv *env, jstring str) {
 }
 
 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1lib_1version_1string(JNIEnv *env, jclass _c) {
-       return str_ref_to_java(env, "v0.0.98.1", strlen("v0.0.98.1"));
+       return str_ref_to_java(env, "v0.0.98.2", strlen("v0.0.98.2"));
 }
 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1ldk_1c_1bindings_1version(JNIEnv *env, jclass _c) {
        return str_ref_to_java(env, check_get_ldk_bindings_version(), strlen(check_get_ldk_bindings_version()));
diff --git a/src/main/resources/liblightningjni_Linux-amd64.nativelib b/src/main/resources/liblightningjni_Linux-amd64.nativelib
new file mode 100755 (executable)
index 0000000..8acc71a
Binary files /dev/null and b/src/main/resources/liblightningjni_Linux-amd64.nativelib differ
diff --git a/src/main/resources/liblightningjni_MacOSX-aarch64.nativelib b/src/main/resources/liblightningjni_MacOSX-aarch64.nativelib
new file mode 100755 (executable)
index 0000000..06f615e
Binary files /dev/null and b/src/main/resources/liblightningjni_MacOSX-aarch64.nativelib differ
diff --git a/src/main/resources/liblightningjni_MacOSX-x86_64.nativelib b/src/main/resources/liblightningjni_MacOSX-x86_64.nativelib
new file mode 100755 (executable)
index 0000000..2c5b8ca
Binary files /dev/null and b/src/main/resources/liblightningjni_MacOSX-x86_64.nativelib differ