Skip to content

Commit 54be51e

Browse files
authored
Merge pull request #88 from TheBlueMatt/main
Fix 32-bit Java builds
2 parents d941cc4 + 606dcf0 commit 54be51e

File tree

7 files changed

+9187
-9188
lines changed

7 files changed

+9187
-9188
lines changed

android-build.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ set -x
2525
LDK_C_BINDINGS="$(realpath $2)"
2626
RUST_LIGHTNING="$(realpath $1)"
2727
pushd "$2"
28-
export LDK_C_BINDINGS_EXTRA_TARGETS="x86_64-linux-android i686-linux-android armv7-linux-androideabi aarch64-linux-android"
29-
export LDK_C_BINDINGS_EXTRA_TARGET_CCS="x86_64-linux-android24-clang i686-linux-android24-clang armv7a-linux-androideabi24-clang aarch64-linux-android24-clang"
28+
export LDK_C_BINDINGS_EXTRA_TARGETS="x86_64-linux-android armv7-linux-androideabi aarch64-linux-android"
29+
export LDK_C_BINDINGS_EXTRA_TARGET_CCS="x86_64-linux-android24-clang armv7a-linux-androideabi24-clang aarch64-linux-android24-clang"
3030
./genbindings.sh "$RUST_LIGHTNING" true
3131
popd
3232

@@ -38,8 +38,8 @@ rm -fr src/main/resources
3838

3939
EXTRA_TARGETS=( $LDK_C_BINDINGS_EXTRA_TARGETS )
4040
EXTRA_TARGET_CCS=( $LDK_C_BINDINGS_EXTRA_TARGET_CCS )
41-
TARGET_CPUS=( "sandybridge" "generic" "generic" "generic" )
42-
STRIPS=( "x86_64-linux-android-strip" "i686-linux-android-strip" "arm-linux-androideabi-strip" "aarch64-linux-android-strip" )
41+
TARGET_CPUS=( "sandybridge" "generic" "generic" )
42+
STRIPS=( "x86_64-linux-android-strip" "arm-linux-androideabi-strip" "aarch64-linux-android-strip" )
4343
for IDX in ${!EXTRA_TARGETS[@]}; do
4444
export CC="${EXTRA_TARGET_CCS[$IDX]}"
4545
export LDK_TARGET="${EXTRA_TARGETS[$IDX]}"
@@ -57,11 +57,10 @@ ls ldk-java-classes.jar
5757
rm -rf aar
5858
mkdir aar
5959
cp -r "$3/"* ./aar/
60-
mkdir -p ./aar/jni/{armeabi-v7a,arm64-v8a,x86,x86_64}
60+
mkdir -p ./aar/jni/{armeabi-v7a,arm64-v8a,x86_64}
6161

6262
cp liblightningjni_release_aarch64-linux-android.so ./aar/jni/arm64-v8a/liblightningjni.so
6363
cp liblightningjni_release_armv7-linux-androideabi.so ./aar/jni/armeabi-v7a/liblightningjni.so
64-
cp liblightningjni_release_i686-linux-android.so ./aar/jni/x86/liblightningjni.so
6564
cp liblightningjni_release_x86_64-linux-android.so ./aar/jni/x86_64/liblightningjni.so
6665
cp ldk-java-classes.jar ./aar/classes.jar
6766

gen_type_mapping.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
303303
"// Thus, after this call, " + ty_info.var_name + " is reset to null and is now a dummy object.\n" + self.consts.set_null_skip_free(ty_info.var_name))
304304

