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