2020-06-26 13:48:50 +02:00
|
|
|
plugins {
|
|
|
|
kotlin("multiplatform") version "1.4-M2-mt"
|
2020-06-26 20:50:32 +02:00
|
|
|
id("com.android.library") version "4.0.0"
|
2020-06-26 13:48:50 +02:00
|
|
|
}
|
|
|
|
group = "fr.acinq.phoenix"
|
|
|
|
version = "1.0-1.4-M2"
|
|
|
|
|
|
|
|
repositories {
|
|
|
|
jcenter()
|
2020-06-26 20:50:32 +02:00
|
|
|
google()
|
2020-06-26 13:48:50 +02:00
|
|
|
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
|
|
|
|
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
|
|
|
}
|
|
|
|
|
|
|
|
val currentOs = org.gradle.internal.os.OperatingSystem.current()
|
|
|
|
|
|
|
|
kotlin {
|
|
|
|
explicitApi()
|
|
|
|
|
2020-06-26 17:10:48 +02:00
|
|
|
val commonMain by sourceSets.getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("stdlib-common"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val commonTest by sourceSets.getting {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test-common"))
|
|
|
|
implementation(kotlin("test-annotations-common"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 20:50:32 +02:00
|
|
|
val jvmAndAndroidMain by sourceSets.creating {
|
|
|
|
dependsOn(commonMain)
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("stdlib-jdk8"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 13:48:50 +02:00
|
|
|
jvm {
|
|
|
|
compilations.all {
|
|
|
|
kotlinOptions.jvmTarget = "1.8"
|
|
|
|
}
|
2020-06-26 17:10:48 +02:00
|
|
|
(tasks[compilations["main"].processResourcesTaskName] as ProcessResources).apply{
|
|
|
|
dependsOn("copyJni")
|
|
|
|
from(buildDir.resolve("jniResources"))
|
2020-06-26 13:48:50 +02:00
|
|
|
}
|
2020-06-26 20:50:32 +02:00
|
|
|
compilations["main"].defaultSourceSet.dependsOn(jvmAndAndroidMain)
|
2020-06-26 17:10:48 +02:00
|
|
|
compilations["test"].dependencies {
|
|
|
|
implementation(kotlin("test-junit"))
|
2020-06-26 13:48:50 +02:00
|
|
|
}
|
2020-06-26 17:10:48 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:50:32 +02:00
|
|
|
android {
|
|
|
|
compilations.all {
|
|
|
|
kotlinOptions.jvmTarget = "1.8"
|
|
|
|
}
|
|
|
|
sourceSets["androidMain"].dependsOn(jvmAndAndroidMain)
|
|
|
|
sourceSets["androidTest"].dependencies {
|
|
|
|
implementation(kotlin("test-junit"))
|
|
|
|
implementation("androidx.test.ext:junit:1.1.1")
|
|
|
|
implementation("androidx.test.espresso:espresso-core:3.2.0")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:10:48 +02:00
|
|
|
fun org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.secp256k1CInterop() {
|
|
|
|
compilations["main"].cinterops {
|
|
|
|
val libsecp256k1 by creating {
|
|
|
|
includeDirs.headerFilterOnly(project.file("native/secp256k1/include/"))
|
|
|
|
// includeDirs("/usr/local/lib")
|
|
|
|
tasks[interopProcessingTaskName].dependsOn("buildSecp256k1Ios")
|
2020-06-26 13:48:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-26 17:10:48 +02:00
|
|
|
|
|
|
|
val nativeMain by sourceSets.creating { dependsOn(commonMain) }
|
|
|
|
|
|
|
|
linuxX64 {
|
|
|
|
secp256k1CInterop()
|
|
|
|
// https://youtrack.jetbrains.com/issue/KT-39396
|
|
|
|
compilations["main"].kotlinOptions.freeCompilerArgs += listOf("-include-binary", "$rootDir/native/build/linux/libsecp256k1.a")
|
|
|
|
compilations["main"].defaultSourceSet.dependsOn(nativeMain)
|
|
|
|
}
|
|
|
|
|
|
|
|
ios {
|
|
|
|
secp256k1CInterop()
|
|
|
|
// https://youtrack.jetbrains.com/issue/KT-39396
|
|
|
|
compilations["main"].kotlinOptions.freeCompilerArgs += listOf("-include-binary", "$rootDir/native/build/ios/libsecp256k1.a")
|
|
|
|
compilations["main"].defaultSourceSet.dependsOn(nativeMain)
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets.all {
|
|
|
|
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
|
|
|
|
}
|
|
|
|
|
2020-06-26 13:48:50 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:50:32 +02:00
|
|
|
android {
|
|
|
|
defaultConfig {
|
|
|
|
compileSdkVersion(30)
|
|
|
|
minSdkVersion(21)
|
|
|
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
|
|
externalNativeBuild {
|
|
|
|
cmake {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
externalNativeBuild {
|
|
|
|
cmake {
|
|
|
|
setPath("src/androidMain/CMakeLists.txt")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ndkVersion = "21.3.6528147"
|
|
|
|
|
|
|
|
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
|
|
|
|
}
|
|
|
|
|
2020-06-26 13:48:50 +02:00
|
|
|
val buildSecp256k1 by tasks.creating { group = "build" }
|
2020-06-26 17:10:48 +02:00
|
|
|
fun creatingBuildSecp256k1(target: String, cross: String? = null, env: String = "", configuration: Task.() -> Unit = {}) = tasks.creating(Exec::class) {
|
2020-06-26 13:48:50 +02:00
|
|
|
group = "build"
|
|
|
|
buildSecp256k1.dependsOn(this)
|
|
|
|
|
|
|
|
inputs.files(projectDir.resolve("native/build.sh"))
|
|
|
|
outputs.dir(projectDir.resolve("native/build/$target"))
|
|
|
|
|
2020-06-26 17:10:48 +02:00
|
|
|
workingDir = projectDir.resolve("native")
|
|
|
|
environment("TARGET", target)
|
|
|
|
if (cross == null) commandLine("./build.sh")
|
|
|
|
else commandLine("./dockcross-$cross", "bash", "-c", "TARGET=$target ./build.sh")
|
2020-06-26 13:48:50 +02:00
|
|
|
|
|
|
|
configuration()
|
|
|
|
}
|
|
|
|
|
|
|
|
val buildSecp256k1Darwin by creatingBuildSecp256k1("darwin")
|
|
|
|
val buildSecp256k1Linux by creatingBuildSecp256k1("linux", cross = if (currentOs.isMacOsX) "linux-x64" else null)
|
|
|
|
val buildSecp256k1Mingw by creatingBuildSecp256k1("mingw", cross = "windows-x64", env = "CONF_OPTS=--host=x86_64-w64-mingw32")
|
|
|
|
|
2020-06-26 20:50:32 +02:00
|
|
|
val copyJni by tasks.creating(Sync::class) {
|
|
|
|
dependsOn(buildSecp256k1)
|
|
|
|
from(projectDir.resolve("native/build/linux/libsecp256k1-jni.so")) { rename { "libsecp256k1-jni-linux-x86_64.so" } }
|
|
|
|
from(projectDir.resolve("native/build/darwin/libsecp256k1-jni.dylib")) { rename { "libsecp256k1-jni-darwin-x86_64.dylib" } }
|
|
|
|
from(projectDir.resolve("native/build/mingw/secp256k1-jni.dll")) { rename { "secp256k1-jni-mingw-x86_64.dll" } }
|
|
|
|
into(buildDir.resolve("jniResources/fr/acinq/secp256k1/native"))
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:10:48 +02:00
|
|
|
val buildSecp256k1Ios by tasks.creating(Exec::class) {
|
|
|
|
group = "build"
|
|
|
|
buildSecp256k1.dependsOn(this)
|
|
|
|
|
|
|
|
inputs.files(projectDir.resolve("native/build-ios.sh"))
|
|
|
|
outputs.dir(projectDir.resolve("native/build/ios"))
|
|
|
|
|
|
|
|
workingDir = projectDir.resolve("native")
|
|
|
|
commandLine("./build-ios.sh")
|
|
|
|
}
|
|
|
|
|
2020-06-26 20:50:32 +02:00
|
|
|
val buildSecp256k1Android by tasks.creating { group = "build" }
|
|
|
|
fun creatingBuildSecp256k1Android(arch: String) = tasks.creating(Exec::class) {
|
|
|
|
group = "build"
|
|
|
|
buildSecp256k1Android.dependsOn(this)
|
|
|
|
|
|
|
|
inputs.files(projectDir.resolve("native/build-android.sh"))
|
|
|
|
outputs.dir(projectDir.resolve("native/build/android/$arch"))
|
|
|
|
|
|
|
|
workingDir = projectDir.resolve("native")
|
|
|
|
|
|
|
|
val toolchain = when {
|
|
|
|
currentOs.isMacOsX -> "darwin-x86_64"
|
|
|
|
else -> error("Cannot build for Android on this OS")
|
|
|
|
}
|
|
|
|
environment("TOOLCHAIN", toolchain)
|
|
|
|
environment("ARCH", arch)
|
|
|
|
environment("ANDROID_NDK", android.ndkDirectory)
|
|
|
|
commandLine("./build-android.sh")
|
2020-06-26 13:48:50 +02:00
|
|
|
}
|
2020-06-26 20:50:32 +02:00
|
|
|
val buildSecp256k1AndroidX86_64 by creatingBuildSecp256k1Android("x86_64")
|
|
|
|
val buildSecp256k1AndroidX86 by creatingBuildSecp256k1Android("x86")
|
|
|
|
val buildSecp256k1AndroidArm64v8a by creatingBuildSecp256k1Android("arm64-v8a")
|
|
|
|
val buildSecp256k1AndroidArmeabiv7a by creatingBuildSecp256k1Android("armeabi-v7a")
|
|
|
|
|
|
|
|
afterEvaluate {
|
|
|
|
configure(listOf("Debug", "Release").map { tasks["externalNativeBuild$it"] }) {
|
|
|
|
dependsOn(buildSecp256k1Android)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks["clean"].doLast {
|
|
|
|
delete(projectDir.resolve("native/build"))
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEvaluate {
|
|
|
|
tasks.withType<com.android.build.gradle.tasks.factory.AndroidUnitTest>().all {
|
|
|
|
enabled = false
|
|
|
|
}
|
|
|
|
}
|