From 4d6e08dd56ecc8c0b645bd294554ec9f3bb067b0 Mon Sep 17 00:00:00 2001 From: Tomislav Grospic Date: Sun, 14 Aug 2022 14:18:40 +0200 Subject: [PATCH] [WIP] Multi architecture support --- .github/workflows/compile.yml | 90 ++++++++++++++++++++++++-- .github/workflows/test-compile.yml | 68 ------------------- compile.sh | 22 ++++++- jni/build-aux/m4/ax_jni_include_dir.m4 | 20 +++--- 4 files changed, 117 insertions(+), 83 deletions(-) delete mode 100644 .github/workflows/test-compile.yml diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index d071e76..1af0a43 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -1,18 +1,98 @@ -name: Compile secp256k1 native code +name: Compile secp256k1 native library on: - push: + pull_request: branches: - master + push: + branches: + - trying + - staging jobs: compile: - name: Compile secp256k1 native code + name: Compile secp256k1 strategy: + fail-fast: false matrix: - os: [ubuntu-22.04, macos-11] + include: + # Linux + - name: linux + os: ubuntu-22.04 + arch: amd64 + - name: linux + os: ubuntu-22.04 + arch: aarch64 + # MacOS + - name: macos + os: macos-11 + arch: amd64 + - name: macos + os: macos-11 + arch: aarch64 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Install dependencies ubuntu + if: matrix.name == 'linux' + run: | + uname -a + sudo apt-get update + sudo apt-get install -y build-essential libtool + sudo apt-get install -y gcc-aarch64-linux-gnu + export DEBIAN_FRONTEND=noninteractive + sudo apt-get install -y openjdk-17-jdk-headless + + - name: Install dependencies macos + if: matrix.name == 'macos' + run: | + uname -a + brew install automake libtool + brew install openjdk@17 + sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk + echo 'export PATH="/usr/local/opt/openjdk@17/bin:$PATH"' >> /Users/runner/.bash_profile + export CPPFLAGS="-I/usr/local/opt/openjdk@17/include" + + brew tap messense/macos-cross-toolchains + # install aarch64-unknown-linux-gnu toolchain + brew install aarch64-unknown-linux-gnu + + # brew install aarch64-elf-gcc - # TODO: add release job + # brew tap osx-cross/arm + # brew install arm-gcc-bin + + - name: Build native code + if: matrix.arch == 'amd64' + run: | + ./compile.sh + + - name: Build native code - Linux aarch64 + if: matrix.name == 'linux' && matrix.arch == 'aarch64' + run: | + ./compile.sh aarch64-linux-gnu + + - name: Build native code - MacOS aarch64 + if: matrix.name == 'macos' && matrix.arch == 'aarch64' + run: | + ./compile.sh aarch64-unknown-linux-gnu + + - name: Export artifacts linux + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.name }}-${{ matrix.arch }} + path: ./secp256k1-tmp/.libs/ + + # Job to notify bors when run is successful. Skipped and cancelled job is considered + # as failure. More info https://github.com/bors-ng/bors-ng/issues/1115. + bors_success: + name: bors build finished + if: ${{ success() }} + needs: + - compile + runs-on: ubuntu-latest + steps: + - run: exit 0 diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml deleted file mode 100644 index c7a4429..0000000 --- a/.github/workflows/test-compile.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Test compile secp256k1 native code - -on: - pull_request: - branches: - - master - push: - branches: - - trying - - staging - -jobs: - test-compile: - name: Compile secp256k1 native code - strategy: - matrix: - os: [ubuntu-22.04, macos-11] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Install dependencies ubuntu - if: matrix.os == 'ubuntu-22.04' - run: | - sudo apt-get update - sudo apt-get install -y build-essential libtool - export DEBIAN_FRONTEND=noninteractive - sudo apt-get install -y openjdk-17-jdk-headless - - - name: Install dependencies macos - if: matrix.os == 'macos-11' - run: | - brew install automake libtool - brew install openjdk@17 - sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk - echo 'export PATH="/usr/local/opt/openjdk@17/bin:$PATH"' >> /Users/runner/.bash_profile - export CPPFLAGS="-I/usr/local/opt/openjdk@17/include" - - - name: Build native code - run: | - ./compile.sh - - - name: Export artifacts linux - if: matrix.os == 'ubuntu-22.04' - uses: actions/upload-artifact@v3 - with: - name: linux64 - path: ./secp256k1-tmp/.libs/ - - - name: Export artifacts macos - if: matrix.os == 'macos-11' - uses: actions/upload-artifact@v3 - with: - name: macos64 - path: ./secp256k1-tmp/.libs/ - - # Job to notify bors when run is successful. Skipped and cancelled job is considered - # as failure. More info https://github.com/bors-ng/bors-ng/issues/1115. - bors_success: - name: bors build finished - needs: - - test-compile - if: "github.event_name == 'push' && (github.ref == 'refs/heads/trying' || github.ref == 'refs/heads/staging') && success()" - runs-on: ubuntu-latest - steps: - - run: true diff --git a/compile.sh b/compile.sh index 4d218ac..18dd4fd 100755 --- a/compile.sh +++ b/compile.sh @@ -2,6 +2,12 @@ set -e +# To cross compile to aarch64 use "arm" as a first argument +# Example: +# ./compile.sh arm +ARCH_HOST="$1" +echo "Arch host = '$ARCH_HOST'" + cp -r secp256k1/ secp256k1-tmp/ pushd secp256k1-tmp/ @@ -16,8 +22,20 @@ cp ../jni/configure.ac configure.ac # Compile secp256k1 native code ./autogen.sh -./configure --enable-jni --enable-module-ecdh --enable-experimental --enable-module-schnorrsig --enable-module-ecdsa-adaptor + +if [[ "$ARCH_HOST" ]]; then + echo "Cross compiling for ARM CPU... $ARCH_HOST" + # ./configure --enable-jni --enable-module-ecdh --host=aarch64-linux-gnu + # ./configure --enable-jni --enable-module-ecdh --host=aarch64-linux-gnu --enable-experimental --with-asm=arm + # ./configure --enable-jni --enable-module-ecdh --host=aarch64-linux-gnu --with-asm=no + ./configure --enable-jni --enable-module-ecdh --host=$ARCH_HOST --with-asm=no +else + ./configure --enable-jni --enable-module-ecdh +fi +# ./configure --enable-jni --enable-module-ecdh --enable-experimental --enable-module-schnorrsig # ./configure --enable-jni --enable-module-ecdh make CFLAGS="-std=c99" make -make check +if [[ ! "$ARCH_HOST" ]]; then + make check +fi diff --git a/jni/build-aux/m4/ax_jni_include_dir.m4 b/jni/build-aux/m4/ax_jni_include_dir.m4 index a61d4a1..10f1296 100644 --- a/jni/build-aux/m4/ax_jni_include_dir.m4 +++ b/jni/build-aux/m4/ax_jni_include_dir.m4 @@ -92,22 +92,26 @@ _AS_ECHO_LOG([_JINC=$_JINC]) # -> ../../CurrentJDK/Headers/jni.h. AC_CACHE_CHECK(jni headers, ac_cv_jni_header_path, [ - if test -f "$_JINC/jni.h"; then + if test -f "/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/include/jni.h"; then + ac_cv_jni_header_path="/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/include \ + /Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/include/darwin" + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path" + elif test -f "$_JINC/jni.h"; then + echo _JINC/jni.h: "$_JINC/jni.h" + ac_cv_jni_header_path="$_JINC" JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path" else _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'` if test -f "$_JTOPDIR/include/jni.h"; then + echo _JTOPDIR/include/jni.h: "$_JTOPDIR/include/jni.h" + ac_cv_jni_header_path="$_JTOPDIR/include" JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path" + + echo JNI_INCLUDE_DIRS: "$JNI_INCLUDE_DIRS" else - if test -f "/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/include/jni.h"; then - ac_cv_jni_header_path="/Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/include \ - /Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/include/darwin" - JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $ac_cv_jni_header_path" - else - ac_cv_jni_header_path=none - fi + ac_cv_jni_header_path=none fi fi ])