Skip to content

Commit 9d652fa

Browse files
authored
Merge pull request #79 from TheBlueMatt/main
TypeScript Cleanups and Fixes
2 parents 1ac8cd1 + 0e66446 commit 9d652fa

File tree

290 files changed

+32968
-20535
lines changed

Some content is hidden

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

290 files changed

+32968
-20535
lines changed

.github/workflows/build.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,46 @@ jobs:
4343
run: |
4444
cd ldk-c-bindings
4545
./genbindings.sh ../rust-lightning false
46-
- name: Build and Test TS Bindings for Node
46+
- name: Build and Test TS Debug Bindings for Node
4747
run: |
4848
# We need FinalizationRegistry and top-level await support, which requires node 14.6/8,
4949
# however Debian ships with Node 12
5050
# Thus, we install the binary nodejs from nodejs.org and test with that.
5151
curl https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz > nodejs.tar.xz
5252
tar xvvf nodejs.tar.xz
53+
export PATH=$(pwd)/$(echo node-*/bin):$PATH
54+
./genbindings.sh ./ldk-c-bindings/ wasm true false
55+
- name: Build and Test TS Release Bindings for Node
56+
run: |
5357
export PATH=$(pwd)/$(echo node-*/bin):$PATH
5458
./genbindings.sh ./ldk-c-bindings/ wasm false false
55-
- name: Build and Test TS Bindings for Web
59+
- name: Install Playwright for Web Tests
5660
run: |
57-
export PATH=$(echo node-*/bin):$PATH
58-
./genbindings.sh ./ldk-c-bindings/ wasm false true
5961
export HOME=/root/ # Github actions is apparently broken
60-
npm i -D playwright
62+
export PATH=$(pwd)/$(echo node-*/bin):$PATH
6163
# npx playwright install-deps is broken so we do it manually, see https://github.com/microsoft/playwright/issues/11165
6264
apt-get install -y --no-install-recommends fonts-liberation libenchant-2-2 libicu67 libjpeg62-turbo libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libdbus-1-3 libdrm2 libegl1 libgbm1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxrandr2 libxshmfence1 xvfb fonts-noto-color-emoji fonts-unifont libfontconfig libfreetype6 xfonts-scalable fonts-ipafont-gothic fonts-wqy-zenhei fonts-tlwg-loma-otf ffmpeg libcairo-gobject2 libdbus-glib-1-2 libfontconfig1 libgdk-pixbuf2.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libxcb-shm0 libxcursor1 libxi6 libxrender1 libxt6 gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good libepoxy0 libevdev2 libgl1 libgles2 libgstreamer-gl1.0-0 libgstreamer1.0-0 libharfbuzz-icu0 libharfbuzz0b libhyphen0 libnotify4 libopenjp2-7 libopus0 libpng16-16 libsecret-1-0 libsoup2.4-1 libwayland-client0 libwayland-egl1 libwayland-server0 libwebp6 libwebpdemux2 libwoff1 libxkbcommon0 libxml2 libxslt1.1
6365
mkdir -p $HOME/.cache/ms-playwright # `playwright install` is too dumb to create this for us
6466
chmod -R 777 $HOME/
67+
npm i -D playwright
6568
npx playwright install
69+
- name: Build and Test TS Debug Bindings for Web
70+
run: |
71+
export HOME=/root/ # Github actions is apparently broken
6672
export PATH=$(pwd)/$(echo node-*/bin):$PATH
73+
./genbindings.sh ./ldk-c-bindings/ wasm true true
6774
cd ts
75+
rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_debug.wasm ./liblightningjs.wasm
6876
python3 -m http.server &
6977
node test/browser.mjs
78+
- name: Build and Test TS Release Bindings for Web
79+
run: |
80+
export HOME=/root/ # Github actions is apparently broken
81+
export PATH=$(pwd)/$(echo node-*/bin):$PATH
82+
./genbindings.sh ./ldk-c-bindings/ wasm false true
83+
cd ts
84+
rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_release.wasm ./liblightningjs.wasm
85+
node test/browser.mjs
7086
- name: Check latest TS files are in git
7187
run: |
7288
git diff --exit-code

gen_type_mapping.py

Lines changed: 25 additions & 22 deletions
Large diffs are not rendered by default.

genbindings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def java_c_types(fn_arg, ret_arr_len):
288288
fn_arg = fn_arg[8:].strip()
289289
else:
290290
java_ty = consts.ptr_native_ty
291-
c_ty = "int64_t"
291+
c_ty = "intptr_t"
292292
arr_ty = "uintptr_t"
293293
rust_obj = "uintptr_t"
294294
fn_arg = fn_arg[9:].strip()

genbindings.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ else
3535
sed -i "s/TransactionOutputs/C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ/g" ./lightning.h
3636
fi
3737

38+
if [ "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" = "" ]; then
39+
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE=$(git describe --tag --dirty)
40+
fi
41+
if [ "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:0:1}" != "v" ]; then
42+
echo "Version tag should start with a v" > /dev/stderr
43+
exit 1
44+
fi
45+
3846
if [ "$2" != "wasm" ]; then
3947
TARGET_STRING="$LDK_TARGET"
4048
if [ "$TARGET_STRING" = "" ]; then
@@ -61,14 +69,6 @@ if [ "$2" != "wasm" ]; then
6169
LDK_TARGET_CPU="sandybridge"
6270
fi
6371

64-
if [ "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" = "" ]; then
65-
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE=$(git describe --tag --dirty)
66-
fi
67-
if [ "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:0:1}" != "v" ]; then
68-
echo "Version tag should start with a v" > /dev/stderr
69-
exit 1
70-
fi
71-
7272
if [ "$(rustc --version --verbose | grep "host:")" = "host: x86_64-apple-darwin" ]; then
7373
# OSX sed is for some reason not compatible with GNU sed
7474
sed -i '' "s/^ <version>.*<\/version>/ <version>${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}<\/version>/g" pom.xml
@@ -203,13 +203,13 @@ else
203203
# We only need malloc and assert/abort, but for now just use WASI for those:
204204
#EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a
205205
EXTRA_LINK=
206-
[ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free"
206+
[ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,aligned_alloc -Wl,-wrap,free"
207207
if [ "$3" = "true" ]; then
208208
WASM_FILE=liblightningjs_debug.wasm
209-
$COMPILE -o liblightningjs_debug.wasm -g -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/debug/libldk.a $EXTRA_LINK
209+
$COMPILE -o liblightningjs_debug.wasm -g -O1 -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/debug/libldk.a $EXTRA_LINK
210210
else
211211
WASM_FILE=liblightningjs_release.wasm
212-
$COMPILE -o liblightningjs_release.wasm -s -Os -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/release/libldk.a $EXTRA_LINK
212+
$COMPILE -o liblightningjs_release.wasm -s -Oz -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/release/libldk.a $EXTRA_LINK
213213
fi
214214

215215
if [ -x "$(which tsc)" ]; then
@@ -223,11 +223,11 @@ else
223223
tsc
224224
else
225225
tsc --types node --typeRoots .
226+
cp ../$WASM_FILE liblightningjs.wasm
227+
echo Ready to publish!
226228
if [ -x "$(which node)" ]; then
227229
NODE_V="$(node --version)"
228230
if [ "${NODE_V:1:2}" -gt 14 ]; then
229-
rm -f liblightningjs.wasm
230-
ln -s "$(pwd)"/../$WASM_FILE liblightningjs.wasm
231231
node test/node.mjs
232232
fi
233233
fi

java_strings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ def constr_hu_array(self, ty_info, arr_len):
673673
# Do a bit of a dance to move any excess [] to the end
674674
conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1]
675675
return conv
676+
def cleanup_converted_native_array(self, ty_info, arr_name):
677+
return None
676678

677679
def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
678680
if fixed_len is not None:

0 commit comments

Comments
 (0)