Skip to content

Commit 7aa095f

Browse files
authored
Merge pull request #46 from TheBlueMatt/main
v0.0.101.1
2 parents 7d6be8a + c0ae06e commit 7aa095f

File tree

185 files changed

+4975
-2771
lines changed

Some content is hidden

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

185 files changed

+4975
-2771
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,25 @@ jobs:
5757
mv liblightningjni_debug_Linux-amd64.so liblightningjni.so
5858
export ASAN_OPTIONS=detect_leaks=0
5959
LD_PRELOAD=/usr/lib/llvm-11/lib/clang/11.0.1/lib/linux/libclang_rt.asan-x86_64.so LD_LIBRARY_PATH=. mvn test
60-
- name: Detect current git version
61-
run: |
62-
# We assume the top commit is just a bindings update commit, so we
63-
# check out the previous commit to use as the commit we git describe.
64-
# If the top commit is a merge commit, we need to get the last merge
65-
# head and assume the latest bindings are built against its parent.
66-
COMMIT_PARENTS=$(git show -s --pretty=format:%P HEAD)
67-
if [ "${#COMMIT_PARENTS}" = 40 ]; then
68-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD^1)"
69-
else
70-
MERGE_HEAD=$(git show --pretty=format:%P HEAD | ( for last in $(cat /dev/stdin); do true; done; echo $last ))
71-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
72-
fi
73-
echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
74-
echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
7560
- name: Checkout latest MacOS binaries
7661
run: |
77-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
62+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
7863
git clone --depth 1 https://git.bitcoin.ninja/ldk-java-bins
7964
mkdir -p src/main/resources/
8065
cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"* src/main/resources/
8166
- name: Build Java/TS Release Bindings
8267
run: |
83-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
68+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
8469
./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
8570
- name: Build deterministic release jar
8671
run: ./build-release-jar.sh
8772
- name: Check latest headers are in git
8873
run: |
74+
git checkout pom.xml
8975
git diff --exit-code
9076
- name: Check latest library and jars are in bins repo
9177
run: |
92-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
78+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
9379
rm "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"*.jar
9480
rm "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_Linux*.nativelib
9581
cp src/main/resources/liblightningjni_Linux-amd64.nativelib "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
@@ -168,34 +154,19 @@ jobs:
168154
git clone https://github.com/lightningdevkit/ldk-c-bindings
169155
cd ldk-c-bindings
170156
git checkout 0.0.101
171-
- name: Detect current git version
172-
run: |
173-
# We assume the top commit is just a bindings update commit, so we
174-
# check out the previous commit to use as the commit we git describe.
175-
# If the top commit is a merge commit, we need to get the last merge
176-
# head and assume the latest bindings are built against its parent.
177-
COMMIT_PARENTS=$(git show -s --pretty=format:%P HEAD)
178-
if [ "${#COMMIT_PARENTS}" = 40 ]; then
179-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD^1)"
180-
else
181-
MERGE_HEAD=$(git show --pretty=format:%P HEAD | ( for last in $(cat /dev/stdin); do true; done; echo $last ))
182-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
183-
fi
184-
echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
185-
echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
186157
- name: Checkout Android AAR binaries and artifacts
187158
run: git clone --depth 1 https://git.bitcoin.ninja/ldk-java-bins
188159
- name: Build Android aar
189160
run: |
190161
. $HOME/.cargo/env
191-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
162+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
192163
cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" ./
193164
export ANDROID_TOOLCHAIN="$(pwd)/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64"
194165
export PATH="$PATH:$ANDROID_TOOLCHAIN/bin"
195166
./android-build.sh ./rust-lightning ./ldk-c-bindings/ ./ldk-java-bins/android-artifacts
196167
- name: Check latest library and jars are in bins repo
197168
run: |
198-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
169+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
199170
rm "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/LDK-release.aar"
200171
cp LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
201172
cd ldk-java-bins
@@ -264,30 +235,15 @@ jobs:
264235
tar xvvf openjdk-16.0.1_osx-x64_bin.tar.gz
265236
export JAVA_HOME=`pwd`/jdk-16.0.1.jdk/Contents/Home
266237
export PATH=$JAVA_HOME/bin:$PATH
267-
- name: Detect current git version
268-
run: |
269-
# We assume the top commit is just a bindings update commit, so we
270-
# check out the previous commit to use as the commit we git describe.
271-
# If the top commit is a merge commit, we need to get the last merge
272-
# head and assume the latest bindings are built against its parent.
273-
COMMIT_PARENTS=$(git show -s --pretty=format:%P HEAD)
274-
if [ "${#COMMIT_PARENTS}" = 40 ]; then
275-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD^1)"
276-
else
277-
MERGE_HEAD=$(git show --pretty=format:%P HEAD | ( for last in $(cat /dev/stdin); do true; done; echo $last ))
278-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
279-
fi
280-
echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
281-
echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
282238
- name: Checkout latest Linux binaries
283239
run: |
284-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
240+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
285241
git clone --depth 1 https://git.bitcoin.ninja/ldk-java-bins
286242
mkdir -p src/main/resources/
287243
cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_Linux-"* src/main/resources/
288244
- name: Build Java/TS Release Bindings
289245
run: |
290-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
246+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
291247
# genbindings.sh always fails as there is no wasm32-wasi library
292248
# available, so instead we check that the expected JNI library
293249
# is created.
@@ -313,7 +269,7 @@ jobs:
313269
- name: Run Java Tests against built jar
314270
run: |
315271
mvn -DskipTests=true package
316-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
272+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
317273
JAR_VERSION=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}
318274
mvn install:install-file -Dfile=target/ldk-java-${JAR_VERSION}.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
319275
cd javatester
@@ -323,7 +279,7 @@ jobs:
323279
- name: Check latest release libs are in git
324280
run: |
325281
if [ "${{ matrix.platform }}" = "macos-11" ]; then
326-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
282+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
327283
rm "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-{x86_64,aarch64}.nativelib
328284
cp src/main/resources/liblightningjni_MacOSX-*.nativelib "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
329285
cd ldk-java-bins
@@ -333,7 +289,7 @@ jobs:
333289
- name: Run Java Tests against release bins
334290
run: |
335291
if [ "${{ matrix.platform }}" != "macos-11" ]; then
336-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
292+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
337293
cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-{x86_64,aarch64}.nativelib src/main/resources/
338294
mvn clean
339295
mvn -DskipTests=true package

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ target
33
.idea
44
*.iml
55
__pycache__
6+
src/main/java/org/ldk/impl/version.java
7+
src/main/jni/version.c
8+
ts/version.ts
9+
ts/version.c

