- name: Run Java Tests against Debug Bindings
run: |
rm liblightningjni.so
- ln -s liblightningjni_debug.so liblightningjni.so
+ ln -s liblightningjni_debug_Linux-amd64.so liblightningjni.so
export LD_LIBRARY_PATH=.
export LD_PRELOAD=/usr/lib/llvm-11/lib/clang/11.0.1/lib/linux/libclang_rt.asan-x86_64.so
export ASAN_OPTIONS=detect_leaks=0
fi
echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" false false
- - name: Check latest headers are in git
+ - name: Check latest headers and release lib are in git
run: |
- # For some reason the debug library is not deterministic, this may be fixed in a future rustc
- git checkout liblightningjni_debug.so
git diff --exit-code
COMMON_COMPILE="clang -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-unused-function -Wno-nullability-completeness -Wno-pointer-sign -Wdate-time -ffile-prefix-map=$(pwd)="
fi
-if [ "$LDK_TARGET" != "" ]; then
- LDK_TARGET_SUFFIX="_$LDK_TARGET"
+TARGET_STRING="$LDK_TARGET"
+if [ "$TARGET_STRING" = "" ]; then
+ # We assume clang-style $CC --version here, but worst-case we just get an empty suffix
+ TARGET_STRING="$($CC --version | grep Target | awk '{ print $2 }')"
fi
+case "$TARGET_STRING" in
+ "x86_64-pc-linux"*)
+ LDK_TARGET_SUFFIX="_Linux-amd64" ;;
+ "x86_64-apple-darwin"*)
+ LDK_TARGET_SUFFIX="_MacOSX-x86_64" ;;
+ "aarch64-apple-darwin"*)
+ LDK_TARGET_SUFFIX="_MacOSX-aarch64" ;;
+ *)
+ LDK_TARGET_SUFFIX=""
+esac
if [ "$LDK_TARGET_CPU" = "" ]; then
LDK_TARGET_CPU="sandybridge"
fi
else
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--version-script=libcode.version -fuse-ld=lld"
$COMPILE -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a
+ if [ "$LDK_TARGET_SUFFIX" != "" ]; then
+ # Copy to JNI native directory for inclusion in JARs
+ cp liblightningjni_release$LDK_TARGET_SUFFIX.so src/main/resources/liblightningjni$LDK_TARGET_SUFFIX.nativelib
+ fi
fi
echo "Creating TS bindings..."
self.bindings_header = """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 {
}
}
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()))