Drop binaries from the repo, they are now at https://git.bitcoin.ninja/index.cgi...
[ldk-java] / .github / workflows / build.yml
index 3145675ac66eaacd43cdbd5a6bdb1d3c38532220..8e1707df80cc8565ae3fdd9482526e30646ff906 100644 (file)
@@ -15,7 +15,7 @@ jobs:
         run: |
           apt-get update
           apt-get -y dist-upgrade
-          apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang openjdk-11-jdk maven
+          apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang openjdk-11-jdk maven faketime zip unzip llvm
       - name: Checkout source code
         uses: actions/checkout@v2
         with:
@@ -26,11 +26,10 @@ jobs:
         run: |
           git config --global user.email "ldk-ci@example.com"
           git config --global user.name "LDK CI"
-          git clone https://github.com/rust-bitcoin/rust-lightning
+          # Note this is a different endpoint, as we need one non-upstream commit!
+          git clone https://git.bitcoin.ninja/rust-lightning
           cd rust-lightning
-          git remote add matt https://git.bitcoin.ninja/rust-lightning
-          git fetch matt
-          git merge matt/2021-03-java-bindings-base
+          git checkout origin/2021-03-java-bindings-base
           cd ..
           git clone https://github.com/lightningdevkit/ldk-c-bindings
       - name: Rebuild C bindings without STD for WASM
@@ -51,14 +50,10 @@ jobs:
         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
       - name: Run Java Tests against Debug Bindings
         run: |
-          rm liblightningjni.so
-          ln -s liblightningjni_debug.so liblightningjni.so
-          export LD_LIBRARY_PATH=.
-          export LD_PRELOAD=/usr/lib/llvm-11/lib/clang/11.0.1/lib/linux/libclang_rt.asan-x86_64.so
+          mv liblightningjni_debug_Linux-amd64.so liblightningjni.so
           export ASAN_OPTIONS=detect_leaks=0
-          mvn test
-          git checkout liblightningjni.so
-      - name: Build Java/TS Release Bindings
+          LD_PRELOAD=/usr/lib/llvm-11/lib/clang/11.0.1/lib/linux/libclang_rt.asan-x86_64.so LD_LIBRARY_PATH=. mvn test
+      - name: Detect current git version
         run: |
           # We assume the top commit is just a bindings update commit, so we
           # check out the previous commit to use as the commit we git describe.
@@ -72,9 +67,145 @@ jobs:
             export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
           fi
           echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
+          echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
+      - name: Checkout latest MacOS binaries
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
+          git clone https://git.bitcoin.ninja/ldk-java-bins
+          mkdir -p src/main/resources/
+          cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"* src/main/resources/
+      - name: Build Java/TS Release Bindings
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
           ./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
+      - name: Build deterministic release jar
+        run: ./build-release-jar.sh
+      - name: Run Java Tests against built release jar
+        run: |
+          mvn install:install-file -Dfile=target/ldk-java-1.0-SNAPSHOT.jar -DgroupId=org.ldk -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
+          cd javatester
+          mvn package
+          java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
+          cd ..
       - name: Check latest headers are in git
         run: |
-          # For some reason the debug library is not deterministic, this may be fixed in a future rustc
-          git checkout liblightningjni_debug.so
           git diff --exit-code
