Skip to content

Commit

Permalink
Build a universal JNI binary for macos
Browse files Browse the repository at this point in the history
Universal libraries embed both arm64 and x64 binaries.
  • Loading branch information
sstone committed Mar 4, 2024
1 parent d30e2a1 commit 0391564
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {

allprojects {
group = "fr.acinq.secp256k1"
version = "0.15.0"
version = "0.16.0-SNAPSHOT"

repositories {
google()
Expand Down
6 changes: 1 addition & 5 deletions jni/jvm/darwin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ dependencies {
val copyJni by tasks.creating(Sync::class) {
onlyIf { org.gradle.internal.os.OperatingSystem.current().isMacOsX }
dependsOn(":jni:jvm:buildNativeHost")
val arch = when (System.getProperty("os.arch")) {
"aarch64" -> "aarch64"
else -> "x86_64"
}
from(rootDir.resolve("jni/jvm/build/darwin/libsecp256k1-jni.dylib"))
into(buildDir.resolve("jniResources/fr/acinq/secp256k1/jni/native/darwin-$arch"))
into(buildDir.resolve("jniResources/fr/acinq/secp256k1/jni/native/darwin"))
}

(tasks["processResources"] as ProcessResources).apply {
Expand Down
3 changes: 2 additions & 1 deletion jni/jvm/src/main/kotlin/fr/acinq/secp256k1/jni/OSInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ internal object OSInfo {
private const val PPC = "ppc"
private const val PPC64 = "ppc64"

@JvmStatic val nativeSuffix: String get() = "$os-$arch"
// on macos we build a universal library that contains arm64 and x64 binaries
@JvmStatic val nativeSuffix: String get() = if (os == "darwin") os else "$os-$arch"

@JvmStatic val os: String get() = translateOSName(System.getProperty("os.name"))

Expand Down
13 changes: 5 additions & 8 deletions native/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ cd "$(dirname "$0")"
cd secp256k1

if [ "$TARGET" == "mingw" ]; then
CONF_OPTS="CFLAGS=-fPIC --host=x86_64-w64-mingw32"
CFLAGS="-fPIC"
CONF_OPTS=" --host=x86_64-w64-mingw32"
elif [ "$TARGET" == "linux" ]; then
CONF_OPTS="CFLAGS=-fPIC"
CFLAGS="-fPIC"
elif [ "$TARGET" == "darwin" ]; then
CONF_OPTS=""
CFLAGS="-arch arm64 -arch x86_64"
else
echo "Unknown TARGET=$TARGET"
exit 1
fi

./autogen.sh
if [ "$TARGET" == "darwin" ]; then
CFLAGS="-arch arm64 -arch x86_64" ./configure $CONF_OPTS --enable-experimental --enable-module_ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-musig --enable-benchmark=no --enable-shared=no --enable-exhaustive-tests=no --enable-tests=no
else
./configure $CONF_OPTS --enable-experimental --enable-module_ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-musig --enable-benchmark=no --enable-shared=no --enable-exhaustive-tests=no --enable-tests=no
fi
CFLAGS="$CFLAGS" ./configure $CONF_OPTS --enable-experimental --enable-module_ecdh --enable-module-recovery --enable-module-schnorrsig --enable-module-musig --enable-benchmark=no --enable-shared=no --enable-exhaustive-tests=no --enable-tests=no
make clean
make

Expand Down

0 comments on commit 0391564

Please sign in to comment.