Skip to content

Commit 5cdb34f

Browse files
authored
Merge pull request #126 from TheBlueMatt/main
0.0.114.0
2 parents 8aa8a96 + df806a3 commit 5cdb34f

File tree

719 files changed

+58545
-33859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

719 files changed

+58545
-33859
lines changed

.github/workflows/build.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ jobs:
3434
cargo install --locked --path .
3535
- name: Checkout Rust-Lightning and LDK-C-Bindings git
3636
run: |
37+
git config --global safe.directory '*'
3738
git config --global user.email "[email protected]"
3839
git config --global user.name "LDK CI"
3940
# Note this is a different endpoint, as we need one non-upstream commit!
4041
git clone https://git.bitcoin.ninja/rust-lightning
4142
cd rust-lightning
42-
git checkout origin/2022-12-0.0.113-java-bindings
43+
git checkout origin/2023-02-0.0.114-java-bindings
4344
cd ..
4445
git clone https://github.com/lightningdevkit/ldk-c-bindings
4546
cd ldk-c-bindings
46-
git checkout 0.0.113
47+
git checkout 0.0.114
4748
- name: Rebuild C bindings without STD
4849
run: |
4950
cd ldk-c-bindings
@@ -120,6 +121,7 @@ jobs:
120121
fetch-depth: 0
121122
- name: Install cbindgen
122123
run: |
124+
git config --global safe.directory '*'
123125
git clone https://github.com/eqrion/cbindgen
124126
cd cbindgen/
125127
git checkout v0.20.0
@@ -132,11 +134,11 @@ jobs:
132134
# Note this is a different endpoint, as we need one non-upstream commit!
133135
git clone https://git.bitcoin.ninja/rust-lightning
134136
cd rust-lightning
135-
git checkout origin/2022-12-0.0.113-java-bindings
137+
git checkout origin/2023-02-0.0.114-java-bindings
136138
cd ..
137139
git clone https://github.com/lightningdevkit/ldk-c-bindings
138140
cd ldk-c-bindings
139-
git checkout 0.0.113
141+
git checkout 0.0.114
140142
- name: Rebuild C bindings, and check the sample app builds + links
141143
run: |
142144
cd ldk-c-bindings
@@ -175,6 +177,7 @@ jobs:
175177
fetch-depth: 0
176178
- name: Install cbindgen
177179
run: |
180+
git config --global safe.directory '*'
178181
git clone https://github.com/eqrion/cbindgen
179182
cd cbindgen/
180183
git checkout v0.20.0
@@ -187,11 +190,11 @@ jobs:
187190
# Note this is a different endpoint, as we need one non-upstream commit!
188191
git clone https://git.bitcoin.ninja/rust-lightning
189192
cd rust-lightning
190-
git checkout origin/2022-12-0.0.113-java-bindings
193+
git checkout origin/2023-02-0.0.114-java-bindings
191194
cd ..
192195
git clone https://github.com/lightningdevkit/ldk-c-bindings
193196
cd ldk-c-bindings
194-
git checkout 0.0.113
197+
git checkout 0.0.114
195198
- name: Rebuild C bindings, and check the sample app builds + links
196199
run: |
197200
cd ldk-c-bindings
@@ -263,6 +266,9 @@ jobs:
263266
chmod +x ./rustup.sh
264267
./rustup.sh -y
265268
. $HOME/.cargo/env
269+
# Temporarily use 1.67.1 to fix https://github.com/rust-lang/rust/issues/108943
270+
rustup install 1.67.1
271+
rustup default 1.67.1
266272
rustup target add armv7-linux-androideabi
267273
rustup target add aarch64-linux-android
268274
rustup target add i686-linux-android
@@ -273,6 +279,7 @@ jobs:
273279
fetch-depth: 0
274280
- name: Install android NDK compilers
275281
run: |
282+
git config --global safe.directory '*'
276283
curl https://dl.google.com/android/repository/android-ndk-r22b-linux-x86_64.zip > android-ndk-r22b-linux-x86_64.zip
277284
if [ "$(sha256sum android-ndk-r22b-linux-x86_64.zip | awk '{ print $1 }')" != "ac3a0421e76f71dd330d0cd55f9d99b9ac864c4c034fc67e0d671d022d4e806b" ]; then
278285
echo "Bad hash"
@@ -290,11 +297,11 @@ jobs:
290297
# Note this is a different endpoint, as we need one non-upstream commit!
291298
git clone https://git.bitcoin.ninja/rust-lightning
292299
cd rust-lightning
293-
git checkout origin/2022-12-0.0.113-java-bindings
300+
git checkout origin/2023-02-0.0.114-java-bindings
294301
cd ..
295302
git clone https://github.com/lightningdevkit/ldk-c-bindings
296303
cd ldk-c-bindings
297-
git checkout 0.0.113
304+
git checkout 0.0.114
298305
- name: Checkout Android AAR binaries and artifacts
299306
run: |
300307
# Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
@@ -351,16 +358,21 @@ jobs:
351358
uses: actions/checkout@v2
352359
with:
353360
fetch-depth: 0
361+
- name: Temporarily use rustc from yesterday
362+
run: |
363+
rustup install 1.67.1
364+
rustup default 1.67.1
354365
- name: Fetch upstream LLVM/clang snapshot
355366
run: |
356-
wget -O clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.3/clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz
357-
if [ "$(shasum -a 256 clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "ac668586b2b3d068f1e43520a3ef0b1592e5dc3eff1a4a4b772e29803b428a69" ]; then
367+
git config --global safe.directory '*'
368+
wget -O clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz
369+
if [ "$(shasum -a 256 clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz | awk '{ print $1 }')" != "d16b6d536364c5bec6583d12dd7e6cf841b9f508c4430d9ee886726bd9983f1c" ]; then
358370
echo "Bad hash"
359371
exit 1
360372
fi
361373
- name: Unpack upstream LLVM+clang and use it by default
362374
run: |
363-
tar xvvf clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz
375+
tar xvvf clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz
364376
- name: Install cbindgen
365377
run: cargo install cbindgen
366378
- name: Checkout Rust-Lightning and LDK-C-Bindings git
@@ -370,15 +382,18 @@ jobs:
370382
# Note this is a different endpoint, as we need one non-upstream commit!
371383
git clone https://git.bitcoin.ninja/rust-lightning
372384
cd rust-lightning
373-
git checkout origin/2022-12-0.0.113-java-bindings
385+
git checkout origin/2023-02-0.0.114-java-bindings
374386
cd ..
375387
git clone https://github.com/lightningdevkit/ldk-c-bindings
376388
cd ldk-c-bindings
377-
git checkout 0.0.113
389+
git checkout 0.0.114
378390
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
379391
run: |
380-
export PATH=`pwd`/clang+llvm-15.0.3-x86_64-apple-darwin/bin:$PATH
392+
export PATH=`pwd`/clang+llvm-15.0.7-x86_64-apple-darwin21.0/bin:$PATH
381393
cd ldk-c-bindings
394+
export CC=clang
395+
export CC_x86_64_apple_darwin=clang
396+
export CC_aarch64_apple_darwin=clang
382397
CC=clang ./genbindings.sh ../rust-lightning true
383398
- name: Fetch OpenJDK 18
384399
run: |
@@ -416,7 +431,7 @@ jobs:
416431
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
417432
export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
418433
export PATH=$JAVA_HOME/bin:$PATH
419-
export PATH=`pwd`/clang+llvm-15.0.3-x86_64-apple-darwin/bin:$PATH
434+
export PATH=`pwd`/clang+llvm-15.0.7-x86_64-apple-darwin21.0/bin:$PATH
420435
./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
421436
422437
if [ "${{ matrix.platform }}" = "macos-11" ]; then

gen_type_mapping.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
4343
else:
4444
arr_name = "ret"
4545
arr_len = ret_arr_len
46-
if ty_info.c_ty == "int8_tArray":
46+
if ty_info.c_ty == "int8_tArray" or ty_info.c_ty == "int16_tArray":
4747
(set_pfx, set_sfx) = self.consts.set_native_arr_contents(arr_name + "_arr", arr_len, ty_info)
48-
ret_conv = ("int8_tArray " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_len, ty_info) + ";\n" + set_pfx, "")
48+
ret_conv = (ty_info.c_ty + " " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_len, ty_info) + ";\n" + set_pfx, "")
4949
arg_conv_cleanup = None
5050
if not arr_len.isdigit():
5151
arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n"
5252
arg_conv = arg_conv + arr_name + "_ref." + arr_len + " = " + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + ";\n"
53-
if (not ty_info.is_ptr or not holds_ref) and ty_info.rust_obj != "LDKu8slice":
53+
if (not ty_info.is_ptr or not holds_ref) and (ty_info.rust_obj != "LDKu8slice" and ty_info.rust_obj != "LDKu16slice"):
5454
arg_conv = arg_conv + arr_name + "_ref." + ty_info.arr_access + " = MALLOC(" + arr_name + "_ref." + arr_len + ", \"" + ty_info.rust_obj + " Bytes\");\n"
5555
arg_conv = arg_conv + self.consts.get_native_arr_contents(arr_name, arr_name + "_ref." + ty_info.arr_access, arr_name + "_ref." + arr_len, ty_info, True) + ";"
5656
else:
@@ -59,10 +59,10 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
5959
if ty_info.rust_obj == "LDKTransaction" or ty_info.rust_obj == "LDKWitness":
6060
arg_conv = arg_conv + "\n" + arr_name + "_ref.data_is_owned = " + str(holds_ref).lower() + ";"
6161
ret_conv = (ty_info.rust_obj + " " + arr_name + "_var = ", "")
62-
ret_conv = (ret_conv[0], ";\nint8_tArray " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_name + "_var." + arr_len, ty_info) + ";\n")
62+
ret_conv = (ret_conv[0], ";\n" + ty_info.c_ty + " " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_name + "_var." + arr_len, ty_info) + ";\n")
6363
(pfx, sfx) = self.consts.set_native_arr_contents(arr_name + "_arr", arr_name + "_var." + arr_len, ty_info)
6464
ret_conv = (ret_conv[0], ret_conv[1] + pfx + arr_name + "_var." + ty_info.arr_access + sfx + ";")
65-
if not holds_ref and ty_info.rust_obj != "LDKu8slice":
65+
if not holds_ref and (ty_info.rust_obj != "LDKu8slice" and ty_info.rust_obj != "LDKu16slice"):
6666
ret_conv = (ret_conv[0], ret_conv[1] + "\n" + ty_info.rust_obj.replace("LDK", "") + "_free(" + arr_name + "_var);")
6767
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, None, arr_name)
6868
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
@@ -74,10 +74,11 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
7474
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, arr_len, arr_name)
7575
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
7676
else:
77-
arg_conv = "unsigned char " + arr_name + "_arr[" + arr_len + "];\n"
77+
# Note that we just blindly assume we should be using unsigned integers here.
78+
arg_conv = "u" + ty_info.subty.c_ty + " " + arr_name + "_arr[" + arr_len + "];\n"
7879
arg_conv = arg_conv + "CHECK(" + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + " == " + arr_len + ");\n"
7980
arg_conv = arg_conv + self.consts.get_native_arr_contents(arr_name, arr_name + "_arr", arr_len, ty_info, True) + ";\n"
80-
arg_conv = arg_conv + "unsigned char (*" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;"
81+
arg_conv = arg_conv + "u" + ty_info.subty.c_ty + " (*" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;"
8182
ret_conv = (ret_conv[0] + "*", set_sfx + ";")
8283
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, arr_len, arr_name)
8384
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
@@ -429,15 +430,13 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
429430
# underlying unlike Vecs, and it gives Java more freedom.
430431
base_conv = base_conv + "\nFREE(untag_ptr(" + ty_info.var_name + "));"
431432
if ty_info.rust_obj in self.complex_enums:
432-
to_hu_conv_sfx = ""
433433
if needs_full_clone and (ty_info.rust_obj.replace("LDK", "") + "_clone") not in self.clone_fns:
434434
# We really need a full clone here, but for now we just implement
435435
# a manual clone explicitly for Option<Trait>s
436436
if ty_info.contains_trait:
437437
assert ty_info.rust_obj.startswith("LDKCOption") # We don't support contained traits for anything else yet
438438
optional_ty = ty_info.rust_obj[11:-1]
439439
assert "LDK" + optional_ty in self.trait_structs # We don't support contained traits for anything else yet
440-
to_hu_conv_sfx = self.consts.add_ref("this", ty_info.var_name)
441440
base_conv += "\nif (" + ty_info.var_name + "_conv.tag == " + ty_info.rust_obj + "_Some) {"
442441
base_conv += "\n\t// Manually implement clone for Java trait instances"
443442
optional_ty_info = self.java_c_types("LDK" + optional_ty + " " + ty_info.var_name, None)
@@ -451,7 +450,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
451450
ret_conv = (ret_conv[0], ";\n" + self.consts.ptr_c_ty + " " + ty_info.var_name + "_ref = tag_ptr(" + ty_info.var_name + "_copy, true);")
452451
if from_hu_conv is None:
453452
from_hu_conv = (self.consts.get_ptr(ty_info.var_name), "")
454-
from_hu_conv = (from_hu_conv[0], to_hu_conv_sfx)
453+
from_hu_conv = (from_hu_conv[0], self.consts.add_ref("this", ty_info.var_name))
455454
fully_qualified_ty = self.consts.fully_qualified_hu_ty_path(ty_info)
456455
to_hu_call = fully_qualified_ty + ".constr_from_ptr(" + ty_info.var_name + ")"
457456
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,