305305
opaque_ret_conv_suf = ";\n"
306-
opaque_ret_conv_suf += "uintptr_t " + ty_info.var_name + "_ref = 0;\n"
306+
opaque_ret_conv_suf += self.consts.ptr_c_ty + " " + ty_info.var_name + "_ref = 0;\n"
307307
indent = ""
308308
if is_nullable:
309309
opaque_ret_conv_suf += "if ((uintptr_t)" + ty_info.var_name + "_var.inner > 4096) {\n"
@@ -392,7 +392,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
392392
from_hu_conv = (from_hu_conv[0], self.consts.add_ref("this", ty_info.var_name))
393393
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
394394
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
395-
ret_conv = ret_conv, ret_conv_name = "(uintptr_t)" + ty_info.var_name + "_ret",
395+
ret_conv = ret_conv, ret_conv_name = "(" + self.consts.ptr_c_ty + ")" + ty_info.var_name + "_ret",
396396
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";",
397397
to_hu_conv_name = "ret_hu_conv", from_hu_conv = from_hu_conv)
398398
needs_full_clone = not is_free and (not ty_info.is_ptr or ty_info.requires_clone == True) and ty_info.requires_clone != False
@@ -431,11 +431,11 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
431431
base_conv += self.consts.trait_struct_inc_refcnt(optional_ty_info).\
432432
replace("\n", "\n\t").replace(ty_info.var_name + "_conv", ty_info.var_name + "_conv.some")
433433
base_conv += "\n}"
434-
ret_conv = ("uintptr_t " + ty_info.var_name + "_ref = ((uintptr_t)&", ") | 1;")
434+
ret_conv = (self.consts.ptr_c_ty + " " + ty_info.var_name + "_ref = ((uintptr_t)&", ") | 1;")
435435
if not holds_ref:
436436
ret_conv = (ty_info.rust_obj + " *" + ty_info.var_name + "_copy = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n", "")
437437
ret_conv = (ret_conv[0] + "*" + ty_info.var_name + "_copy = ", "")
438-
ret_conv = (ret_conv[0], ";\nuintptr_t " + ty_info.var_name + "_ref = (uintptr_t)" + ty_info.var_name + "_copy;")
438+
ret_conv = (ret_conv[0], ";\n" + self.consts.ptr_c_ty + " " + ty_info.var_name + "_ref = (uintptr_t)" + ty_info.var_name + "_copy;")
439439
if from_hu_conv is None:
440440
from_hu_conv = (self.consts.get_ptr(ty_info.var_name), "")
441441
from_hu_conv = (from_hu_conv[0], to_hu_conv_sfx)
@@ -456,11 +456,11 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
456456
from_hu_conv = (ty_info.var_name + " != null ? " + self.consts.get_ptr(ty_info.var_name) + " : 0", "")
457457
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
458458
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
459-
ret_conv = ret_conv, ret_conv_name = "(uintptr_t)" + ty_info.var_name + "_conv",
459+
ret_conv = ret_conv, ret_conv_name = "(" + self.consts.ptr_c_ty + ")" + ty_info.var_name + "_conv",
460460
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ")") + ";",
461461
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)
462462
if ty_info.rust_obj in self.tuple_types:
463-
ret_conv_name = "((uintptr_t)" + ty_info.var_name + "_conv)"
463+
ret_conv_name = "((" + self.consts.ptr_c_ty + ")" + ty_info.var_name + "_conv)"
464464
if holds_ref:
465465
# If we're trying to return a ref, we have to clone.
466466
if (ty_info.rust_obj.replace("LDK", "") + "_clone") not in self.clone_fns:
@@ -497,16 +497,16 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
497497
if not ty_info.is_ptr and not holds_ref:
498498
ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = MALLOC(sizeof(LDKTxOut), \"LDKTxOut\");\n*" + ty_info.var_name + "_ref = ", ";")
499499
else:
500-
ret_conv = ("uintptr_t " + ty_info.var_name + "_ref = ((uintptr_t)&", ") | 1;")
500+
ret_conv = (self.consts.ptr_c_ty + " " + ty_info.var_name + "_ref = ((uintptr_t)&", ") | 1;")
501501
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
502502
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
503-
ret_conv = ret_conv, ret_conv_name = "(uintptr_t)" + ty_info.var_name + "_ref",
503+
ret_conv = ret_conv, ret_conv_name = "(" + self.consts.ptr_c_ty + ")" + ty_info.var_name + "_ref",
504504
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_conv", "new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";",
505505
to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (self.consts.get_ptr(ty_info.var_name), ""))
506506
elif ty_info.is_ptr:
507507
assert(not is_free)
508508
if ty_info.rust_obj in self.complex_enums:
509-
ret_conv = ("uintptr_t ret_" + ty_info.var_name + " = (uintptr_t)", " | 1; // WARNING: We should clone here!")
509+
ret_conv = (self.consts.ptr_c_ty + " ret_" + ty_info.var_name + " = (uintptr_t)", " | 1; // WARNING: We should clone here!")
510510
from_hu_sfx = self.consts.add_ref("this", ty_info.var_name)
511511
if ty_info.rust_obj.replace("LDK", "") + "_clone" in self.clone_fns:
512512
ret_conv_pfx = ty_info.rust_obj + " *ret_" + ty_info.var_name + " = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + " ret conversion\");\n"
@@ -516,7 +516,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
516516
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
517517
arg_conv = ty_info.rust_obj + "* " + ty_info.var_name + "_conv = (" + ty_info.rust_obj + "*)" + ty_info.var_name + ";",
518518
arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
519-
ret_conv = ret_conv, ret_conv_name = "(uintptr_t)ret_" + ty_info.var_name,
519+
ret_conv = ret_conv, ret_conv_name = "(" + self.consts.ptr_c_ty + ")ret_" + ty_info.var_name,
520520
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ")") + ";",
521521
to_hu_conv_name = ty_info.var_name + "_hu_conv",
522522
from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name) + " & ~1", from_hu_sfx))
@@ -545,19 +545,19 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
545545
arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = None,
546546
ret_conv = (ty_info.rust_obj + " *" + ty_info.var_name + "_clone = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n" +
547547
"*" + ty_info.var_name + "_clone = " + ty_info.rust_obj.replace("LDK", "") + "_clone(", ");"),
548-
ret_conv_name = "(uintptr_t)" + ty_info.var_name + "_clone",
548+
ret_conv_name = "(" + self.consts.ptr_c_ty + ")" + ty_info.var_name + "_clone",
549549
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";",
550550
to_hu_conv_name = "ret_hu_conv",
551551
from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), ""))
552552
else:
553553
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
554554
arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = None,
555-
ret_conv = ("// WARNING: This object doesn't live past this scope, needs clone!\nuintptr_t ret_" + ty_info.var_name + " = ((uintptr_t)", ") | 1;"),
555+
ret_conv = ("// WARNING: This object doesn't live past this scope, needs clone!\n" + self.consts.ptr_c_ty + " ret_" + ty_info.var_name + " = ((uintptr_t)", ") | 1;"),
556556
ret_conv_name = "ret_" + ty_info.var_name,
557557
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";",
558558
to_hu_conv_name = "ret_hu_conv",
559559
from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name)))
560-
ret_conv = ("uintptr_t ret_" + ty_info.var_name + " = (uintptr_t)", ";")
560+
ret_conv = (self.consts.ptr_c_ty + " ret_" + ty_info.var_name + " = (uintptr_t)", ";")
561561
if holds_ref:
562562
ret_conv = (ret_conv[0], " | 1;")
563563
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,

genbindings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def java_c_types(fn_arg, ret_arr_len):
298298
fn_arg = fn_arg[8:].strip()
299299
else:
300300
java_ty = consts.ptr_native_ty
301-
c_ty = "intptr_t"
301+
c_ty = consts.ptr_c_ty
302302
arr_ty = "uintptr_t"
303303
rust_obj = "uintptr_t"
304304
fn_arg = fn_arg[9:].strip()

0 commit comments

Comments
 (0)