+      - name: Check latest library and jars are in bins repo
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
+          cp src/main/resources/liblightningjni_Linux-amd64.nativelib "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
+          cp target/ldk-java-1.0-SNAPSHOT.jar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
+          cp target/ldk-java-1.0-SNAPSHOT-sources.jar "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
+          cd ldk-java-bins
+          git diff --exit-code
+
+  osx:
+    strategy:
+      matrix:
+        include:
+          - platform: macos-10.15
+          # MacOS 11 is currently in private preview, we've applied for access
+          # - platform: macos-11
+    runs-on: ${{ matrix.platform }}
+    env:
+      TOOLCHAIN: stable
+    steps:
+      - name: Install other Rust platforms
+        run: rustup target install aarch64-apple-darwin
+      - name: Fetch upstream LLVM/clang snapshot
+        run: |
+          wget -O clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
+          if [ "$(shasum -a 256 clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "7bc2259bf75c003f644882460fc8e844ddb23b27236fe43a2787870a4cd8ab50" ]; then
+            echo "Bad hash"
+            exit 1
+          fi
+      - name: Unpack upstream LLVM+clang and use it by default
+        run: |
+          tar xvvf clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
+      - name: Checkout source code
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - name: Install cbindgen
+        run: cargo install --force cbindgen
+      - name: Checkout Rust-Lightning and LDK-C-Bindings git
+        run: |
+          git config --global user.email "ldk-ci@example.com"
+          git config --global user.name "LDK CI"
+          git clone https://github.com/rust-bitcoin/rust-lightning
+          cd rust-lightning
+          git remote add matt https://git.bitcoin.ninja/rust-lightning
+          git fetch matt
+          git merge matt/2021-03-java-bindings-base
+          cd ..
+          git clone https://github.com/lightningdevkit/ldk-c-bindings
+      - name: Rebuild C bindings with upstream clang, and check the sample app builds + links
+        run: |
+          cd ldk-c-bindings
+          export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
+          CC=clang ./genbindings.sh ../rust-lightning true
+          cd ..
+      - name: Fetch OpenJDK 16
+        run: |
+          wget -O openjdk-16.0.1_osx-x64_bin.tar.gz https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_osx-x64_bin.tar.gz
+          if [ "$(shasum -a 256 openjdk-16.0.1_osx-x64_bin.tar.gz | awk '{ print $1 }')" != "6098f839954439d4916444757c542c1b8778a32461706812d41cc8bbefce7f2f" ]; then
+            echo "Bad hash"
+            exit 1
+          fi
+          tar xvvf openjdk-16.0.1_osx-x64_bin.tar.gz
+          export JAVA_HOME=`pwd`/jdk-16.0.1.jdk/Contents/Home
+          export PATH=$JAVA_HOME/bin:$PATH
+      - name: Detect current git version
+        run: |
+          # We assume the top commit is just a bindings update commit, so we
+          # check out the previous commit to use as the commit we git describe.
+          # If the top commit is a merge commit, we need to get the last merge
+          # head and assume the latest bindings are built against its parent.
+          COMMIT_PARENTS=$(git show -s --pretty=format:%P HEAD)
+          if [ "${#COMMIT_PARENTS}" = 40 ]; then
+            export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD^1)"
+          else
+            MERGE_HEAD=$(git show --pretty=format:%P HEAD | ( for last in $(cat /dev/stdin); do true; done; echo $last ))
+            export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag $MERGE_HEAD^1)"
+          fi
+          echo "Using $LDK_GARBAGECOLLECTED_GIT_OVERRIDE as git version"
+          echo "$LDK_GARBAGECOLLECTED_GIT_OVERRIDE" > .git_ver
+      - name: Checkout latest Linux binaries
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
+          git clone https://git.bitcoin.ninja/ldk-java-bins
+          mkdir -p src/main/resources/
+          cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_Linux-"* src/main/resources/
+      - name: Build Java/TS Release Bindings
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
+          # genbindings.sh always fails as there is no wasm32-wasi library
+          # available, so instead we check that the expected JNI library
+          # is created.
+          ./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false || echo
+          cat src/main/resources/liblightningjni_MacOSX-x86_64.nativelib > /dev/null
+      - name: Fetch Maven 3.8.1
+        run: |
+          wget -O apache-maven-3.8.1-bin.tar.gz https://apache.osuosl.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
+          if [ "$(shasum -a 256 apache-maven-3.8.1-bin.tar.gz | awk '{ print $1 }')" != "b98a1905eb554d07427b2e5509ff09bd53e2f1dd7a0afa38384968b113abef02" ]; then
+            echo "Bad hash"
+            exit 1
+          fi
+          tar xvvf apache-maven-3.8.1-bin.tar.gz
+          export PATH=apache-maven-3.8.1/bin:$PATH
+      - name: Run Java Tests against built jar
+        run: |
+          mvn -DskipTests=true package
+          mvn install:install-file -Dfile=target/ldk-java-1.0-SNAPSHOT.jar -DgroupId=org.ldk -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
+          cd javatester
+          mvn package
+          java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
+          cd ..
+      - name: Check latest release libs are in git
+        run: |
+          if [ "${{ matrix.platform }}" = "macos-11" ]; then
+            export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(cat .git_ver)"
+            cp src/main/resources/liblightningjni_MacOS-amd64.nativelib "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"
+            cd ldk-java-bins
+            git diff --exit-code
+          fi