Skip to content

Commit

Permalink
[WIP] Multi architecture support
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrospic committed Aug 15, 2022
1 parent b6e85f1 commit 9a213a1
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 83 deletions.
90 changes: 85 additions & 5 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
@@ -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.os == 'linux') && (matrix.arch == 'aarch64')
run: |
./compile.sh aarch64-linux-gnu
- name: Build native code - MacOS aarch64
if: ${{ (matrix.os == '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
68 changes: 0 additions & 68 deletions .github/workflows/test-compile.yml

This file was deleted.

21 changes: 19 additions & 2 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

# To cross compile to aarch64 use "arm" as a first argument
# Example:
# ./compile.sh arm
ARCH_HOST="$1"

cp -r secp256k1/ secp256k1-tmp/

pushd secp256k1-tmp/
Expand All @@ -16,8 +21,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..."
# ./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
20 changes: 12 additions & 8 deletions jni/build-aux/m4/ax_jni_include_dir.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
Expand Down

0 comments on commit 9a213a1

Please sign in to comment.