]> git.bitcoin.ninja Git - ldk-java/commitdiff
[Java] Move MacOS release build to build on Linux and test in CI
authorMatt Corallo <git@bluematt.me>
Sun, 4 Jun 2023 04:49:58 +0000 (04:49 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 4 Jun 2023 05:37:11 +0000 (05:37 +0000)
.github/workflows/build.yml

index 6ce9785a61d15b3101a14e3f433037943cc59ee9..98a900896a67cd9d7b864c9e84e6ddee040c62c1 100644 (file)
@@ -250,6 +250,114 @@ jobs:
           mvn package
           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
 
+  macos_determinism:
+    runs-on: ubuntu-latest
+    # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
+    # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
+    container: debian:bookworm
+    strategy:
+      fail-fast: false
+    steps:
+      - name: Install native Rust toolchain, Valgrind, and build utilitis
+        run: |
+          apt-get update
+          apt-get -y dist-upgrade
+          apt-get -y install cargo valgrind openjdk-17-jdk lld git g++ clang llvm curl rust-src
+      - name: Checkout source code
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - name: Install cbindgen
+        run: |
+          git config --global safe.directory '*'
+          git clone https://github.com/eqrion/cbindgen
+          cd cbindgen/
+          git checkout v0.20.0
+          cargo update -p indexmap --precise "1.6.2" --verbose
+          cargo install --locked --path .
+      - 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"
+          # 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 checkout origin/2023-04-0.0.115-java-bindings
+          cd ..
+          git clone https://github.com/lightningdevkit/ldk-c-bindings
+          cd ldk-c-bindings
+          git checkout 0.0.115
+      - name: Fetch MacOS SDK
+        run: |
+          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
+          tar xvvf Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
+      - name: Rebuild C bindings, and check the sample app builds + links
+        run: |
+          # rust-src doesn't distribute the rustlib Cargo.lock, but an empty
+          # file seems to suffice to make `-Zbuild-std` happy.
+          touch /usr/lib/rustlib/src/rust/Cargo.lock
+          export MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
+          cd ldk-c-bindings
+          ./genbindings.sh ../rust-lightning true
+      - name: Fetch MacOS OpenJDK 18 for x86_64
+        run: |
+          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
+          if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-x64_bin.tar.gz | awk '{ print $1 }')" != "f02d17ec5a387555f8489abc352d973b6c10364409b597046025938e2266d72a" ]; then
+            echo "Bad hash"
+            exit 1
+          fi
+          mkdir jdk-x86_64
+          cd jdk-x86_64
+          tar xvvf ../openjdk-18.0.1.1_macos-x64_bin.tar.gz
+      - name: Fetch MacOS OpenJDK 18 for aarch64
+        run: |
+          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
+          if [ "$(shasum -a 256 openjdk-18.0.1.1_macos-aarch64_bin.tar.gz | awk '{ print $1 }')" != "29773ad68063bdad7fbaeb762cd873d3f243e86de380d3ac5335cdb929371fb5" ]; then
+            echo "Bad hash"
+            exit 1
+          fi
+          mkdir jdk-aarch64
+          cd jdk-aarch64
+          tar xvvf ../openjdk-18.0.1.1_macos-aarch64_bin.tar.gz
+      - name: Build MacOS aarch64 Java Release Bindings
+        run: |
+          MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
+          JAVA_HOME=jdk-aarch64/jdk-18.0.1.1.jdk/Contents/Home
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
+          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
+      - name: Build MacOS x86_64 Java Release Bindings
+        run: |
+          MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers"
+          JAVA_HOME=jdk-x86_64/jdk-18.0.1.1.jdk/Contents/Home
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
+          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
+      - name: Checkout latest binaries
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
+          echo "Fetching deterministic binaries for LDK-GC ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
+          # Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
+          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)"
+          curl -o bins-snapshot.tgz "https://git.bitcoin.ninja${SNAPSHOT_LINK}"
+          mkdir -p ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
+          cd ldk-java-bins/"${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}"
+          tar xvvf ../../bins-snapshot.tgz
+          mv ldk-java-bins-*/* ./
+          rm -r ldk-java-bins-*
+          cd ../..
+      - name: Check latest MacOS libraries are in the bins repo
+        shell: bash
+        run: |
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
+          for F in liblightningjni_MacOSX-{x86_64,aarch64}.nativelib; do
+            if ! diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F"; then
+              apt-get -y install diffoscope
+              # Sadly these binaries are still non-deterministic, but only due
+              # to a few-byte tag, thus we use diffoscope to ensure there
+              # aren't any "real" differences and move on.
+              diffoscope "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/$F" "src/main/resources/$F" || echo
+            fi
+          done
+
   android:
     runs-on: ubuntu-latest
     # Frankly, I'm not really sure why debian and ubuntu differ in the results here, they really shouldn't
@@ -462,38 +570,14 @@ jobs:
           cd javatester
           mvn -q -B package
           java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
-      - name: Check latest release libs are in git
-        run: |
-          if [ "${{ matrix.platform }}" = "macos-11" ]; then
-            export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
-            # Sadly, OSX binaries are not currently deterministic, more debugging is needed.
-            diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-x86_64.nativelib src/main/resources/liblightningjni_MacOSX-x86_64.nativelib || echo
-            diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-aarch64.nativelib src/main/resources/liblightningjni_MacOSX-aarch64.nativelib || echo
-          fi
-      - name: Upload CI x86_64 build for analysis
-        if: matrix.platform == 'macos-11'
-        uses: actions/upload-artifact@v3.0.0
-        with:
-          name: liblightningjni_MacOSX-x86_64.nativelib.ci-build
-          path: src/main/resources/liblightningjni_MacOSX-x86_64.nativelib
-      - name: Upload CI aarch64 build for analysis
-        if: matrix.platform == 'macos-11'
-        uses: actions/upload-artifact@v3.0.0
-        with:
-          name: liblightningjni_MacOSX-aarch64.nativelib.ci-build
-          path: src/main/resources/liblightningjni_MacOSX-aarch64.nativelib
       - name: Run Java Tests against release bins
         run: |
-          if [ "${{ matrix.platform }}" != "macos-11" ]; then
-            export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
-            export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
-            export PATH=$JAVA_HOME/bin:$PATH
-            cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-{x86_64,aarch64}.nativelib src/main/resources/
-            mvn clean
-            mvn -q -B -DskipTests=true package
-            JAR_VERSION=${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}
-            mvn install:install-file -Dfile=target/ldk-java-${JAR_VERSION}.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
-            cd javatester
-            mvn -q -B package
-            java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar
-          fi
+          export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
+          export JAVA_HOME=`pwd`/jdk-18.0.1.1.jdk/Contents/Home
+          export PATH=$JAVA_HOME/bin:$PATH
+          cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/ldk-java.jar" ./
+          mvn install:install-file -Dfile=ldk-java.jar -DgroupId=org.lightningdevkit -DartifactId=ldk-java -Dversion=1.0-SNAPSHOT -Dpackaging=jar
+          cd javatester
+          mvn clean
+          mvn -q -B package
+          java -ea -jar target/ldk-java-tests-1.0-SNAPSHOT-jar-with-dependencies.jar