Compat with linux host
This commit is contained in:
parent
ff37b86ff3
commit
548fb27c33
@ -115,7 +115,23 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val buildSecp256k1 by tasks.creating { group = "build" }
|
val buildSecp256k1 by tasks.creating { group = "build" }
|
||||||
fun creatingBuildSecp256k1(target: String, cross: String? = null, env: String = "", configuration: Task.() -> Unit = {}) = tasks.creating(Exec::class) {
|
sealed class Cross {
|
||||||
|
abstract fun cmd(target: String, nativeDir: File): List<String>
|
||||||
|
class DockCross(val cross: String) : Cross() {
|
||||||
|
override fun cmd(target: String, nativeDir: File): List<String> = listOf("./dockcross-$cross", "bash", "-c", "TARGET=$target ./build.sh")
|
||||||
|
}
|
||||||
|
class MultiArch(val crossTriple: String) : Cross() {
|
||||||
|
override fun cmd(target: String, nativeDir: File): List<String> {
|
||||||
|
val uid = Runtime.getRuntime().exec("id -u").inputStream.use { it.reader().readText() }.trim().toInt()
|
||||||
|
return listOf(
|
||||||
|
"docker", "run", "--rm", "-v", "${nativeDir.absolutePath}:/workdir",
|
||||||
|
"-e", "CROSS_TRIPLE=$crossTriple", "-e", "TARGET=$target", "-e", "TO_UID=$uid",
|
||||||
|
"multiarch/crossbuild", "./build.sh"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun creatingBuildSecp256k1(target: String, cross: Cross?) = tasks.creating(Exec::class) {
|
||||||
group = "build"
|
group = "build"
|
||||||
buildSecp256k1.dependsOn(this)
|
buildSecp256k1.dependsOn(this)
|
||||||
|
|
||||||
@ -124,15 +140,11 @@ fun creatingBuildSecp256k1(target: String, cross: String? = null, env: String =
|
|||||||
|
|
||||||
workingDir = projectDir.resolve("native")
|
workingDir = projectDir.resolve("native")
|
||||||
environment("TARGET", target)
|
environment("TARGET", target)
|
||||||
if (cross == null) commandLine("./build.sh")
|
commandLine((cross?.cmd(target, workingDir) ?: emptyList()) + "./build.sh")
|
||||||
else commandLine("./dockcross-$cross", "bash", "-c", "TARGET=$target ./build.sh")
|
|
||||||
|
|
||||||
configuration()
|
|
||||||
}
|
}
|
||||||
|
val buildSecp256k1Darwin by creatingBuildSecp256k1("darwin", if (currentOs.isMacOsX) null else Cross.MultiArch("x86_64-apple-darwin"))
|
||||||
val buildSecp256k1Darwin by creatingBuildSecp256k1("darwin")
|
val buildSecp256k1Linux by creatingBuildSecp256k1("linux", if (currentOs.isLinux) null else Cross.DockCross("linux-x64"))
|
||||||
val buildSecp256k1Linux by creatingBuildSecp256k1("linux", cross = if (currentOs.isMacOsX) "linux-x64" else null)
|
val buildSecp256k1Mingw by creatingBuildSecp256k1("mingw", if (currentOs.isWindows) null else Cross.DockCross("windows-x64"))
|
||||||
val buildSecp256k1Mingw by creatingBuildSecp256k1("mingw", cross = "windows-x64", env = "CONF_OPTS=--host=x86_64-w64-mingw32")
|
|
||||||
|
|
||||||
val copyJni by tasks.creating(Sync::class) {
|
val copyJni by tasks.creating(Sync::class) {
|
||||||
dependsOn(buildSecp256k1)
|
dependsOn(buildSecp256k1)
|
||||||
@ -146,6 +158,8 @@ val buildSecp256k1Ios by tasks.creating(Exec::class) {
|
|||||||
group = "build"
|
group = "build"
|
||||||
buildSecp256k1.dependsOn(this)
|
buildSecp256k1.dependsOn(this)
|
||||||
|
|
||||||
|
onlyIf { currentOs.isMacOsX }
|
||||||
|
|
||||||
inputs.files(projectDir.resolve("native/build-ios.sh"))
|
inputs.files(projectDir.resolve("native/build-ios.sh"))
|
||||||
outputs.dir(projectDir.resolve("native/build/ios"))
|
outputs.dir(projectDir.resolve("native/build/ios"))
|
||||||
|
|
||||||
@ -153,7 +167,10 @@ val buildSecp256k1Ios by tasks.creating(Exec::class) {
|
|||||||
commandLine("./build-ios.sh")
|
commandLine("./build-ios.sh")
|
||||||
}
|
}
|
||||||
|
|
||||||
val buildSecp256k1Android by tasks.creating { group = "build" }
|
val buildSecp256k1Android by tasks.creating {
|
||||||
|
group = "build"
|
||||||
|
buildSecp256k1.dependsOn(this)
|
||||||
|
}
|
||||||
fun creatingBuildSecp256k1Android(arch: String) = tasks.creating(Exec::class) {
|
fun creatingBuildSecp256k1Android(arch: String) = tasks.creating(Exec::class) {
|
||||||
group = "build"
|
group = "build"
|
||||||
buildSecp256k1Android.dependsOn(this)
|
buildSecp256k1Android.dependsOn(this)
|
||||||
@ -164,8 +181,10 @@ fun creatingBuildSecp256k1Android(arch: String) = tasks.creating(Exec::class) {
|
|||||||
workingDir = projectDir.resolve("native")
|
workingDir = projectDir.resolve("native")
|
||||||
|
|
||||||
val toolchain = when {
|
val toolchain = when {
|
||||||
|
currentOs.isLinux -> "linux-x86_64"
|
||||||
currentOs.isMacOsX -> "darwin-x86_64"
|
currentOs.isMacOsX -> "darwin-x86_64"
|
||||||
else -> error("Cannot build for Android on this OS")
|
currentOs.isWindows -> "windows-x86_64"
|
||||||
|
else -> error("No Android toolchain defined for this OS: $currentOs")
|
||||||
}
|
}
|
||||||
environment("TOOLCHAIN", toolchain)
|
environment("TOOLCHAIN", toolchain)
|
||||||
environment("ARCH", arch)
|
environment("ARCH", arch)
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
ANDROID_NDK=/Users/salomonbrys/Library/Android/sdk/ndk/21.3.6528147
|
|
||||||
TOOLCHAIN=darwin-x86_64
|
|
||||||
|
|
||||||
[[ -z "$ANDROID_NDK" ]] && echo "Please set the ANDROID_NDK variable" && exit 1
|
[[ -z "$ANDROID_NDK" ]] && echo "Please set the ANDROID_NDK variable" && exit 1
|
||||||
[[ -z "$ARCH" ]] && echo "Please set the ARCH variable" && exit 1
|
[[ -z "$ARCH" ]] && echo "Please set the ARCH variable" && exit 1
|
||||||
[[ -z "$TOOLCHAIN" ]] && echo "Please set the TOOLCHAIN variable" && exit 1
|
[[ -z "$TOOLCHAIN" ]] && echo "Please set the TOOLCHAIN variable" && exit 1
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
[[ -z "$TARGET" ]] && echo "Please set the PLATFORM variable" && exit 1
|
[[ -z "$TARGET" ]] && echo "Please set the TARGET variable" && exit 1
|
||||||
|
|
||||||
|
if [ "$(id -u)" == "0" ]; then
|
||||||
|
[[ -z "$TO_UID" ]] && echo "Please set the TO_UID variable" && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cd secp256k1
|
cd secp256k1
|
||||||
|
|
||||||
@ -9,6 +13,8 @@ if [ "$TARGET" == "mingw" ]; then
|
|||||||
CONF_OPTS="CFLAGS=-fpic --host=x86_64-w64-mingw32"
|
CONF_OPTS="CFLAGS=-fpic --host=x86_64-w64-mingw32"
|
||||||
elif [ "$TARGET" == "linux" ]; then
|
elif [ "$TARGET" == "linux" ]; then
|
||||||
CONF_OPTS="CFLAGS=-fpic"
|
CONF_OPTS="CFLAGS=-fpic"
|
||||||
|
elif [ "$TARGET" == "darwin" ]; then
|
||||||
|
CONF_OPTS="--host=x86_64-w64-darwin"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
@ -16,19 +22,26 @@ fi
|
|||||||
make clean
|
make clean
|
||||||
make
|
make
|
||||||
|
|
||||||
|
[[ ! -z "$TO_UID" ]] && chown -R $TO_UID:$TO_UID .
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
mkdir -p build/$TARGET
|
mkdir -p build/$TARGET
|
||||||
cp -v secp256k1/.libs/libsecp256k1.a build/$TARGET/
|
cp -v secp256k1/.libs/libsecp256k1.a build/$TARGET/
|
||||||
|
|
||||||
|
[[ ! -z "$TO_UID" ]] && chown -R $TO_UID:$TO_UID build
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
JNI_HEADERS=$TARGET
|
JNI_HEADERS=$TARGET
|
||||||
|
|
||||||
if [ "$TARGET" == "linux" ]; then
|
if [ "$TARGET" == "linux" ]; then
|
||||||
OUTFILE=libsecp256k1-jni.so
|
OUTFILE=libsecp256k1-jni.so
|
||||||
|
ADD_LIB=-lgmp
|
||||||
elif [ "$TARGET" == "darwin" ]; then
|
elif [ "$TARGET" == "darwin" ]; then
|
||||||
OUTFILE=libsecp256k1-jni.dylib
|
OUTFILE=libsecp256k1-jni.dylib
|
||||||
ADD_LIB=-lgmp
|
if [ -z "$CROSS_TRIPLE" ]; then
|
||||||
|
ADD_LIB=-lgmp
|
||||||
|
fi
|
||||||
elif [ "$TARGET" == "mingw" ]; then
|
elif [ "$TARGET" == "mingw" ]; then
|
||||||
OUTFILE=secp256k1-jni.dll
|
OUTFILE=secp256k1-jni.dll
|
||||||
CC=/usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-gcc
|
CC=/usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-gcc
|
||||||
@ -37,3 +50,7 @@ elif [ "$TARGET" == "mingw" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
$CC -shared $CC_OPTS -o build/$TARGET/$OUTFILE jni/src/org_bitcoin_NativeSecp256k1.c jni/src/org_bitcoin_Secp256k1Context.c -Ijni/headers/ -Ijni/headers/$JNI_HEADERS/ -Isecp256k1/ -lsecp256k1 -Lbuild/$TARGET/ $ADD_LIB
|
$CC -shared $CC_OPTS -o build/$TARGET/$OUTFILE jni/src/org_bitcoin_NativeSecp256k1.c jni/src/org_bitcoin_Secp256k1Context.c -Ijni/headers/ -Ijni/headers/$JNI_HEADERS/ -Isecp256k1/ -lsecp256k1 -Lbuild/$TARGET/ $ADD_LIB
|
||||||
|
|
||||||
|
[[ ! -z "$TO_UID" ]] && chown -R $TO_UID:$TO_UID build
|
||||||
|
|
||||||
|
echo "Build done for $TARGET"
|
||||||
|
@ -5,7 +5,7 @@ headerFilter = secp256k1/** secp256k1_ecdh.h secp256k1_recovery.h secp256k1.h
|
|||||||
|
|
||||||
staticLibraries.linux = libsecp256k1.a
|
staticLibraries.linux = libsecp256k1.a
|
||||||
libraryPaths.linux = c/secp256k1/build/linux/
|
libraryPaths.linux = c/secp256k1/build/linux/
|
||||||
linkerOpts.linux = -L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib
|
linkerOpts.linux = -L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -lgmp
|
||||||
|
|
||||||
staticLibraries.ios = libsecp256k1.a
|
staticLibraries.ios = libsecp256k1.a
|
||||||
libraryPaths.ios = c/secp256k1/build/ios/ /usr/local/lib
|
libraryPaths.ios = c/secp256k1/build/ios/ /usr/local/lib
|
||||||
|
Loading…
x
Reference in New Issue
Block a user