[Java] Move MacOS release build to build on Linux and test in CI
[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://git.bitcoin.ninja/rust-lightning
42           cd rust-lightning
43           git checkout origin/2023-04-0.0.115-java-bindings
44           cd ..
45           git clone https://github.com/lightningdevkit/ldk-c-bindings
46           cd ldk-c-bindings
47           git checkout 0.0.115
48       - name: Rebuild C bindings without STD
49         run: |
50           cd ldk-c-bindings
51           git config --global safe.directory "*"
52           ./genbindings.sh ../rust-lightning false
53       - name: Build and Test TS Debug Bindings for Node
54         run: |
55           # We need FinalizationRegistry and top-level await support, which requires node 14.6/8,
56           # however Debian ships with Node 12
57           # Thus, we install the binary nodejs from nodejs.org and test with that.
58           curl https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz > nodejs.tar.xz
59           tar xvvf nodejs.tar.xz
60           export PATH=$(pwd)/$(echo node-*/bin):$PATH
61           ./genbindings.sh ./ldk-c-bindings/ wasm true false
62       - name: Build and Test TS Release Bindings for Node
63         run: |
64           export PATH=$(pwd)/$(echo node-*/bin):$PATH
65           ./genbindings.sh ./ldk-c-bindings/ wasm false false
66       - name: Install Playwright for Web Tests
67         run: |
68           export HOME=/root/ # Github actions is apparently broken
69           export PATH=$(pwd)/$(echo node-*/bin):$PATH
70           # npx playwright install-deps is broken so we do it manually, see https://github.com/microsoft/playwright/issues/11165
71           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
72           mkdir -p $HOME/.cache/ms-playwright # `playwright install` is too dumb to create this for us
73           chmod -R 777 $HOME/
74           npm i -D playwright
75           npx playwright install
76       - name: Build and Test TS Debug Bindings for Web
77         run: |
78           export HOME=/root/ # Github actions is apparently broken
79           export PATH=$(pwd)/$(echo node-*/bin):$PATH
80           git config --global safe.directory "*"
81           ./genbindings.sh ./ldk-c-bindings/ wasm true true
82           cd ts
83           rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_debug.wasm ./liblightningjs.wasm
84           python3 -m http.server &
85           SERVER_PID=$!
86           node test/browser.mjs
87           kill $SERVER_PID
88       - name: Build and Test TS Release Bindings for Web
89         run: |
90           export HOME=/root/ # Github actions is apparently broken
91           export PATH=$(pwd)/$(echo node-*/bin):$PATH
92           ./genbindings.sh ./ldk-c-bindings/ wasm false true
93           cd ts
94           rm liblightningjs.wasm && ln -s $(pwd)/../liblightningjs_release.wasm ./liblightningjs.wasm
95           python3 -m http.server &
96           SERVER_PID=$!
97           node test/browser.mjs
98           kill $SERVER_PID
99       - name: Check latest TS files are in git
100         run: |
101           git checkout ts/package.json
102           git checkout node-net/package.json
103           git diff --exit-code
104
105   java_bindings:
106     runs-on: ubuntu-latest
107     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
108     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
109     container: debian:bullseye
110     strategy:
111       fail-fast: false
112     steps:
113       - name: Install native Rust toolchain, Valgrind, and build utilitis
114         run: |
115           apt-get update
116           apt-get -y dist-upgrade
117           apt-get -y install cargo valgrind lld git g++ clang openjdk-11-jdk maven faketime zip unzip llvm curl
118       - name: Checkout source code
119         uses: actions/checkout@v2
120         with:
121           fetch-depth: 0
122       - name: Install cbindgen
123         run: |
124           git config --global safe.directory '*'
125           git clone https://github.com/eqrion/cbindgen
126           cd cbindgen/
127           git checkout v0.20.0
128           cargo update -p indexmap --precise "1.6.2" --verbose
129           cargo install --locked --path .
130       - name: Checkout Rust-Lightning and LDK-C-Bindings git
131         run: |
132           git config --global user.email "ldk-ci@example.com"
133           git config --global user.name "LDK CI"
134           # Note this is a different endpoint, as we need one non-upstream commit!
135           git clone https://git.bitcoin.ninja/rust-lightning
136           cd rust-lightning
137           git checkout origin/2023-04-0.0.115-java-bindings
138           cd ..
139           git clone https://github.com/lightningdevkit/ldk-c-bindings
140           cd ldk-c-bindings
141           git checkout 0.0.115
142       - name: Rebuild C bindings, and check the sample app builds + links
143         run: |
144           cd ldk-c-bindings
145           ./genbindings.sh ../rust-lightning true
146       - name: Build Java Debug Bindings
147         run: ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" true false
148       - name: Run Java Tests against Debug Bindings
149         run: |
150           mv liblightningjni_debug_Linux-amd64.so liblightningjni.so
151           export ASAN_OPTIONS=detect_leaks=0
152           LD_PRELOAD=/usr/lib/llvm-11/lib/clang/11.0.1/lib/linux/libclang_rt.asan-x86_64.so LD_LIBRARY_PATH=. mvn test
153       - name: Build Java Release Bindings
154         run: |
155           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" false false
156       - name: Check latest headers are in git
157         run: |
158           git checkout pom.xml
159           git diff --exit-code
160
161   java_determinism:
162     runs-on: ubuntu-latest
163     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
164     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
165     container: debian:bullseye
166     strategy:
167       fail-fast: false
168     steps:
169       - name: Install native Rust toolchain, Valgrind, and build utilitis
170         run: |
171           apt-get update
172           apt-get -y dist-upgrade
173           apt-get -y install cargo valgrind lld git g++ clang openjdk-11-jdk maven faketime zip unzip llvm curl
174       - name: Checkout source code
175         uses: actions/checkout@v2
176         with:
177           fetch-depth: 0
178       - name: Install cbindgen
179         run: |
180           git config --global safe.directory '*'
181           git clone https://github.com/eqrion/cbindgen
182           cd cbindgen/
183           git checkout v0.20.0
184           cargo update -p indexmap --precise "1.6.2" --verbose
185           cargo install --locked --path .
186       - name: Checkout Rust-Lightning and LDK-C-Bindings git
187         run: |
188           git config --global user.email "ldk-ci@example.com"
189           git config --global user.name "LDK CI"
190           # Note this is a different endpoint, as we need one non-upstream commit!
191           git clone https://git.bitcoin.ninja/rust-lightning
192           cd rust-lightning
193           git checkout origin/2023-04-0.0.115-java-bindings
194           cd ..
195           git clone https://github.com/lightningdevkit/ldk-c-bindings
196           cd ldk-c-bindings
197           git checkout 0.0.115
198       - name: Rebuild C bindings, and check the sample app builds + links
199         run: |
200           cd ldk-c-bindings
201           ./genbindings.sh ../rust-lightning true
202       - name: Checkout latest MacOS binaries
203         run: |
204           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
205           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
206           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
207           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)"
208           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
209           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
210           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
211           tar xvvf ../../bins-snapshot.tgz
212           mv ldk-java-bins-*/* ./
213           rm -r ldk-java-bins-*
214           cd ../..
215           mkdir -p src/main/resources/
216           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"* src/main/resources/
217           rm src/main/resources/liblightningjni_MacOSX-*-leaktracking.nativelib
218       - name: Build Java Release Bindings
219         run: |
220           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
221           ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" false false
222       - name: Build deterministic release jar
223         run: ./build-release-jar.sh
224       - name: Check latest library and jars are in bins repo
225         run: |
226           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
227           mkdir ldk-java-bins/new/
228           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_Mac*.nativelib ldk-java-bins/new/
229           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"LDK-release.aar ldk-java-bins/new/
230           # ldk-java-leaktracking is only for debug purposes and we don't bother with determinism
231           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"ldk-java-leaktracking.jar ldk-java-bins/new/
232           cp src/main/resources/liblightningjni_Linux-amd64.nativelib ldk-java-bins/new/
233           cp ldk-java-sources.jar ldk-java-bins/new/
234           cp ldk-java.jar ldk-java-bins/new/
235           cp ldk-java-classes.jar ldk-java-bins/new/
236           cp ldk-java-javadoc.jar ldk-java-bins/new/
237           cd ldk-java-bins
238           if ! diff -r "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/" new/; then
239             apt-get -y install diffoscope
240             diffoscope new/ldk-java-sources.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-sources.jar" || echo
241             diffoscope new/ldk-java-javadoc.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-javadoc.jar" || echo
242             diffoscope new/ldk-java-classes.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" || echo
243             diffoscope new/ldk-java.jar "${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" || echo
244             exit 1
245           fi
246       - name: Run Java Tests against built release jar
247         run: |
248           mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
249           cd javatester
250           mvn package
251           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
252
253   macos_determinism:
254     runs-on: ubuntu-latest
255     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
256     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
257     container: debian:bookworm
258     strategy:
259       fail-fast: false
260     steps:
261       - name: Install native Rust toolchain, Valgrind, and build utilitis
262         run: |
263           apt-get update
264           apt-get -y dist-upgrade
265           apt-get -y install cargo valgrind openjdk-17-jdk lld git g++ clang llvm curl rust-src
266       - name: Checkout source code
267         uses: actions/checkout@v2
268         with:
269           fetch-depth: 0
270       - name: Install cbindgen
271         run: |
272           git config --global safe.directory '*'
273           git clone https://github.com/eqrion/cbindgen
274           cd cbindgen/
275           git checkout v0.20.0
276           cargo update -p indexmap --precise "1.6.2" --verbose
277           cargo install --locked --path .
278       - name: Checkout Rust-Lightning and LDK-C-Bindings git
279         run: |
280           git config --global user.email "ldk-ci@example.com"
281           git config --global user.name "LDK CI"
282           # Note this is a different endpoint, as we need one non-upstream commit!
283           git clone https://git.bitcoin.ninja/rust-lightning
284           cd rust-lightning
285           git checkout origin/2023-04-0.0.115-java-bindings
286           cd ..
287           git clone https://github.com/lightningdevkit/ldk-c-bindings
288           cd ldk-c-bindings
289           git checkout 0.0.115
290       - name: Fetch MacOS SDK
291         run: |
292           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
293           tar xvvf Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
294       - name: Rebuild C bindings, and check the sample app builds + links
295         run: |
296           # rust-src doesn't distribute the rustlib Cargo.lock, but an empty
297           # file seems to suffice to make `-Zbuild-std` happy.
298           touch /usr/lib/rustlib/src/rust/Cargo.lock
299           export MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
300           cd ldk-c-bindings
301           ./genbindings.sh ../rust-lightning true
302       - name: Fetch MacOS OpenJDK 18 for x86_64
303         run: |
304           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
305           if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
306             echo "Bad hash"
307             exit 1
308           fi
309           mkdir jdk-x86_64
310           cd jdk-x86_64
311           tar xvvf ../openjdk-18.0.1.1_macos-x64_bin.tar.gz
312       - name: Fetch MacOS OpenJDK 18 for aarch64
313         run: |
314           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
315           if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
316             echo "Bad hash"
317             exit 1
318           fi
319           mkdir jdk-aarch64
320           cd jdk-aarch64
321           tar xvvf ../openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
322       - name: Build MacOS aarch64 Java Release Bindings
323         run: |
324           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
325           JAVA_HOME=jdk-aarch64/jdk-18.0.1.1.jdk/Contents/Home
326           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
327           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
328       - name: Build MacOS x86_64 Java Release Bindings
329         run: |
330           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
331           JAVA_HOME=jdk-x86_64/jdk-18.0.1.1.jdk/Contents/Home
332           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
333           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
334       - name: Checkout latest binaries
335         run: |
336           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
337           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
338           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
339           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)"
340           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
341           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
342           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
343           tar xvvf ../../bins-snapshot.tgz
344           mv ldk-java-bins-*/* ./
345           rm -r ldk-java-bins-*
346           cd ../..
347       - name: Check latest MacOS libraries are in the bins repo
348         shell: bash
349         run: |
350           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
351           for F in liblightningjni_MacOSX-{x86_64,aarch64}.nativelib; do
352             if ! diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F"; then
353               apt-get -y install diffoscope
354               # Sadly these binaries are still non-deterministic, but only due
355               # to a few-byte tag, thus we use diffoscope to ensure there
356               # aren't any "real" differences and move on.
357               diffoscope "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F" || echo
358             fi
359           done
360
361   android:
362     runs-on: ubuntu-latest
363     # Frankly, I'm not really sure why debian and ubuntu differ in the results here, they really shouldn't
364     container: debian:bullseye
365     strategy:
366       fail-fast: false
367     steps:
368       - name: Install rust targets
369         run: |
370           apt-get update
371           apt-get -y dist-upgrade
372           apt-get -y install git g++ clang faketime zip unzip curl openjdk-11-jdk
373           curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
374           chmod +x ./rustup.sh
375           ./rustup.sh -y
376           . $HOME/.cargo/env
377           # Temporarily use 1.67.1 to fix https://github.com/rust-lang/rust/issues/108943
378           rustup install 1.67.1
379           rustup default 1.67.1
380           rustup target add armv7-linux-androideabi
381           rustup target add aarch64-linux-android
382           rustup target add i686-linux-android
383           rustup target add x86_64-linux-android
384       - name: Checkout source code
385         uses: actions/checkout@v2
386         with:
387           fetch-depth: 0
388       - name: Install android NDK compilers
389         run: |
390           git config --global safe.directory '*'
391           curl https://dl.google.com/android/repository/android-ndk-r22b-linux-x86_64.zip > android-ndk-r22b-linux-x86_64.zip
392           if [ "$(sha256sum android-ndk-r22b-linux-x86_64.zip | awk '{ print $1 }')" != "ac3a0421e76f71dd330d0cd55f9d99b9ac864c4c034fc67e0d671d022d4e806b" ]; then
393             echo "Bad hash"
394             exit 1
395           fi
396           unzip android-ndk-r22b-linux-x86_64.zip
397       - name: Install cbindgen
398         run: |
399           . $HOME/.cargo/env
400           cargo install cbindgen
401       - name: Checkout Rust-Lightning and LDK-C-Bindings git
402         run: |
403           git config --global user.email "ldk-ci@example.com"
404           git config --global user.name "LDK CI"
405           # Note this is a different endpoint, as we need one non-upstream commit!
406           git clone https://git.bitcoin.ninja/rust-lightning
407           cd rust-lightning
408           git checkout origin/2023-04-0.0.115-java-bindings
409           cd ..
410           git clone https://github.com/lightningdevkit/ldk-c-bindings
411           cd ldk-c-bindings
412           git checkout 0.0.115
413       - name: Checkout Android AAR binaries and artifacts
414         run: |
415           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
416           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
417           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
418           RELEASE_PAGE="https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE};hb=refs/heads/main"
419           SNAPSHOT_LINK="$(curl "$RELEASE_PAGE" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
420           curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
421
422           ANDROID_PAGE="https://git.bitcoin.ninja/index.cgi?p=ldk-java-bins;a=tree;f=android-artifacts;hb=refs/heads/main"
423           SNAPSHOT_LINK="$(curl "$ANDROID_PAGE" | grep snapshot | grep -o 'href="[a-zA-Z0-9/?\.=;\-]*"' | sed 's/href="//' | tr -d '"' | grep snapshot)"
424           curl -o android-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
425
426           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
427           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
428           tar xvvf ../../bins-snapshot.tgz
429           mv ldk-java-bins-*/* ./
430           rm -r ldk-java-bins-*
431
432           mkdir -p ../android-artifacts
433           cd ../android-artifacts
434           tar xvvf ../../android-snapshot.tgz
435           mv ldk-java-bins-*/* ./
436           rm -r ldk-java-bins-*
437       - name: Build Android aar
438         run: |
439           . $HOME/.cargo/env
440           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
441           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java-classes.jar" ./
442           export ANDROID_TOOLCHAIN="$(pwd)/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64"
443           export PATH="$PATH:$ANDROID_TOOLCHAIN/bin"
444           ./android-build.sh ./rust-lightning ./ldk-c-bindings/ ./ldk-java-bins/android-artifacts
445       - name: Check latest library and jars are in bins repo
446         run: |
447           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
448           if ! diff LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"LDK-release.aar; then
449             apt-get -y install diffoscope
450             diffoscope LDK-release.aar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/LDK-release.aar"
451             exit 1
452           fi
453
454   osx:
455     strategy:
456       matrix:
457         include:
458           - platform: macos-10.15
459           - platform: macos-11
460       fail-fast: false
461     runs-on: ${{ matrix.platform }}
462     steps:
463       - name: Install other Rust platforms
464         run: rustup target install aarch64-apple-darwin
465       - name: Checkout source code
466         uses: actions/checkout@v2
467         with:
468           fetch-depth: 0
469       - name: Fetch upstream LLVM/clang snapshot
470         run: |
471           git config --global safe.directory '*'
472           wget -O clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz
473           if [ "$(shasum -a 256 clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz | awk '{ print $1 }')" != "d16b6d536364c5bec6583d12dd7e6cf841b9f508c4430d9ee886726bd9983f1c" ]; then
474             echo "Bad hash"
475             exit 1
476           fi
477       - name: Unpack upstream LLVM+clang and use it by default
478         run: |
479           tar xvvf clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz
480       - name: Install cbindgen
481         run: cargo install cbindgen
482       - name: Checkout Rust-Lightning and LDK-C-Bindings git
483         run: |
484           git config --global user.email "ldk-ci@example.com"
485           git config --global user.name "LDK CI"
486           # Note this is a different endpoint, as we need one non-upstream commit!
487           git clone https://git.bitcoin.ninja/rust-lightning
488           cd rust-lightning
489           git checkout origin/2023-04-0.0.115-java-bindings
490           cd ..
491           git clone https://github.com/lightningdevkit/ldk-c-bindings
492           cd ldk-c-bindings
493           git checkout 0.0.115
494       - name: Rebuild C bindings with upstream clang, and check the sample app builds + links
495         run: |
496           export PATH=`pwd`/clang+llvm-15.0.7-x86_64-apple-darwin21.0/bin:$PATH
497           cd ldk-c-bindings
498           export CC=clang
499           export CC_x86_64_apple_darwin=clang
500           export CC_aarch64_apple_darwin=clang
501           CC=clang ./genbindings.sh ../rust-lightning true
502       - name: Fetch OpenJDK 18
503         run: |
504           if [ "$(uname -m)" = "arm64" ]; then
505             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
506             if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
507               echo "Bad hash"
508               exit 1
509             fi
510             tar xvvf openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
511           else
512             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
513             if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
514               echo "Bad hash"
515               exit 1
516             fi
517             tar xvvf openjdk-18.0.1.1_macos-x64_bin.tar.gz
518           fi
519       - name: Checkout latest Linux binaries
520         run: |
521           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
522           echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
523           # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
524           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)"
525           wget -O bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
526           mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
527           cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
528           tar xvvf ../../bins-snapshot.tgz
529           mv ldk-java-bins-*/* ./
530           cd ../..
531           mkdir -p src/main/resources/
532           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_Linux-"* src/main/resources/
533       - name: Build Java Release Bindings
534         run: |
535           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
536           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
537           export PATH=$JAVA_HOME/bin:$PATH
538           export PATH=`pwd`/clang+llvm-15.0.7-x86_64-apple-darwin21.0/bin:$PATH
539           ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
540
541           if [ "${{ matrix.platform }}" = "macos-11" ]; then
542             export CC="clang --target=aarch64-apple-darwin"
543             export LDK_TARGET=aarch64-apple-darwin
544             export LDK_TARGET_CPU=apple-a14
545             ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
546             cat src/main/resources/liblightningjni_MacOSX-aarch64.nativelib > /dev/null
547
548           fi
549
550       - name: Fetch Maven 3.8.4
551         run: |
552           # We don't bother using the upstream mirrors as they remove prior
553           # releases aggressively, causing spurious CI failures when we don't
554           # care about the version used.
555           wget -O apache-maven-3.8.4-bin.tar.gz https://bitcoin.ninja/apache-maven-3.8.4-bin.tar.gz
556           if [ "$(shasum -a 256 apache-maven-3.8.4-bin.tar.gz | awk '{ print $1 }')" != "2cdc9c519427bb20fdc25bef5a9063b790e4abd930e7b14b4e9f4863d6f9f13c" ]; then
557             echo "Bad hash"
558             exit 1
559           fi
560           tar xvvf apache-maven-3.8.4-bin.tar.gz
561           export PATH=apache-maven-3.8.4/bin:$PATH
562       - name: Run Java Tests against built jar
563         run: |
564           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
565           export PATH=$JAVA_HOME/bin:$PATH
566           mvn -DskipTests=true package
567           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
568           JAR_VERSION=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}
569           mvn install:install-file -Dfile=target/ldk-java-${JAR_VERSION}.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
570           cd javatester
571           mvn -q -B package
572           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
573       - name: Run Java Tests against release bins
574         run: |
575           export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
576           export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
577           export PATH=$JAVA_HOME/bin:$PATH
578           cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" ./
579           mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
580           cd javatester
581           mvn clean
582           mvn -q -B package
583           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar