296c19dccef7598752fe21ca222b52ad803c2717
[ldk-java] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   wasm_bindings:
7     runs-on: ubuntu-latest
8     # Ubuntu's version of clang doesn't support....anything that should work.
9     # Ubuntu is an utter trash OS and should generally never be used for anything.
10     # We also require at least rustc 1.51 (ie https://github.com/rust-lang/rust/pull/79998),
11     # so we use debian testing
12     container: debian:bookworm
13     strategy:
14       fail-fast: false
15     steps:
16       - name: Install build utilities and test that clang can build for wasm
17         run: |
18           apt-get update
19           apt-get -y dist-upgrade
20           apt-get -y install cargo libstd-rust-dev-wasm32 lld git g++ clang curl node-typescript npm python3 wasi-libc
21           echo "int main() {}" > genbindings_wasm_test_file.c
22           clang -nostdlib -o /dev/null --target=wasm32-wasi -Wl,--no-entry genbindings_wasm_test_file.c
23           rm genbindings_wasm_test_file.c
24       - name: Checkout source code
25         uses: actions/checkout@v2
26         with:
27           fetch-depth: 0
28       - name: Install cbindgen
29         run: |
30           git clone https://github.com/eqrion/cbindgen
31           cd cbindgen/
32           git checkout v0.20.0
33           cargo update -p indexmap --precise "1.6.2" --verbose
34           cargo install --locked --path .
35       - name: Checkout Rust-Lightning and LDK-C-Bindings git
36         run: |
37           git config --global safe.directory '*'
38           git config --global user.email "ldk-ci@example.com"
39           git config --global user.name "LDK CI"
40           # Note this is a different endpoint, as we need one non-upstream commit!
41           git clone https://github.com/lightningdevkit/rust-lightning
42           cd rust-lightning
43           git checkout origin/0.0.121-bindings
44           cd ..
45           git clone https://github.com/lightningdevkit/ldk-c-bindings
46           cd ldk-c-bindings
47           git checkout 0.0.121
48           cd lightning-c-bindings
49           cargo update -p memchr --precise "2.5.0" --verbose
50       - name: Rebuild C bindings without STD
51         run: |
52           cd ldk-c-bindings
53           git config --global safe.directory "*"
54           ./genbindings.sh ../rust-lightning false
55       - name: Build and Test TS Debug Bindings for Node
56         run: |
57           # We need FinalizationRegistry and top-level await support, which requires node 14.6/8,
58           # however Debian ships with Node 12
59           # Thus, we install the binary nodejs from nodejs.org and test with that.
60           curl https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz > nodejs.tar.xz
61           tar xvvf nodejs.tar.xz
62           export PATH=$(pwd)/$(echo node-*/bin):$PATH
63           ./genbindings.sh ./ldk-c-bindings/ wasm true false
64       - name: Build and Test TS Release Bindings for Node
65         run: |
66           export PATH=$(pwd)/$(echo node-*/bin):$PATH
67           ./genbindings.sh ./ldk-c-bindings/ wasm false false
68       - name: Install Playwright for Web Tests
69         run: |
70           export HOME=/root/ # Github actions is apparently broken
71           export PATH=$(pwd)/$(echo node-*/bin):$PATH
72           # npx playwright install-deps is broken so we do it manually, see https://github.com/microsoft/playwright/issues/11165
73           apt-get install -y --no-install-recommends fonts-liberation libenchant-2-2 libicu72 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 libwebp7 libwebpdemux2 libwoff1 libxkbcommon0 libxml2 libxslt1.1
74           mkdir -p $HOME/.cache/ms-playwright # `playwright install` is too dumb to create this for us
75           chmod -R 777 $HOME/
76           npm i -D playwright@1.37.0-alpha-jul-31-2023
77           npx playwright@1.37.0-alpha-jul-31-2023 install
78       - name: Build and Test TS Debug Bindings for Web
79         run: |
80           export HOME=/root/ # Github actions is apparently broken
81           export PATH=$(pwd)/$(echo node-*/bin):$PATH
82           git config --global safe.directory "*"
83           ./genbindings.sh ./ldk-c-bindings/ wasm true true
84           cd ts
85           rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_debug.wasm ./liblightningjs.wasm
86           python3 -m http.server &
87           SERVER_PID=$!
88           node test/browser.mjs
89           kill $SERVER_PID
90       - name: Build and Test TS Release Bindings for Web
91         run: |
92           export HOME=/root/ # Github actions is apparently broken
93           export PATH=$(pwd)/$(echo node-*/bin):$PATH
94           ./genbindings.sh ./ldk-c-bindings/ wasm false true
95           cd ts
96           rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_release.wasm ./liblightningjs.wasm
97           python3 -m http.server &
98           SERVER_PID=$!
99           node test/browser.mjs
100           kill $SERVER_PID
101       - name: Check latest TS files are in git
102         run: |
103           git checkout ts/package.json
104           git checkout node-net/package.json
105           git diff --exit-code
106
107   c_sharp_bindings:
108     runs-on: ubuntu-latest
109     # Ubuntu's version of clang doesn't support....anything that should work.
110     # Ubuntu is an utter trash OS and should generally never be used for anything.
111     # We also require at least rustc 1.51 (ie https://github.com/rust-lang/rust/pull/79998),
112     # so we use debian testing
113     container: debian:bookworm
114     strategy:
115       fail-fast: false
116     steps:
117       - name: Install required dependencies
118         run: |
119           apt-get update
120           apt-get -y dist-upgrade
121           apt-get -y install cargo lld llvm git g++ clang curl python3 mono-devel
122       - name: Checkout source code
123         uses: actions/checkout@v2
124         with:
125           fetch-depth: 0
126       - name: Install cbindgen
127         run: |
128           git clone https://github.com/eqrion/cbindgen
129           cd cbindgen/
130           git checkout v0.20.0
131           cargo update -p indexmap --precise "1.6.2" --verbose
132           cargo install --locked --path .
133       - name: Checkout Rust-Lightning and LDK-C-Bindings git
134         run: |
135           git config --global safe.directory '*'
136           git config --global user.email "ldk-ci@example.com"
137           git config --global user.name "LDK CI"
138           # Note this is a different endpoint, as we need one non-upstream commit!
139           git clone https://github.com/lightningdevkit/rust-lightning
140           cd rust-lightning
141           git checkout origin/0.0.121-bindings
142           cd ..
143           git clone https://github.com/lightningdevkit/ldk-c-bindings
144           cd ldk-c-bindings
145           git checkout 0.0.121
146           cd lightning-c-bindings
147           cargo update -p memchr --precise "2.5.0" --verbose
148       - name: Rebuild C bindings with STD
149         run: |
150           cd ldk-c-bindings
151           git config --global safe.directory "*"
152           ./genbindings.sh ../rust-lightning true
153       - name: Build and Test C# Debug Bindings
154         run: |
155           ./genbindings.sh ./ldk-c-bindings/ c_sharp true true
156           mono-csc -out:test.exe -langversion:3 -unsafe c_sharp/src/org/ldk/enums/*.cs c_sharp/src/org/ldk/impl/*.cs c_sharp/src/org/ldk/util/*.cs c_sharp/src/org/ldk/structs/*.cs c_sharp/test/src/tests.cs
157           ln -s libldkcsharp_debug_Linux-amd64.so libldkcsharp.so
158           export ASAN_OPTIONS=detect_leaks=0
159           LD_PRELOAD=/usr/lib/llvm-14/lib/clang/14.0.6/lib/linux/libclang_rt.asan-x86_64.so mono test.exe
160
161   c_sharp_determinism:
162     runs-on: ubuntu-latest
163     # Ubuntu's version of clang doesn't support....anything that should work.
164     # Ubuntu is an utter trash OS and should generally never be used for anything.
165     # We also require dotnet so we use fedora
166     container: fedora:39
167     strategy:
168       fail-fast: false
169     steps:
170       - name: Install required dependencies
171         run: |
172           dnf install -y mingw64-gcc git cargo dotnet clang llvm lld faketime rust-std-static-x86_64-pc-windows-gnu which diffutils
173       - name: Checkout source code
174         uses: actions/checkout@v2
175         with:
176           fetch-depth: 0
177       - name: Install cbindgen
178         run: |
179           cargo install cbindgen
180       - name: Checkout Rust-Lightning and LDK-C-Bindings git
181         run: |
182           git config --global safe.directory '*'
183           git config --global user.email "ldk-ci@example.com"
184           git config --global user.name "LDK CI"
185           # Note this is a different endpoint, as we need one non-upstream commit!
186           git clone https://github.com/lightningdevkit/rust-lightning
187           cd rust-lightning
188           git checkout origin/0.0.121-bindings
189           cd ..
190           git clone https://github.com/lightningdevkit/ldk-c-bindings
191           cd ldk-c-bindings
192           git checkout 0.0.121
193       - name: Rebuild C bindings with STD
194         run: |
195           cd ldk-c-bindings
196           export LDK_C_BINDINGS_EXTRA_TARGETS=x86_64-pc-windows-gnu
197           export LDK_C_BINDINGS_EXTRA_TARGET_CCS=`pwd`/deterministic-build-wrappers/clang-x86_64-windows
198           ./genbindings.sh ../rust-lightning true
199       - name: Remove checked-in source to ensure its correctly checked-in
200         run: rm c_sharp/src/org/ldk/enums/*.cs c_sharp/src/org/ldk/impl/*.cs c_sharp/src/org/ldk/structs/*.cs
201       - name: Build Windows C# Bindings
202         run: |
203           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
204           LDK_TARGET=x86_64-pc-windows-gnu ./genbindings.sh ./ldk-c-bindings/ c_sharp false false
205       - name: Build Linux C# Bindings
206         run: |
207           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
208           ./genbindings.sh ./ldk-c-bindings/ c_sharp false false
209       - name: Build Release NUPKG
210         run: |
211           cd c_sharp
212           ./build-release-nupkg.sh
213       - uses: actions/upload-artifact@v3
214         with:
215           name: org.ldk.nupkg
216           path: c_sharp/org.ldk.nupkg
217       - name: Check latest auto-generated code is in git
218         run: |
219           # Checkout files that get updated with version information
220           git checkout c_sharp/packaging_artifacts/package/services/metadata/core-properties/ldk.psmdcp
221           git checkout c_sharp/packaging_artifacts/org.ldk.nuspec
222           git diff --exit-code
223       - name: Checkout latest binaries
224         shell: bash
225         run: |
226           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
227           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
228           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
229           SNAPSHOT_LINK="$(curl "https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
230           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
231           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
232           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
233           tar xvvf ../../bins-snapshot.tgz
234           mv ldk-java-bins-*/* ./
235           rm -r ldk-java-bins-*
236       - name: Compare C# nupkg with built one
237         shell: bash
238         run: |
239           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
240           if ! diff ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"org.ldk.nupkg c_sharp/org.ldk.nupkg; then
241             dnf -y install diffoscope
242             diffoscope ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"org.ldk.nupkg c_sharp/org.ldk.nupkg || echo
243             exit 1
244           fi
245
246   java_bindings:
247     runs-on: ubuntu-latest
248     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
249     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
250     container: debian:bookworm
251     strategy:
252       fail-fast: false
253     steps:
254       - name: Install native Rust toolchain, Valgrind, and build utilitis
255         run: |
256           apt-get update
257           apt-get -y dist-upgrade
258           apt-get -y install cargo valgrind lld git g++ clang openjdk-17-jdk maven faketime zip unzip llvm curl
259       - name: Checkout source code
260         uses: actions/checkout@v2
261         with:
262           fetch-depth: 0
263       - name: Install cbindgen
264         run: |
265           git config --global safe.directory '*'
266           git clone https://github.com/eqrion/cbindgen
267           cd cbindgen/
268           git checkout v0.20.0
269           cargo update -p indexmap --precise "1.6.2" --verbose
270           cargo install --locked --path .
271       - name: Checkout Rust-Lightning and LDK-C-Bindings git
272         run: |
273           git config --global user.email "ldk-ci@example.com"
274           git config --global user.name "LDK CI"
275           # Note this is a different endpoint, as we need one non-upstream commit!
276           git clone https://github.com/lightningdevkit/rust-lightning
277           cd rust-lightning
278           git checkout origin/0.0.121-bindings
279           cd ..
280           git clone https://github.com/lightningdevkit/ldk-c-bindings
281           cd ldk-c-bindings
282           git checkout 0.0.121
283           cd lightning-c-bindings
284           cargo update -p memchr --precise "2.5.0" --verbose
285       - name: Pin proc-macro and quote to meet MSRV
286         run: |
287           cd ldk-c-bindings/c-bindings-gen
288           cargo update -p quote --precise "1.0.30" --verbose
289           cargo update -p proc-macro2 --precise "1.0.65" --verbose
290       - name: Rebuild C bindings, and check the sample app builds + links
291         run: |
292           cd ldk-c-bindings
293           ./genbindings.sh ../rust-lightning true
294       - name: Build Java Debug Bindings
295         run: ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-17-openjdk-amd64/include/ -I/usr/lib/jvm/java-17-openjdk-amd64/include/linux/" true false
296       - name: Run Java Tests against Debug Bindings
297         run: |
298           mv liblightningjni_debug_Linux-amd64.so liblightningjni.so
299           export ASAN_OPTIONS=detect_leaks=0
300           LD_PRELOAD=/usr/lib/llvm-14/lib/clang/14.0.6/lib/linux/libclang_rt.asan-x86_64.so LD_LIBRARY_PATH=. mvn test
301       - name: Build Java Release Bindings
302         run: |
303           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-17-openjdk-amd64/include/ -I/usr/lib/jvm/java-17-openjdk-amd64/include/linux/" false false
304       - name: Check latest headers are in git
305         run: |
306           git checkout pom.xml
307           git diff --exit-code
308
309   java_determinism:
310     runs-on: ubuntu-latest
311     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
312     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
313     container: debian:bookworm
314     strategy:
315       fail-fast: false
316     steps:
317       - name: Install native Rust toolchain, Valgrind, and build utilitis
318         run: |
319           apt-get update
320           apt-get -y dist-upgrade
321           apt-get -y install cargo valgrind lld git g++ clang openjdk-17-jdk maven faketime zip unzip llvm curl
322       - name: Checkout source code
323         uses: actions/checkout@v2
324         with:
325           fetch-depth: 0
326       - name: Install cbindgen
327         run: |
328           git config --global safe.directory '*'
329           git clone https://github.com/eqrion/cbindgen
330           cd cbindgen/
331           git checkout v0.20.0
332           cargo update -p indexmap --precise "1.6.2" --verbose
333           cargo install --locked --path .
334       - name: Checkout Rust-Lightning and LDK-C-Bindings git
335         run: |
336           git config --global user.email "ldk-ci@example.com"
337           git config --global user.name "LDK CI"
338           # Note this is a different endpoint, as we need one non-upstream commit!
339           git clone https://github.com/lightningdevkit/rust-lightning
340           cd rust-lightning
341           git checkout origin/0.0.121-bindings
342           cd ..
343           git clone https://github.com/lightningdevkit/ldk-c-bindings
344           cd ldk-c-bindings
345           git checkout 0.0.121
346           cd lightning-c-bindings
347           cargo update -p memchr --precise "2.5.0" --verbose
348       - name: Pin proc-macro and quote to meet MSRV
349         run: |
350           cd ldk-c-bindings/c-bindings-gen
351           cargo update -p quote --precise "1.0.30" --verbose
352           cargo update -p proc-macro2 --precise "1.0.65" --verbose
353       - name: Rebuild C bindings, and check the sample app builds + links
354         run: |
355           cd ldk-c-bindings
356           ./genbindings.sh ../rust-lightning true
357       - name: Checkout latest MacOS binaries
358         shell: bash
359         run: |
360           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
361           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
362           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
363           SNAPSHOT_LINK="$(curl "https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
364           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
365           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
366           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
367           tar xvvf ../../bins-snapshot.tgz
368           mv ldk-java-bins-*/* ./
369           rm -r ldk-java-bins-*
370           cd ../..
371           mkdir -p src/main/resources/
372       - name: Copy latest MacOS leaktracking libs
373         run: |
374           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
375           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-aarch64-leaktracking.nativelib src/main/resources/liblightningjni_MacOSX-aarch64.nativelib
376           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-x86_64-leaktracking.nativelib src/main/resources/liblightningjni_MacOSX-x86_64.nativelib
377       - name: Build Leaktracking Java Release Bindings
378         run: |
379           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
380           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-17-openjdk-amd64/include/ -I/usr/lib/jvm/java-17-openjdk-amd64/include/linux/" leaks false
381       - name: Build deterministic release jar
382         run: |
383           ./build-release-jar.sh
384           mv ldk-java.jar ldk-java-leaktracking.jar
385       - name: Copy latest MacOS libs
386         shell: bash
387         run: |
388           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
389           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"{aarch64,x86_64}.nativelib src/main/resources/
390       - name: Build Java leaktracking Bindings
391         run: |
392           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
393           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-17-openjdk-amd64/include/ -I/usr/lib/jvm/java-17-openjdk-amd64/include/linux/" leaks false
394           mkdir ldk-java-bins/new/
395           cp src/main/resources/liblightningjni_Linux-amd64.nativelib ldk-java-bins/new/liblightningjni_Linux-amd64-leaktracking.nativelib
396       - name: Build Java Release Bindings
397         run: |
398           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
399           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-17-openjdk-amd64/include/ -I/usr/lib/jvm/java-17-openjdk-amd64/include/linux/" false false
400       - name: Build deterministic release jar
401         run: ./build-release-jar.sh
402       - uses: actions/upload-artifact@v3
403         with:
404           name: ldk-java.jar
405           path: ldk-java.jar
406       - uses: actions/upload-artifact@v3
407         with:
408           name: ldk-java-leaktracking.jar
409           path: ldk-java-leaktracking.jar
410       - name: Check latest library and jars are in bins repo
411         run: |
412           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
413           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_Mac*.nativelib ldk-java-bins/new/
414           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"LDK-release.aar ldk-java-bins/new/
415           cp src/main/resources/liblightningjni_Linux-amd64.nativelib ldk-java-bins/new/
416           cp ldk-java-sources.jar ldk-java-bins/new/
417           cp ldk-java.jar ldk-java-bins/new/
418           cp ldk-java-leaktracking.jar ldk-java-bins/new/
419           cp ldk-java-classes.jar ldk-java-bins/new/
420           cd ldk-java-bins
421           rm "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjs.wasm" # TODO: Test this
422           if ! diff -r "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/" new/; then
423             apt-get -y install diffoscope
424             diffoscope new/ldk-java-sources.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-sources.jar" || echo
425             diffoscope new/ldk-java-classes.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" || echo
426             diffoscope new/ldk-java.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" || echo
427             diffoscope new/ldk-java-leaktracking.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-leaktracking.jar" || echo
428             exit 1
429           fi
430       - name: Run Java Tests against built release jar
431         run: |
432           mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
433           cd javatester
434           mvn package
435           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
436
437   macos_determinism:
438     runs-on: ubuntu-latest
439     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
440     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
441     container: debian:bookworm
442     strategy:
443       fail-fast: false
444     steps:
445       - name: Install native Rust toolchain, Valgrind, and build utilitis
446         run: |
447           apt-get update
448           apt-get -y dist-upgrade
449           apt-get -y install cargo valgrind openjdk-17-jdk lld git g++ clang llvm curl rust-src
450       - name: Checkout source code
451         uses: actions/checkout@v2
452         with:
453           fetch-depth: 0
454       - name: Install cbindgen
455         run: |
456           git config --global safe.directory '*'
457           git clone https://github.com/eqrion/cbindgen
458           cd cbindgen/
459           git checkout v0.20.0
460           cargo update -p indexmap --precise "1.6.2" --verbose
461           cargo install --locked --path .
462       - name: Checkout Rust-Lightning and LDK-C-Bindings git
463         run: |
464           git config --global user.email "ldk-ci@example.com"
465           git config --global user.name "LDK CI"
466           # Note this is a different endpoint, as we need one non-upstream commit!
467           git clone https://github.com/lightningdevkit/rust-lightning
468           cd rust-lightning
469           git checkout origin/0.0.121-bindings
470           cd ..
471           git clone https://github.com/lightningdevkit/ldk-c-bindings
472           cd ldk-c-bindings
473           git checkout 0.0.121
474       - name: Fetch MacOS SDK
475         run: |
476           curl -o Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz https://bitcoincore.org/depends-sources/sdks/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
477           tar xvvf Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
478       - name: Rebuild C bindings, and check the sample app builds + links
479         run: |
480           # rust-src doesn't distribute the rustlib Cargo.lock, but an empty
481           # file seems to suffice to make `-Zbuild-std` happy.
482           touch /usr/lib/rustlib/src/rust/Cargo.lock
483           export MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
484           cd ldk-c-bindings
485           ./genbindings.sh ../rust-lightning true
486       - name: Fetch MacOS OpenJDK 18 for x86_64
487         run: |
488           curl -o openjdk-18.0.1.1_macos-x64_bin.tar.gz https://download.java.net/java/GA/jdk18.0.1.1/65ae32619e2f40f3a9af3af1851d6e19/2/GPL/openjdk-18.0.1.1_macos-x64_bin.tar.gz
489           if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
490             echo "Bad hash"
491             exit 1
492           fi
493           mkdir jdk-x86_64
494           cd jdk-x86_64
495           tar xvvf ../openjdk-18.0.1.1_macos-x64_bin.tar.gz
496       - name: Fetch MacOS OpenJDK 18 for aarch64
497         run: |
498           curl -o openjdk-18.0.1.1_macos-aarch64_bin.tar.gz https://download.java.net/java/GA/jdk18.0.1.1/65ae32619e2f40f3a9af3af1851d6e19/2/GPL/openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
499           if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
500             echo "Bad hash"
501             exit 1
502           fi
503           mkdir jdk-aarch64
504           cd jdk-aarch64
505           tar xvvf ../openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
506       - name: Build MacOS aarch64 Java leaktracking Release Bindings
507         run: |
508           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
509           JAVA_HOME=jdk-aarch64/jdk-18.0.1.1.jdk/Contents/Home
510           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
511           CC=clang LDK_TARGET=aarch64-apple-darwin LDK_TARGET_CPU=apple-a14 ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$MACOS_SDK" leaks false
512           mv src/main/resources/liblightningjni_MacOSX-aarch64.nativelib src/main/resources/liblightningjni_MacOSX-aarch64-leaktracking.nativelib
513       - name: Build MacOS x86_64 Java leaktracking Release Bindings
514         run: |
515           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
516           JAVA_HOME=jdk-x86_64/jdk-18.0.1.1.jdk/Contents/Home
517           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
518           CC=clang LDK_TARGET=x86_64-apple-darwin LDK_TARGET_CPU=sandybridge ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$MACOS_SDK" leaks false
519           mv src/main/resources/liblightningjni_MacOSX-x86_64.nativelib src/main/resources/liblightningjni_MacOSX-x86_64-leaktracking.nativelib
520       - name: Build MacOS aarch64 Java Release Bindings
521         run: |
522           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
523           JAVA_HOME=jdk-aarch64/jdk-18.0.1.1.jdk/Contents/Home
524           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
525           CC=clang LDK_TARGET=aarch64-apple-darwin LDK_TARGET_CPU=apple-a14 ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$MACOS_SDK" false false
526       - name: Build MacOS x86_64 Java Release Bindings
527         run: |
528           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
529           JAVA_HOME=jdk-x86_64/jdk-18.0.1.1.jdk/Contents/Home
530           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
531           CC=clang LDK_TARGET=x86_64-apple-darwin LDK_TARGET_CPU=sandybridge ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$MACOS_SDK" false false
532       - name: Checkout latest binaries
533         run: |
534           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
535           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
536           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
537           SNAPSHOT_LINK="$(curl "https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
538           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
539           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
540           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
541           tar xvvf ../../bins-snapshot.tgz
542           mv ldk-java-bins-*/* ./
543           rm -r ldk-java-bins-*
544           cd ../..
545       - name: Check latest MacOS libraries are in the bins repo
546         shell: bash
547         run: |
548           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
549           for F in liblightningjni_MacOSX-{x86_64,aarch64}{,-leaktracking}.nativelib; do
550             if ! diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F"; then
551               apt-get -y install diffoscope
552               # Sadly these binaries are still non-deterministic, but only due
553               # to a few-byte tag, thus we use diffoscope to ensure there
554               # aren't any "real" differences and move on.
555               diffoscope "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F" || echo
556             fi
557           done
558
559   android:
560     runs-on: ubuntu-latest
561     # Frankly, I'm not really sure why debian and ubuntu differ in the results here, they really shouldn't
562     container: debian:bookworm
563     strategy:
564       fail-fast: false
565     steps:
566       - name: Install rust targets
567         run: |
568           apt-get update
569           apt-get -y dist-upgrade
570           apt-get -y install git g++ clang faketime zip unzip curl openjdk-17-jdk
571           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
572           chmod +x ./rustup.sh
573           ./rustup.sh -y
574           . $HOME/.cargo/env
575           # Temporarily use 1.67.1 to fix https://github.com/rust-lang/rust/issues/108943
576           rustup install 1.67.1
577           rustup default 1.67.1
578           rustup target add armv7-linux-androideabi
579           rustup target add aarch64-linux-android
580           rustup target add i686-linux-android
581           rustup target add x86_64-linux-android
582       - name: Checkout source code
583         uses: actions/checkout@v2
584         with:
585           fetch-depth: 0
586       - name: Install android NDK compilers
587         run: |
588           git config --global safe.directory '*'
589           curl https://dl.google.com/android/repository/android-ndk-r22b-linux-x86_64.zip > android-ndk-r22b-linux-x86_64.zip
590           if [ "$(sha256sum android-ndk-r22b-linux-x86_64.zip | awk '{ print $1 }')" != "ac3a0421e76f71dd330d0cd55f9d99b9ac864c4c034fc67e0d671d022d4e806b" ]; then
591             echo "Bad hash"
592             exit 1
593           fi
594           unzip android-ndk-r22b-linux-x86_64.zip
595       - name: Install cbindgen
596         run: |
597           . $HOME/.cargo/env
598           cargo install cbindgen
599       - name: Checkout Rust-Lightning and LDK-C-Bindings git
600         run: |
601           git config --global user.email "ldk-ci@example.com"
602           git config --global user.name "LDK CI"
603           # Note this is a different endpoint, as we need one non-upstream commit!
604           git clone https://github.com/lightningdevkit/rust-lightning
605           cd rust-lightning
606           git checkout origin/0.0.121-bindings
607           cd ..
608           git clone https://github.com/lightningdevkit/ldk-c-bindings
609           cd ldk-c-bindings
610           git checkout 0.0.121
611           cd lightning-c-bindings
612           . $HOME/.cargo/env
613           cargo update -p memchr --precise "2.5.0" --verbose
614       - name: Checkout Android AAR binaries and artifacts
615         run: |
616           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
617           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
618           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
619           RELEASE_PAGE="https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main"
620           SNAPSHOT_LINK="$(curl "$RELEASE_PAGE" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
621           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
622
623           ANDROID_PAGE="https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=android-artifacts;hb=refs/heads/main"
624           SNAPSHOT_LINK="$(curl "$ANDROID_PAGE" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
625           curl -o android-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
626
627           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
628           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
629           tar xvvf ../../bins-snapshot.tgz
630           mv ldk-java-bins-*/* ./
631           rm -r ldk-java-bins-*
632
633           mkdir -p ../android-artifacts
634           cd ../android-artifacts
635           tar xvvf ../../android-snapshot.tgz
636           mv ldk-java-bins-*/* ./
637           rm -r ldk-java-bins-*
638       - name: Build Android aar
639         run: |
640           . $HOME/.cargo/env
641           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
642           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" ./
643           export ANDROID_TOOLCHAIN="$(pwd)/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64"
644           export PATH="$PATH:$ANDROID_TOOLCHAIN/bin"
645           ./android-build.sh ./rust-lightning ./ldk-c-bindings/ ./ldk-java-bins/android-artifacts
646       - uses: actions/upload-artifact@v3
647         with:
648           name: LDK-release.aar
649           path: LDK-release.aar
650       - name: Check latest library and jars are in bins repo
651         run: |
652           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
653           if ! diff LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"LDK-release.aar; then
654             apt-get -y install diffoscope
655             diffoscope LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/LDK-release.aar"
656             exit 1
657           fi
658
659   osx:
660     strategy:
661       matrix:
662         include:
663           - platform: macos-11
664           - platform: macos-12
665           - platform: macos-13
666       fail-fast: false
667     runs-on: ${{ matrix.platform }}
668     steps:
669       - name: Install Rust components
670         run: |
671           rustup target install aarch64-apple-darwin
672           rustup component add rust-src
673       - name: Checkout source code
674         uses: actions/checkout@v2
675         with:
676           fetch-depth: 0
677       - name: Install cbindgen
678         run: cargo install cbindgen
679       - name: Checkout Rust-Lightning and LDK-C-Bindings git
680         run: |
681           git config --global user.email "ldk-ci@example.com"
682           git config --global user.name "LDK CI"
683           # Note this is a different endpoint, as we need one non-upstream commit!
684           git clone https://github.com/rghtningdevkit/ust-lightning
685           cd rust-lightning
686           git checkout origin/0.0.121-bindings
687           cd ..
688           git clone https://github.com/lightningdevkit/ldk-c-bindings
689           cd ldk-c-bindings
690           git checkout 0.0.121
691           cd lightning-c-bindings
692           cargo update -p memchr --precise "2.5.0" --verbose
693       - name: Rebuild C bindings and check the sample app builds + links
694         run: |
695           cd ldk-c-bindings
696           CC=clang ./genbindings.sh ../rust-lightning true
697       - name: Fetch OpenJDK 18
698         run: |
699           if [ "$(uname -m)" = "arm64" ]; then
700             wget -O openjdk-18.0.1.1_macos-aarch64_bin.tar.gz https://download.java.net/java/GA/jdk18.0.1.1/65ae32619e2f40f3a9af3af1851d6e19/2/GPL/openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
701             if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
702               echo "Bad hash"
703               exit 1
704             fi
705             tar xvvf openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
706           else
707             wget -O openjdk-18.0.1.1_macos-x64_bin.tar.gz https://download.java.net/java/GA/jdk18.0.1.1/65ae32619e2f40f3a9af3af1851d6e19/2/GPL/openjdk-18.0.1.1_macos-x64_bin.tar.gz
708             if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
709               echo "Bad hash"
710               exit 1
711             fi
712             tar xvvf openjdk-18.0.1.1_macos-x64_bin.tar.gz
713           fi
714       - name: Checkout latest Linux binaries
715         run: |
716           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
717           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
718           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
719           SNAPSHOT_LINK="$(wget -O /dev/stdout "https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
720           wget -O bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
721           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
722           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
723           tar xvvf ../../bins-snapshot.tgz
724           mv ldk-java-bins-*/* ./
725           cd ../..
726           mkdir -p src/main/resources/
727           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_Linux-"* src/main/resources/
728       - name: Build Java Release Bindings
729         run: |
730           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
731           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
732           export PATH=$JAVA_HOME/bin:$PATH
733           ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
734
735           if [ "${{ matrix.platform }}" = "macos-11" ]; then
736             export CC="clang --target=aarch64-apple-darwin"
737             export LDK_TARGET=aarch64-apple-darwin
738             export LDK_TARGET_CPU=apple-a14
739             ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
740             cat src/main/resources/liblightningjni_MacOSX-aarch64.nativelib > /dev/null
741
742           fi
743       - name: Fetch Maven 3.8.4
744         run: |
745           # We don't bother using the upstream mirrors as they remove prior
746           # releases aggressively, causing spurious CI failures when we don't
747           # care about the version used.
748           wget -O apache-maven-3.8.4-bin.tar.gz https://bitcoin.ninja/apache-maven-3.8.4-bin.tar.gz
749           if [ "$(shasum -a 256 apache-maven-3.8.4-bin.tar.gz | awk '{ print $1 }')" != "2cdc9c519427bb20fdc25bef5a9063b790e4abd930e7b14b4e9f4863d6f9f13c" ]; then
750             echo "Bad hash"
751             exit 1
752           fi
753           tar xvvf apache-maven-3.8.4-bin.tar.gz
754           export PATH=apache-maven-3.8.4/bin:$PATH
755       - name: Run Java Tests against built jar
756         run: |
757           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
758           export PATH=$JAVA_HOME/bin:$PATH
759           mvn -DskipTests=true package
760           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
761           JAR_VERSION=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}
762           mvn install:install-file -Dfile=target/ldk-java-${JAR_VERSION}.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
763           cd javatester
764           mvn -q -B package
765           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
766       - name: Run Java Tests against release bins
767         run: |
768           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
769           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
770           export PATH=$JAVA_HOME/bin:$PATH
771           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" ./
772           mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
773           cd javatester
774           mvn clean
775           mvn -q -B package
776           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar