dda796c93d28843dd6cdf57fc5b43334e848e638
[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.118-bindings
44           cd ..
45           git clone https://github.com/lightningdevkit/ldk-c-bindings
46           cd ldk-c-bindings
47           git checkout 0.0.118
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.118-bindings
142           cd ..
143           git clone https://github.com/lightningdevkit/ldk-c-bindings
144           cd ldk-c-bindings
145           git checkout 0.0.118
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.118-bindings
189           cd ..
190           git clone https://github.com/lightningdevkit/ldk-c-bindings
191           cd ldk-c-bindings
192           git checkout 0.0.118
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       - name: Check latest auto-generated code is in git
214         run: |
215           # Checkout files that get updated with version information
216           git checkout c_sharp/packaging_artifacts/package/services/metadata/core-properties/ldk.psmdcp
217           git checkout c_sharp/packaging_artifacts/org.ldk.nuspec
218           git diff --exit-code
219       - name: Checkout latest binaries
220         shell: bash
221         run: |
222           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
223           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
224           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
225           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)"
226           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
227           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
228           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
229           tar xvvf ../../bins-snapshot.tgz
230           mv ldk-java-bins-*/* ./
231           rm -r ldk-java-bins-*
232       - name: Compare C# nupkg with built one
233         shell: bash
234         run: |
235           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
236           if ! diff ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"org.ldk.nupkg c_sharp/org.ldk.nupkg; then
237             dnf -y install diffoscope
238             diffoscope ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"org.ldk.nupkg c_sharp/org.ldk.nupkg || echo
239             exit 1
240           fi
241
242   java_bindings:
243     runs-on: ubuntu-latest
244     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
245     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
246     container: debian:bookworm
247     strategy:
248       fail-fast: false
249     steps:
250       - name: Install native Rust toolchain, Valgrind, and build utilitis
251         run: |
252           apt-get update
253           apt-get -y dist-upgrade
254           apt-get -y install cargo valgrind lld git g++ clang openjdk-17-jdk maven faketime zip unzip llvm curl
255       - name: Checkout source code
256         uses: actions/checkout@v2
257         with:
258           fetch-depth: 0
259       - name: Install cbindgen
260         run: |
261           git config --global safe.directory '*'
262           git clone https://github.com/eqrion/cbindgen
263           cd cbindgen/
264           git checkout v0.20.0
265           cargo update -p indexmap --precise "1.6.2" --verbose
266           cargo install --locked --path .
267       - name: Checkout Rust-Lightning and LDK-C-Bindings git
268         run: |
269           git config --global user.email "ldk-ci@example.com"
270           git config --global user.name "LDK CI"
271           # Note this is a different endpoint, as we need one non-upstream commit!
272           git clone https://github.com/lightningdevkit/rust-lightning
273           cd rust-lightning
274           git checkout origin/0.0.118-bindings
275           cd ..
276           git clone https://github.com/lightningdevkit/ldk-c-bindings
277           cd ldk-c-bindings
278           git checkout 0.0.118
279           cd lightning-c-bindings
280           cargo update -p memchr --precise "2.5.0" --verbose
281       - name: Pin proc-macro and quote to meet MSRV
282         run: |
283           cd ldk-c-bindings/c-bindings-gen
284           cargo update -p quote --precise "1.0.30" --verbose
285           cargo update -p proc-macro2 --precise "1.0.65" --verbose
286       - name: Rebuild C bindings, and check the sample app builds + links
287         run: |
288           cd ldk-c-bindings
289           ./genbindings.sh ../rust-lightning true
290       - name: Build Java Debug Bindings
291         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
292       - name: Run Java Tests against Debug Bindings
293         run: |
294           mv liblightningjni_debug_Linux-amd64.so liblightningjni.so
295           export ASAN_OPTIONS=detect_leaks=0
296           LD_PRELOAD=/usr/lib/llvm-14/lib/clang/14.0.6/lib/linux/libclang_rt.asan-x86_64.so LD_LIBRARY_PATH=. mvn test
297       - name: Build Java Release Bindings
298         run: |
299           ./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
300       - name: Check latest headers are in git
301         run: |
302           git checkout pom.xml
303           git diff --exit-code
304
305   java_determinism:
306     runs-on: ubuntu-latest
307     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
308     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
309     container: debian:bookworm
310     strategy:
311       fail-fast: false
312     steps:
313       - name: Install native Rust toolchain, Valgrind, and build utilitis
314         run: |
315           apt-get update
316           apt-get -y dist-upgrade
317           apt-get -y install cargo valgrind lld git g++ clang openjdk-17-jdk maven faketime zip unzip llvm curl
318       - name: Checkout source code
319         uses: actions/checkout@v2
320         with:
321           fetch-depth: 0
322       - name: Install cbindgen
323         run: |
324           git config --global safe.directory '*'
325           git clone https://github.com/eqrion/cbindgen
326           cd cbindgen/
327           git checkout v0.20.0
328           cargo update -p indexmap --precise "1.6.2" --verbose
329           cargo install --locked --path .
330       - name: Checkout Rust-Lightning and LDK-C-Bindings git
331         run: |
332           git config --global user.email "ldk-ci@example.com"
333           git config --global user.name "LDK CI"
334           # Note this is a different endpoint, as we need one non-upstream commit!
335           git clone https://github.com/lightningdevkit/rust-lightning
336           cd rust-lightning
337           git checkout origin/0.0.118-bindings
338           cd ..
339           git clone https://github.com/lightningdevkit/ldk-c-bindings
340           cd ldk-c-bindings
341           git checkout 0.0.118
342           cd lightning-c-bindings
343           cargo update -p memchr --precise "2.5.0" --verbose
344       - name: Pin proc-macro and quote to meet MSRV
345         run: |
346           cd ldk-c-bindings/c-bindings-gen
347           cargo update -p quote --precise "1.0.30" --verbose
348           cargo update -p proc-macro2 --precise "1.0.65" --verbose
349       - name: Rebuild C bindings, and check the sample app builds + links
350         run: |
351           cd ldk-c-bindings
352           ./genbindings.sh ../rust-lightning true
353       - name: Checkout latest MacOS binaries
354         shell: bash
355         run: |
356           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
357           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
358           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
359           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)"
360           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
361           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
362           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
363           tar xvvf ../../bins-snapshot.tgz
364           mv ldk-java-bins-*/* ./
365           rm -r ldk-java-bins-*
366           cd ../..
367           mkdir -p src/main/resources/
368       - name: Copy latest MacOS leaktracking libs
369         run: |
370           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
371           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-aarch64-leaktracking.nativelib src/main/resources/liblightningjni_MacOSX-aarch64.nativelib
372           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-x86_64-leaktracking.nativelib src/main/resources/liblightningjni_MacOSX-x86_64.nativelib
373       - name: Build Leaktracking Java Release Bindings
374         run: |
375           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
376           ./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
377       - name: Build deterministic release jar
378         run: |
379           ./build-release-jar.sh
380           mv ldk-java.jar ldk-java-leaktracking.jar
381       - name: Copy latest MacOS libs
382         shell: bash
383         run: |
384           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
385           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"{aarch64,x86_64}.nativelib src/main/resources/
386       - name: Build Java leaktracking Bindings
387         run: |
388           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
389           ./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
390           mkdir ldk-java-bins/new/
391           cp src/main/resources/liblightningjni_Linux-amd64.nativelib ldk-java-bins/new/liblightningjni_Linux-amd64-leaktracking.nativelib
392       - name: Build Java Release Bindings
393         run: |
394           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
395           ./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
396       - name: Build deterministic release jar
397         run: ./build-release-jar.sh
398       - name: Check latest library and jars are in bins repo
399         run: |
400           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
401           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_Mac*.nativelib ldk-java-bins/new/
402           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"LDK-release.aar ldk-java-bins/new/
403           cp src/main/resources/liblightningjni_Linux-amd64.nativelib ldk-java-bins/new/
404           cp ldk-java-sources.jar ldk-java-bins/new/
405           cp ldk-java.jar ldk-java-bins/new/
406           cp ldk-java-leaktracking.jar ldk-java-bins/new/
407           cp ldk-java-classes.jar ldk-java-bins/new/
408           cd ldk-java-bins
409           rm "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjs.wasm" # TODO: Test this
410           if ! diff -r "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/" new/; then
411             apt-get -y install diffoscope
412             diffoscope new/ldk-java-sources.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-sources.jar" || echo
413             diffoscope new/ldk-java-classes.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" || echo
414             diffoscope new/ldk-java.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" || echo
415             diffoscope new/ldk-java-leaktracking.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-leaktracking.jar" || echo
416             exit 1
417           fi
418       - name: Run Java Tests against built release jar
419         run: |
420           mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
421           cd javatester
422           mvn package
423           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
424
425   macos_determinism:
426     runs-on: ubuntu-latest
427     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
428     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
429     container: debian:bookworm
430     strategy:
431       fail-fast: false
432     steps:
433       - name: Install native Rust toolchain, Valgrind, and build utilitis
434         run: |
435           apt-get update
436           apt-get -y dist-upgrade
437           apt-get -y install cargo valgrind openjdk-17-jdk lld git g++ clang llvm curl rust-src
438       - name: Checkout source code
439         uses: actions/checkout@v2
440         with:
441           fetch-depth: 0
442       - name: Install cbindgen
443         run: |
444           git config --global safe.directory '*'
445           git clone https://github.com/eqrion/cbindgen
446           cd cbindgen/
447           git checkout v0.20.0
448           cargo update -p indexmap --precise "1.6.2" --verbose
449           cargo install --locked --path .
450       - name: Checkout Rust-Lightning and LDK-C-Bindings git
451         run: |
452           git config --global user.email "ldk-ci@example.com"
453           git config --global user.name "LDK CI"
454           # Note this is a different endpoint, as we need one non-upstream commit!
455           git clone https://github.com/lightningdevkit/rust-lightning
456           cd rust-lightning
457           git checkout origin/0.0.118-bindings
458           cd ..
459           git clone https://github.com/lightningdevkit/ldk-c-bindings
460           cd ldk-c-bindings
461           git checkout 0.0.118
462       - name: Fetch MacOS SDK
463         run: |
464           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
465           tar xvvf Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
466       - name: Rebuild C bindings, and check the sample app builds + links
467         run: |
468           # rust-src doesn't distribute the rustlib Cargo.lock, but an empty
469           # file seems to suffice to make `-Zbuild-std` happy.
470           touch /usr/lib/rustlib/src/rust/Cargo.lock
471           export MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
472           cd ldk-c-bindings
473           ./genbindings.sh ../rust-lightning true
474       - name: Fetch MacOS OpenJDK 18 for x86_64
475         run: |
476           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
477           if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
478             echo "Bad hash"
479             exit 1
480           fi
481           mkdir jdk-x86_64
482           cd jdk-x86_64
483           tar xvvf ../openjdk-18.0.1.1_macos-x64_bin.tar.gz
484       - name: Fetch MacOS OpenJDK 18 for aarch64
485         run: |
486           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
487           if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
488             echo "Bad hash"
489             exit 1
490           fi
491           mkdir jdk-aarch64
492           cd jdk-aarch64
493           tar xvvf ../openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
494       - name: Build MacOS aarch64 Java leaktracking Release Bindings
495         run: |
496           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
497           JAVA_HOME=jdk-aarch64/jdk-18.0.1.1.jdk/Contents/Home
498           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
499           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
500           mv src/main/resources/liblightningjni_MacOSX-aarch64.nativelib src/main/resources/liblightningjni_MacOSX-aarch64-leaktracking.nativelib
501       - name: Build MacOS x86_64 Java leaktracking Release Bindings
502         run: |
503           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
504           JAVA_HOME=jdk-x86_64/jdk-18.0.1.1.jdk/Contents/Home
505           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
506           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
507           mv src/main/resources/liblightningjni_MacOSX-x86_64.nativelib src/main/resources/liblightningjni_MacOSX-x86_64-leaktracking.nativelib
508       - name: Build MacOS aarch64 Java Release Bindings
509         run: |
510           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
511           JAVA_HOME=jdk-aarch64/jdk-18.0.1.1.jdk/Contents/Home
512           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
513           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
514       - name: Build MacOS x86_64 Java Release Bindings
515         run: |
516           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
517           JAVA_HOME=jdk-x86_64/jdk-18.0.1.1.jdk/Contents/Home
518           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
519           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
520       - name: Checkout latest binaries
521         run: |
522           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
523           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
524           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
525           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)"
526           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
527           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
528           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
529           tar xvvf ../../bins-snapshot.tgz
530           mv ldk-java-bins-*/* ./
531           rm -r ldk-java-bins-*
532           cd ../..
533       - name: Check latest MacOS libraries are in the bins repo
534         shell: bash
535         run: |
536           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
537           for F in liblightningjni_MacOSX-{x86_64,aarch64}{,-leaktracking}.nativelib; do
538             if ! diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F"; then
539               apt-get -y install diffoscope
540               # Sadly these binaries are still non-deterministic, but only due
541               # to a few-byte tag, thus we use diffoscope to ensure there
542               # aren't any "real" differences and move on.
543               diffoscope "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F" || echo
544             fi
545           done
546
547   android:
548     runs-on: ubuntu-latest
549     # Frankly, I'm not really sure why debian and ubuntu differ in the results here, they really shouldn't
550     container: debian:bookworm
551     strategy:
552       fail-fast: false
553     steps:
554       - name: Install rust targets
555         run: |
556           apt-get update
557           apt-get -y dist-upgrade
558           apt-get -y install git g++ clang faketime zip unzip curl openjdk-17-jdk
559           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
560           chmod +x ./rustup.sh
561           ./rustup.sh -y
562           . $HOME/.cargo/env
563           # Temporarily use 1.67.1 to fix https://github.com/rust-lang/rust/issues/108943
564           rustup install 1.67.1
565           rustup default 1.67.1
566           rustup target add armv7-linux-androideabi
567           rustup target add aarch64-linux-android
568           rustup target add i686-linux-android
569           rustup target add x86_64-linux-android
570       - name: Checkout source code
571         uses: actions/checkout@v2
572         with:
573           fetch-depth: 0
574       - name: Install android NDK compilers
575         run: |
576           git config --global safe.directory '*'
577           curl https://dl.google.com/android/repository/android-ndk-r22b-linux-x86_64.zip > android-ndk-r22b-linux-x86_64.zip
578           if [ "$(sha256sum android-ndk-r22b-linux-x86_64.zip | awk '{ print $1 }')" != "ac3a0421e76f71dd330d0cd55f9d99b9ac864c4c034fc67e0d671d022d4e806b" ]; then
579             echo "Bad hash"
580             exit 1
581           fi
582           unzip android-ndk-r22b-linux-x86_64.zip
583       - name: Install cbindgen
584         run: |
585           . $HOME/.cargo/env
586           cargo install cbindgen
587       - name: Checkout Rust-Lightning and LDK-C-Bindings git
588         run: |
589           git config --global user.email "ldk-ci@example.com"
590           git config --global user.name "LDK CI"
591           # Note this is a different endpoint, as we need one non-upstream commit!
592           git clone https://github.com/lightningdevkit/rust-lightning
593           cd rust-lightning
594           git checkout origin/0.0.118-bindings
595           cd ..
596           git clone https://github.com/lightningdevkit/ldk-c-bindings
597           cd ldk-c-bindings
598           git checkout 0.0.118
599           cd lightning-c-bindings
600           . $HOME/.cargo/env
601           cargo update -p memchr --precise "2.5.0" --verbose
602       - name: Checkout Android AAR binaries and artifacts
603         run: |
604           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
605           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
606           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
607           RELEASE_PAGE="https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main"
608           SNAPSHOT_LINK="$(curl "$RELEASE_PAGE" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
609           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
610
611           ANDROID_PAGE="https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=android-artifacts;hb=refs/heads/main"
612           SNAPSHOT_LINK="$(curl "$ANDROID_PAGE" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
613           curl -o android-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
614
615           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
616           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
617           tar xvvf ../../bins-snapshot.tgz
618           mv ldk-java-bins-*/* ./
619           rm -r ldk-java-bins-*
620
621           mkdir -p ../android-artifacts
622           cd ../android-artifacts
623           tar xvvf ../../android-snapshot.tgz
624           mv ldk-java-bins-*/* ./
625           rm -r ldk-java-bins-*
626       - name: Build Android aar
627         run: |
628           . $HOME/.cargo/env
629           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
630           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" ./
631           export ANDROID_TOOLCHAIN="$(pwd)/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64"
632           export PATH="$PATH:$ANDROID_TOOLCHAIN/bin"
633           ./android-build.sh ./rust-lightning ./ldk-c-bindings/ ./ldk-java-bins/android-artifacts
634       - name: Check latest library and jars are in bins repo
635         run: |
636           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
637           if ! diff LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"LDK-release.aar; then
638             apt-get -y install diffoscope
639             diffoscope LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/LDK-release.aar"
640             exit 1
641           fi
642
643   osx:
644     strategy:
645       matrix:
646         include:
647           - platform: macos-11
648           - platform: macos-12
649           - platform: macos-13
650       fail-fast: false
651     runs-on: ${{ matrix.platform }}
652     steps:
653       - name: Install Rust components
654         run: |
655           rustup target install aarch64-apple-darwin
656           rustup component add rust-src
657       - name: Checkout source code
658         uses: actions/checkout@v2
659         with:
660           fetch-depth: 0
661       - name: Install cbindgen
662         run: cargo install cbindgen
663       - name: Checkout Rust-Lightning and LDK-C-Bindings git
664         run: |
665           git config --global user.email "ldk-ci@example.com"
666           git config --global user.name "LDK CI"
667           # Note this is a different endpoint, as we need one non-upstream commit!
668           git clone https://github.com/rghtningdevkit/ust-lightning
669           cd rust-lightning
670           git checkout origin/0.0.118-bindings
671           cd ..
672           git clone https://github.com/lightningdevkit/ldk-c-bindings
673           cd ldk-c-bindings
674           git checkout 0.0.118
675           cd lightning-c-bindings
676           cargo update -p memchr --precise "2.5.0" --verbose
677       - name: Rebuild C bindings and check the sample app builds + links
678         run: |
679           cd ldk-c-bindings
680           CC=clang ./genbindings.sh ../rust-lightning true
681       - name: Fetch OpenJDK 18
682         run: |
683           if [ "$(uname -m)" = "arm64" ]; then
684             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
685             if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
686               echo "Bad hash"
687               exit 1
688             fi
689             tar xvvf openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
690           else
691             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
692             if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
693               echo "Bad hash"
694               exit 1
695             fi
696             tar xvvf openjdk-18.0.1.1_macos-x64_bin.tar.gz
697           fi
698       - name: Checkout latest Linux binaries
699         run: |
700           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
701           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
702           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
703           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)"
704           wget -O bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
705           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
706           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
707           tar xvvf ../../bins-snapshot.tgz
708           mv ldk-java-bins-*/* ./
709           cd ../..
710           mkdir -p src/main/resources/
711           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_Linux-"* src/main/resources/
712       - name: Build Java Release Bindings
713         run: |
714           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
715           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
716           export PATH=$JAVA_HOME/bin:$PATH
717           ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
718
719           if [ "${{ matrix.platform }}" = "macos-11" ]; then
720             export CC="clang --target=aarch64-apple-darwin"
721             export LDK_TARGET=aarch64-apple-darwin
722             export LDK_TARGET_CPU=apple-a14
723             ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
724             cat src/main/resources/liblightningjni_MacOSX-aarch64.nativelib > /dev/null
725
726           fi
727       - name: Fetch Maven 3.8.4
728         run: |
729           # We don't bother using the upstream mirrors as they remove prior
730           # releases aggressively, causing spurious CI failures when we don't
731           # care about the version used.
732           wget -O apache-maven-3.8.4-bin.tar.gz https://bitcoin.ninja/apache-maven-3.8.4-bin.tar.gz
733           if [ "$(shasum -a 256 apache-maven-3.8.4-bin.tar.gz | awk '{ print $1 }')" != "2cdc9c519427bb20fdc25bef5a9063b790e4abd930e7b14b4e9f4863d6f9f13c" ]; then
734             echo "Bad hash"
735             exit 1
736           fi
737           tar xvvf apache-maven-3.8.4-bin.tar.gz
738           export PATH=apache-maven-3.8.4/bin:$PATH
739       - name: Run Java Tests against built jar
740         run: |
741           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
742           export PATH=$JAVA_HOME/bin:$PATH
743           mvn -DskipTests=true package
744           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
745           JAR_VERSION=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}
746           mvn install:install-file -Dfile=target/ldk-java-${JAR_VERSION}.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
747           cd javatester
748           mvn -q -B package
749           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
750       - name: Run Java Tests against release bins
751         run: |
752           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
753           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
754           export PATH=$JAVA_HOME/bin:$PATH
755           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" ./
756           mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
757           cd javatester
758           mvn clean
759           mvn -q -B package
760           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar