Skip to content

Commit 964ae2f

Browse files
committed
Build a universal JNI binary for macos
Universal libraries embed both arm64 and x64 binaries.
1 parent d30e2a1 commit 964ae2f

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ buildscript {
2222

2323
allprojects {
2424
group = "fr.acinq.secp256k1"
25-
version = "0.15.0"
25+
version = "0.16.0-SNAPSHOT"
2626

2727
repositories {
2828
google()

jni/jvm/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if [ "$TARGET" == "linux" ]; then
1717
CC_OPTS="-fPIC"
1818
elif [ "$TARGET" == "darwin" ]; then
1919
OUTFILE=libsecp256k1-jni.dylib
20+
CC_OPTS="-arch arm64 -arch x86_64"
2021
elif [ "$TARGET" == "mingw" ]; then
2122
OUTFILE=secp256k1-jni.dll
2223
CC=x86_64-w64-mingw32-gcc

jni/jvm/darwin/build.gradle.kts

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ dependencies {
1212
val copyJni by tasks.creating(Sync::class) {
1313
onlyIf { org.gradle.internal.os.OperatingSystem.current().isMacOsX }
1414
dependsOn(":jni:jvm:buildNativeHost")
15-
val arch = when (System.getProperty("os.arch")) {
16-
"aarch64" -> "aarch64"
17-
else -> "x86_64"
18-
}
1915
from(rootDir.resolve("jni/jvm/build/darwin/libsecp256k1-jni.dylib"))
20-
into(buildDir.resolve("jniResources/fr/acinq/secp256k1/jni/native/darwin-$arch"))
16+
into(buildDir.resolve("jniResources/fr/acinq/secp256k1/jni/native/darwin"))
2117
}
2218

2319
(tasks["processResources"] as ProcessResources).apply {

jni/jvm/src/main/kotlin/fr/acinq/secp256k1/jni/OSInfo.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ internal object OSInfo {
1919
private const val PPC = "ppc"
2020
private const val PPC64 = "ppc64"
2121

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

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

native/build.sh

+6-8
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ cd "$(dirname "$0")"
1212
cd secp256k1
1313

1414
if [ "$TARGET" == "mingw" ]; then
15-
CONF_OPTS="CFLAGS=-fPIC --host=x86_64-w64-mingw32"
15+
CFLAGS="-fPIC"
16+
CONF_OPTS=" --host=x86_64-w64-mingw32"
1617
elif [ "$TARGET" == "linux" ]; then
17-
CONF_OPTS="CFLAGS=-fPIC"
18+
CFLAGS="-fPIC"
1819
elif [ "$TARGET" == "darwin" ]; then
19-
CONF_OPTS=""
20+
CFLAGS="-arch arm64 -arch x86_64"
21+
LDFLAGS="-arch arm64 -arch x86_64"
2022
else
2123
echo "Unknown TARGET=$TARGET"
2224
exit 1
2325
fi
2426

2527
./autogen.sh
26-
if [ "$TARGET" == "darwin" ]; then
27-
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
28-
else
29-
./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
30-
fi
28+
CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" ./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
3129
make clean
3230
make
3331

0 commit comments

Comments
 (0)