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