genbindings.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ def java_c_types(fn_arg, ret_arr_len):
143143
assert var_is_arr_regex.match(fn_arg[8:])
144144
rust_obj = "LDKThirtyTwoBytes"
145145
arr_access = "data"
146+
elif fn_arg.startswith("LDKEightU16s"):
147+
fn_arg = "uint16_t (*" + fn_arg[13:] + ")[8]"
148+
assert var_is_arr_regex.match(fn_arg[9:])
149+
rust_obj = "LDKEightU16s"
150+
arr_access = "data"
146151
elif fn_arg.startswith("LDKU128"):
147152
if fn_arg == "LDKU128":
148153
fn_arg = "LDKU128 arg"
@@ -760,13 +765,20 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines, trait_doc_comment):
760765
for var_line in field_var_lines:
761766
if var_line.group(1) in trait_structs:
762767
field_var_convs.append((var_line.group(1), var_line.group(2), trait_structs[var_line.group(1)]))
763-
flattened_field_var_convs.append((var_line.group(1), var_line.group(2), ))
764-
flattened_field_var_convs.extend(trait_structs[var_line.group(1)])
768+
flattened_field_var_convs.append((var_line.group(1), var_line.group(2), var_line.group(2)))
769+
for field_var in trait_structs[var_line.group(1)]:
770+
if isinstance(field_var, ConvInfo):
771+
flattened_field_var_convs.append(field_var)
772+
else:
773+
path = var_line.group(2)
774+
if len(field_var) > 2:
775+
path = var_line.group(2) + "." + field_var[2]
776+
flattened_field_var_convs.append((field_var[0], field_var[1], path))
765777
else:
766778
mapped = type_mapping_generator.map_type(var_line.group(1) + " " + var_line.group(2), False, None, False, False)
767779
field_var_convs.append(mapped)
768780
flattened_field_var_convs.append(mapped)
769-
trait_structs[struct_name] = field_var_convs
781+
trait_structs[struct_name] = flattened_field_var_convs
770782

771783
field_fns = []
772784
for fn_docs, fn_line in trait_fn_lines:

genbindings.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ if [ "$2" = "c_sharp" ]; then
110110
echo "Building C# bindings..."
111111
COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC"
112112
LINK="-ldl -shared"
113-
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--no-undefined"
113+
[ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined"
114114
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
115115
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
116116
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
117-
[ "$IS_MAC" = "false" -a "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
117+
[ "$IS_MAC" = "false" -a "$3" != "false" ] && LINK="$LINK -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
118118

119119
exit 0 # Sadly compilation doesn't currently work
120120
if [ "$3" = "true" ]; then
121121
$COMPILE $LINK -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
122122
else
123-
$COMPILE -o bindings.o -c -flto -O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
124-
$COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -O3 -Wl,--lto-O3 -Wl,-O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
123+
$COMPILE -o bindings.o -c -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 c_sharp/bindings.c
124+
$COMPILE $LINK -o liblightningjni_release$LDK_TARGET_SUFFIX.so -Wl,--version-script=c_sharp/libcode.version -flto -O3 -Wl,--lto-O3 -Wl,-O3 -Wl,--version-script=c_sharp/libcode.version -I"$1"/lightning-c-bindings/include/ $2 bindings.o "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a -lm
125125
llvm-strip liblightningjni_release$LDK_TARGET_SUFFIX.so
126126
fi
127127
elif [ "$2" = "wasm" ]; then
@@ -249,17 +249,17 @@ else
249249
echo "Building Java bindings..."
250250
COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC"
251251
LINK="-ldl -shared"
252-
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--no-undefined"
252+
[ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined"
253253
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
254254
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && LINK="$LINK -fuse-ld=lld"
255255
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
256-
[ "$IS_MAC" = "false" -a "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
256+
[ "$IS_MAC" = "false" -a "$3" != "false" ] && LINK="$LINK -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
257257
if [ "$3" = "true" ]; then
258258
$COMPILE $LINK -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
259259
else
260260
LDK_LIB="$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a
261261
if [ "$IS_MAC" = "false" -a "$4" = "false" ]; then
262-
COMPILE="$COMPILE -Wl,--version-script=libcode.version -fuse-ld=lld"
262+
LINK="$LINK -Wl,--version-script=libcode.version -fuse-ld=lld"
263263
# __cxa_thread_atexit_impl is used to more effeciently cleanup per-thread local storage by rust libstd.
264264
# However, it is not available on glibc versions 2.17 or earlier, and rust libstd has a null-check and
265265
# fallback in case it is missing.

0 commit comments

Comments
 (0)