From: Matt Corallo Date: Tue, 15 Jun 2021 23:18:12 +0000 (+0000) Subject: Re-generate auto-generated bindings + add Mac OS generated bindings X-Git-Tag: v0.0.98.3~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a442b8532ad57aed1fc740141189899b39a15d79;p=ldk-java Re-generate auto-generated bindings + add Mac OS generated bindings --- diff --git a/liblightningjni_debug.so b/liblightningjni_debug.so deleted file mode 100755 index 8f58fe0e..00000000 Binary files a/liblightningjni_debug.so and /dev/null differ diff --git a/liblightningjni_release.so b/liblightningjni_release.so deleted file mode 100755 index e30297b5..00000000 Binary files a/liblightningjni_release.so and /dev/null differ diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index 511f6839..49f921d2 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -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(); diff --git a/src/main/java/org/ldk/structs/CommonBase.java b/src/main/java/org/ldk/structs/CommonBase.java index acff6661..1794158b 100644 --- a/src/main/java/org/ldk/structs/CommonBase.java +++ b/src/main/java/org/ldk/structs/CommonBase.java @@ -4,5 +4,4 @@ class CommonBase { long ptr; LinkedList ptrs_to = new LinkedList(); protected CommonBase(long ptr) { this.ptr = ptr; } - public long _test_only_get_ptr() { return this.ptr; } } diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index 4d1fdc88..68b11b17 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -1,5 +1,8 @@ #define LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ LDKCVec_TransactionOutputsZ #define CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free CVec_TransactionOutputsZ_free +#include +// 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 #include @@ -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())); diff --git a/src/main/jni/bindings.c.body b/src/main/jni/bindings.c.body index 95ae6d52..e3fe4d19 100644 --- a/src/main/jni/bindings.c.body +++ b/src/main/jni/bindings.c.body @@ -1,3 +1,6 @@ +#include +// 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 #include @@ -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 index 00000000..8acc71a4 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 index 00000000..06f615e8 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 index 00000000..2c5b8ca7 Binary files /dev/null and b/src/main/resources/liblightningjni_MacOSX-x86_64.nativelib differ