gen_type_mapping.py

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,23 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
268268
opaque_ret_conv_suf = opaque_ret_conv_suf + "\t" + ty_info.var_name + "_ref |= 1;\n"
269269
opaque_ret_conv_suf = opaque_ret_conv_suf + "}"
270270

271+
to_hu_conv_sfx = ""
272+
if not ty_info.is_ptr or holds_ref:
273+
to_hu_conv_sfx = "\n" + ty_info.var_name + "_hu_conv.ptrs_to.add(this);"
271274
if ty_info.is_ptr:
272275
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
273276
arg_conv = opaque_arg_conv, arg_conv_name = "&" + ty_info.var_name + "_conv", arg_conv_cleanup = None,
274277
ret_conv = (ty_info.rust_obj + " " + ty_info.var_name + "_var = *", opaque_ret_conv_suf),
275278
ret_conv_name = ty_info.var_name + "_ref",
276-
to_hu_conv = self.consts.to_hu_conv_templates['ptr'].replace('{human_type}', ty_info.java_hu_ty).replace('{var_name}', ty_info.var_name),
279+
to_hu_conv = self.consts.to_hu_conv_templates['ptr'].replace('{human_type}', ty_info.java_hu_ty).replace('{var_name}', ty_info.var_name) + to_hu_conv_sfx,
277280
to_hu_conv_name = ty_info.var_name + "_hu_conv",
278281
from_hu_conv = from_hu_conv)
279282
else:
280283
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
281284
arg_conv = opaque_arg_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
282285
ret_conv = (ty_info.rust_obj + " " + ty_info.var_name + "_var = ", opaque_ret_conv_suf),
283286
ret_conv_name = ty_info.var_name + "_ref",
284-
to_hu_conv = self.consts.to_hu_conv_templates['default'].replace('{human_type}', ty_info.java_hu_ty).replace('{var_name}', ty_info.var_name) + "\n" + ty_info.var_name + "_hu_conv.ptrs_to.add(this);",
287+
to_hu_conv = self.consts.to_hu_conv_templates['default'].replace('{human_type}', ty_info.java_hu_ty).replace('{var_name}', ty_info.var_name) + to_hu_conv_sfx,
285288
to_hu_conv_name = ty_info.var_name + "_hu_conv",
286289
from_hu_conv = from_hu_conv)
287290

