Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Multi architecture support #10

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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
68 changes: 0 additions & 68 deletions .github/workflows/test-compile.yml

This file was deleted.

22 changes: 20 additions & 2 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
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