Skip to content

Commit cb964a0

Browse files
authored
Merge pull request #150 from TheBlueMatt/main
Ensure bindings statics run before enums try to call native init
2 parents 6ab8c07 + 10dd563 commit cb964a0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Diff for: csharp_strings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,12 @@ def get_java_arr_len(self, arr_name):
576576
return "InternalUtils.getArrayLength(" + arr_name + ")"
577577

578578
def get_java_arr_elem(self, elem_ty, arr_name, idx):
579-
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":
579+
if elem_ty.c_ty == "int64_t" or elem_ty.c_ty == "uint64_t":
580+
return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
581+
elif elem_ty.c_ty.endswith("Array") or elem_ty.c_ty == "uintptr_t" or elem_ty.rust_obj == "LDKStr":
580582
return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
581583
elif elem_ty.rust_obj == "LDKU5":
582584
return "InternalUtils.getU8ArrayElem(" + arr_name + ", " + idx + ")"
583-
elif elem_ty.rust_obj == "LDKStr":
584-
return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")"
585585
else:
586586
assert False
587587

Diff for: genbindings.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ IS_WIN=false
3737
IS_APPLE_CLANG=false
3838
[ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true
3939

40+
STRIP=llvm-strip
41+
[ "$IS_APPLE_CLANG" = "true" ] && STRIP=echo
42+
4043
case "$TARGET_STRING" in
4144
"x86_64-pc-linux"*)
4245
LDK_TARGET_SUFFIX="_Linux-amd64"
@@ -66,6 +69,8 @@ case "$TARGET_STRING" in
6669
CS_PLATFORM_NAME="win-x64"
6770
LDK_JAR_TARGET=true
6871
IS_WIN=true
72+
# llvm-strip currently corrupts DLLs - https://github.com/llvm/llvm-project/issues/63081
73+
STRIP=echo
6974
;;
7075
*)
7176
LDK_TARGET_SUFFIX="_${TARGET_STRING}"
@@ -171,7 +176,7 @@ if [ "$2" = "c_sharp" ]; then
171176
# so we have to build with faketime.
172177
faketime -f "2021-01-01 00:00:00" $COMPILE -o bindings.o -c -O3 -I"$1"/lightning-c-bindings/include/ c_sharp/bindings.c
173178
faketime -f "2021-01-01 00:00:00" $COMPILE $LINK -o libldkcsharp_release$LDK_TARGET_SUFFIX.so -O3 bindings.o $LDK_LIB -lm
174-
[ "$IS_APPLE_CLANG" != "true" ] && llvm-strip -R .llvmbc -R .llvmcmd libldkcsharp_release$LDK_TARGET_SUFFIX.so
179+
$STRIP -R .llvmbc -R .llvmcmd libldkcsharp_release$LDK_TARGET_SUFFIX.so
175180

176181
if [ "$LDK_JAR_TARGET" = "true" ]; then
177182
# Copy resulting native binary for inclusion in release nuget zip
@@ -225,7 +230,7 @@ elif [ "$2" = "python" ]; then
225230
else
226231
$COMPILE -o bindings.o -c -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
227232
$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
228-
[ "$IS_APPLE_CLANG" != "true" ] && llvm-strip -R .llvmbc -R .llvmcmd liblightningpython_release$LDK_TARGET_SUFFIX.so
233+
$STRIP -R .llvmbc -R .llvmcmd liblightningpython_release$LDK_TARGET_SUFFIX.so
229234
fi
230235
elif [ "$2" = "wasm" ]; then
231236
echo "Creating TS bindings..."
@@ -341,7 +346,7 @@ else
341346

342347
$COMPILE -o bindings.o -c -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c
343348
$COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -O3 $2 bindings.o $LDK_LIB -lm
344-
[ "$IS_APPLE_CLANG" != "true" ] && llvm-strip -R .llvmbc -R .llvmcmd liblightningjni_release$LDK_TARGET_SUFFIX.so
349+
$STRIP -R .llvmbc -R .llvmcmd liblightningjni_release$LDK_TARGET_SUFFIX.so
345350

346351
if [ "$IS_MAC" = "false" -a "$4" = "false" ]; then
347352
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)"

Diff for: java_strings.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, DEBUG: bool, target: Target, **kwargs):
7272
// Fetching the LDK versions from C also checks that the header and binaries match
7373
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());
7474
}
75+
public static void run_statics() { /* Useful to force the statics to run */ }
7576
static native void init(java.lang.Class c);
7677
static native void init_class_cache();
7778
static native String get_lib_version_string();
@@ -861,7 +862,7 @@ def native_c_unitary_enum_map(self, struct_name, variants, enum_doc_comment):
861862
out_c = out_c + "\t\tcase %d: return %s;\n" % (ord_v, var)
862863
ord_v = ord_v + 1
863864
out_java_enum = out_java_enum + "\t; static native void init();\n"
864-
out_java_enum = out_java_enum + "\tstatic { init(); }\n"
865+
out_java_enum = out_java_enum + "\tstatic { org.ldk.impl.bindings.run_statics(); init(); }\n"
865866
out_java_enum = out_java_enum + "}"
866867
out_java = out_java + "\tstatic { " + struct_name + ".values(); /* Force enum statics to run */ }\n"
867868
out_c += "\t}\n"

0 commit comments

Comments
 (0)