@@ -375,60 +378,27 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
375378
to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ");",
376379
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + " != null ? " + ty_info.var_name + ".ptr : 0", ""))
377380
if ty_info.rust_obj in self.tuple_types:
378-
from_hu_conv_sfx = ""
379-
from_hu_conv = "bindings." + self.tuple_types[ty_info.rust_obj][1].replace("LDK", "") + "_new("
380-
to_hu_conv_pfx = ""
381-
to_hu_conv_sfx = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " + ty_info.java_hu_ty + "("
382-
to_hu_conv_refs = ""
383-
for idx, conv in enumerate(self.tuple_types[ty_info.rust_obj][0]):
384-
if idx != 0:
385-
to_hu_conv_sfx = to_hu_conv_sfx + ", "
386-
from_hu_conv = from_hu_conv + ", "
387-
conv.var_name = ty_info.var_name + "_" + chr(idx + ord("a"))
388-
conv_map = self.map_type_with_info(conv, False, None, is_free, holds_ref)
389-
to_hu_conv_pfx = to_hu_conv_pfx + conv.java_ty + " " + ty_info.var_name + "_" + chr(idx + ord("a")) + " = "
390-
if not conv.is_native_primitive and (conv_map.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns and conv_map.rust_obj == "LDKTxOut":
391-
to_hu_conv_pfx = to_hu_conv_pfx + "bindings." + conv_map.rust_obj.replace("LDK", "") + "_clone("
392-
to_hu_conv_pfx = to_hu_conv_pfx + "bindings." + self.tuple_types[ty_info.rust_obj][1] + "_get_" + chr(idx + ord("a")) + "(" + ty_info.var_name + ")"
393-
if not conv.is_native_primitive and (conv_map.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns and conv_map.rust_obj == "LDKTxOut": # XXX
394-
to_hu_conv_pfx = to_hu_conv_pfx + ")"
395-
to_hu_conv_pfx = to_hu_conv_pfx + ";\n"
396-
if conv_map.to_hu_conv is not None:
397-
to_hu_conv_pfx = to_hu_conv_pfx + conv_map.to_hu_conv + ";\n"
398-
to_hu_conv_sfx = to_hu_conv_sfx + conv_map.to_hu_conv_name
399-
if to_hu_conv_refs is not None:
400-
if conv_map.c_ty.endswith("Array"):
401-
to_hu_conv_refs = None
402-
else:
403-
to_hu_conv_refs = to_hu_conv_refs + "\n" + conv_map.to_hu_conv_name + ".ptrs_to.add(" + ty_info.var_name + "_conv);"
404-
else:
405-
to_hu_conv_sfx = to_hu_conv_sfx + ty_info.var_name + "_" + chr(idx + ord("a"))
406-
if conv_map.from_hu_conv is not None:
407-
from_hu_conv = from_hu_conv + conv_map.from_hu_conv[0].replace(ty_info.var_name + "_" + chr(idx + ord("a")), ty_info.var_name + "." + chr(idx + ord("a")))
408-
if conv_map.from_hu_conv[1] != "":
409-
from_hu_conv_sfx = from_hu_conv_sfx + conv_map.from_hu_conv[1].replace(conv.var_name, ty_info.var_name + "." + chr(idx + ord("a")))
410-
if idx != len(self.tuple_types[ty_info.rust_obj][0]) - 1:
411-
from_hu_conv_sfx += "; "
381+
ret_conv_name = "((uint64_t)" + ty_info.var_name + "_conv)"
382+
if holds_ref:
383+
# If we're trying to return a ref, we have to clone.
384+
# We just blindly assume its implemented and let the compiler fail if its not.
385+
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_conv = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_conv = ", ";")
386+
if (ty_info.rust_obj.replace("LDK", "") + "_clone") not in self.clone_fns:
387+
ret_conv = (ret_conv[0], ret_conv[1] + "\n// Warning: we really need to clone here, but no clone is available for " + ty_info.rust_obj)
388+
ret_conv_name += " | 1"
412389
else:
413-
from_hu_conv = from_hu_conv + ty_info.var_name + "." + chr(idx + ord("a"))
414-
415-
if to_hu_conv_refs is None:
416-
to_hu_conv = to_hu_conv_pfx + to_hu_conv_sfx + ");\n// Warning: We may not free the C tuple object!"
390+
ret_conv = (ret_conv[0], ret_conv[1] + "\n*" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(" + ty_info.var_name + "_conv);")
417391
else:
418-
to_hu_conv = to_hu_conv_pfx + to_hu_conv_sfx + ", () -> {\n"
419-
to_hu_conv = to_hu_conv + "\tbindings." + ty_info.rust_obj.replace("LDK", "") + "_free(" + ty_info.var_name + ");\n"
420-
to_hu_conv = to_hu_conv + "});" + to_hu_conv_refs
421-
if not ty_info.is_ptr and not holds_ref:
422-
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_ref = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_ref = ", ";")
423-
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
424-
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
425-
ret_conv = ret_conv,
426-
ret_conv_name = "(uint64_t)" + ty_info.var_name + "_ref",
427-
to_hu_conv = to_hu_conv, to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (from_hu_conv + ")", from_hu_conv_sfx))
392+
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_conv = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_conv = ", ";")
393+
if not ty_info.is_ptr or holds_ref:
394+
to_hu_conv_sfx = "\n" + ty_info.var_name + "_hu_conv.ptrs_to.add(this);"
395+
else:
396+
to_hu_conv_sfx = ""
428397
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
429398
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
430-
ret_conv = ("uint64_t " + ty_info.var_name + "_ref = (uint64_t)(&", ") | 1;"), ret_conv_name = ty_info.var_name + "_ref",
431-
to_hu_conv = to_hu_conv, to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (from_hu_conv + ")", from_hu_conv_sfx))
399+
ret_conv = ret_conv, ret_conv_name = ret_conv_name,
400+
to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");" + to_hu_conv_sfx,
401+
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + " != null ? " + ty_info.var_name + ".ptr : 0", ""))
432402

433403
# The manually-defined types - TxOut and u5
434404
if ty_info.rust_obj == "LDKu5":

0 commit comments

Comments
 (0)