2024-03-20 16:01:45 +01:00
|
|
|
import Versions.ktor
|
2024-03-08 18:44:24 +01:00
|
|
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
|
2024-03-20 16:01:45 +01:00
|
|
|
import java.io.ByteArrayOutputStream
|
2024-03-08 18:44:24 +01:00
|
|
|
|
|
|
|
buildscript {
|
|
|
|
dependencies {
|
2024-03-20 16:01:45 +01:00
|
|
|
classpath("app.cash.sqldelight:gradle-plugin:${Versions.sqlDelight}")
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
repositories {
|
|
|
|
google()
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins {
|
2024-03-20 16:01:45 +01:00
|
|
|
kotlin("multiplatform") version Versions.kotlin
|
|
|
|
kotlin("plugin.serialization") version Versions.kotlin
|
|
|
|
id("app.cash.sqldelight") version Versions.sqlDelight
|
2024-03-25 17:52:09 +01:00
|
|
|
application
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
|
|
|
group = "fr.acinq.lightning"
|
2024-07-03 16:04:32 +02:00
|
|
|
version = "0.2.1-SNAPSHOT"
|
2024-03-08 18:44:24 +01:00
|
|
|
|
|
|
|
repositories {
|
|
|
|
// using the local maven repository with Kotlin Multi Platform can lead to build errors that are hard to diagnose.
|
|
|
|
// uncomment this only if you need to experiment with snapshot dependencies that have not yet be published.
|
|
|
|
mavenLocal()
|
|
|
|
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
|
|
|
mavenCentral()
|
|
|
|
google()
|
2024-08-14 21:44:24 +02:00
|
|
|
maven("https://jitpack.io")
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 16:01:45 +01:00
|
|
|
/** Get the current git commit hash. */
|
|
|
|
fun gitCommitHash(): String {
|
|
|
|
val stream = ByteArrayOutputStream()
|
|
|
|
project.exec {
|
|
|
|
commandLine = "git rev-parse --verify --long HEAD".split(" ")
|
|
|
|
standardOutput = stream
|
|
|
|
}
|
|
|
|
return String(stream.toByteArray()).split("\n").first()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a `BuildVersions` file in build/generated-src containing the current git commit and the lightning-kmp version.
|
|
|
|
* See https://stackoverflow.com/a/74771876 for details.
|
|
|
|
*/
|
|
|
|
val buildVersionsTask by tasks.registering(Sync::class) {
|
|
|
|
group = "build"
|
|
|
|
from(
|
|
|
|
resources.text.fromString(
|
|
|
|
"""
|
|
|
|
|package fr.acinq.lightning
|
|
|
|
|
|
|
|
|
|object BuildVersions {
|
|
|
|
| const val phoenixdCommit = "${gitCommitHash()}"
|
|
|
|
| const val phoenixdVersion = "${project.version}-${gitCommitHash().take(7)}"
|
|
|
|
| const val lightningKmpVersion = "${Versions.lightningKmp}"
|
|
|
|
|}
|
|
|
|
|
|
|
|
|
""".trimMargin()
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
rename { "BuildVersions.kt" }
|
|
|
|
into("fr/acinq/lightning")
|
|
|
|
}
|
|
|
|
into(layout.buildDirectory.dir("generated/kotlin/"))
|
|
|
|
}
|
|
|
|
|
2024-03-08 18:44:24 +01:00
|
|
|
kotlin {
|
2024-03-25 17:52:09 +01:00
|
|
|
jvm {
|
|
|
|
withJava()
|
2024-08-16 01:52:25 +02:00
|
|
|
compilations["main"].defaultSourceSet {
|
|
|
|
resources.srcDirs("src/jvmMain/kotlin/fr/acinq/lightning/vsock/")
|
|
|
|
}
|
2024-03-25 17:52:09 +01:00
|
|
|
}
|
2024-03-08 18:44:24 +01:00
|
|
|
|
|
|
|
fun KotlinNativeTargetWithHostTests.phoenixBinaries() {
|
|
|
|
binaries {
|
|
|
|
executable("phoenixd") {
|
|
|
|
entryPoint = "fr.acinq.lightning.bin.main"
|
|
|
|
optimized = false // without this, release mode throws 'Index 0 out of bounds for length 0' in StaticInitializersOptimization.kt
|
|
|
|
}
|
2024-08-16 01:52:25 +02:00
|
|
|
/*executable("phoenix-cli") {
|
2024-03-08 18:44:24 +01:00
|
|
|
entryPoint = "fr.acinq.lightning.cli.main"
|
|
|
|
optimized = false // without this, release mode throws 'Index 0 out of bounds for length 0' in StaticInitializersOptimization.kt
|
2024-08-16 01:52:25 +02:00
|
|
|
}*/
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val currentOs = org.gradle.internal.os.OperatingSystem.current()
|
2024-03-28 14:23:05 +01:00
|
|
|
val arch = System.getProperty("os.arch")
|
|
|
|
|
|
|
|
if (currentOs.isLinux && arch != "aarch64") {
|
|
|
|
// there is no kotlin native toolchain for linux arm64 yet, but we can still build for the JVM
|
|
|
|
// see https://youtrack.jetbrains.com/issue/KT-51794/Cant-run-JVM-targets-on-ARM-Linux-when-using-Kotlin-Multiplatform-plugin
|
2024-03-08 18:44:24 +01:00
|
|
|
linuxX64 {
|
|
|
|
phoenixBinaries()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentOs.isMacOsX) {
|
|
|
|
macosX64 {
|
|
|
|
phoenixBinaries()
|
|
|
|
}
|
2024-03-20 16:52:50 +01:00
|
|
|
macosArm64 {
|
|
|
|
phoenixBinaries()
|
|
|
|
}
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets {
|
|
|
|
commonMain {
|
2024-03-20 16:01:45 +01:00
|
|
|
kotlin.srcDir(buildVersionsTask.map { it.destinationDir })
|
2024-03-08 18:44:24 +01:00
|
|
|
dependencies {
|
2024-08-14 21:44:24 +02:00
|
|
|
implementation("com.github.raymond98.lightning-kmp:lightning-kmp:v1.6.2-FEECREDIT-8")
|
|
|
|
|
2024-08-16 01:52:25 +02:00
|
|
|
implementation("org.jetbrains.kotlinx:atomicfu:0.25.0")
|
2024-08-14 21:44:24 +02:00
|
|
|
|
2024-08-16 01:52:25 +02:00
|
|
|
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.20")
|
2024-08-14 21:44:24 +02:00
|
|
|
api("fr.acinq.bitcoin:bitcoin-kmp:${Versions.bitcoinKmpVersion}")
|
|
|
|
api("co.touchlab:kermit:${Versions.kermitLoggerVersion}")
|
|
|
|
api("org.jetbrains.kotlinx:kotlinx-datetime:${Versions.datetimeVersion}")
|
|
|
|
api(ktor("network"))
|
|
|
|
api(ktor("network-tls"))
|
|
|
|
|
2024-03-08 18:44:24 +01:00
|
|
|
// ktor serialization
|
|
|
|
implementation(ktor("serialization-kotlinx-json"))
|
|
|
|
// ktor server
|
|
|
|
implementation(ktor("server-core"))
|
|
|
|
implementation(ktor("server-content-negotiation"))
|
|
|
|
implementation(ktor("server-cio"))
|
|
|
|
implementation(ktor("server-websockets"))
|
|
|
|
implementation(ktor("server-auth"))
|
|
|
|
implementation(ktor("server-status-pages")) // exception handling
|
|
|
|
// ktor client (needed for webhook)
|
|
|
|
implementation(ktor("client-core"))
|
|
|
|
implementation(ktor("client-content-negotiation"))
|
|
|
|
implementation(ktor("client-auth"))
|
|
|
|
implementation(ktor("client-json"))
|
|
|
|
|
2024-03-20 16:01:45 +01:00
|
|
|
implementation("com.squareup.okio:okio:${Versions.okio}")
|
|
|
|
implementation("com.github.ajalt.clikt:clikt:${Versions.clikt}")
|
|
|
|
implementation("app.cash.sqldelight:coroutines-extensions:${Versions.sqlDelight}")
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
jvmMain {
|
|
|
|
dependencies {
|
2024-03-20 16:01:45 +01:00
|
|
|
implementation("app.cash.sqldelight:sqlite-driver:${Versions.sqlDelight}")
|
2024-08-14 21:44:24 +02:00
|
|
|
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:${Versions.secpJniJvmVersion}")
|
2024-03-19 21:43:29 +01:00
|
|
|
implementation(ktor("client-okhttp"))
|
2024-03-25 17:52:09 +01:00
|
|
|
implementation("ch.qos.logback:logback-classic:1.2.3")
|
2024-08-16 01:52:25 +02:00
|
|
|
implementation("org.bytedeco:javacpp:1.5.10")
|
|
|
|
implementation("org.bytedeco:javacpp-presets:1.5.10")
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nativeMain {
|
|
|
|
dependencies {
|
2024-03-20 16:01:45 +01:00
|
|
|
implementation("app.cash.sqldelight:native-driver:${Versions.sqlDelight}")
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-21 14:13:57 +01:00
|
|
|
if (currentOs.isLinux) {
|
|
|
|
linuxMain {
|
|
|
|
dependencies {
|
|
|
|
implementation(ktor("client-curl"))
|
|
|
|
}
|
2024-03-19 21:43:29 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-21 14:13:57 +01:00
|
|
|
if (currentOs.isMacOsX) {
|
|
|
|
macosMain {
|
|
|
|
dependencies {
|
|
|
|
implementation(ktor("client-darwin"))
|
|
|
|
}
|
2024-03-19 14:00:01 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
2024-03-20 16:30:35 +01:00
|
|
|
|
|
|
|
fun Zip.configureZip(dir: String, classifier: String) {
|
|
|
|
group = "package"
|
|
|
|
description = "build and package $dir release executables"
|
|
|
|
archiveBaseName = "phoenix"
|
|
|
|
archiveClassifier = classifier
|
|
|
|
|
2024-03-21 16:20:22 +01:00
|
|
|
from("$projectDir/build/bin/$dir/phoenixdReleaseExecutable") {
|
2024-03-21 14:11:10 +01:00
|
|
|
include("*.kexe")
|
2024-03-20 16:30:35 +01:00
|
|
|
rename("phoenixd.kexe", "phoenixd")
|
|
|
|
}
|
2024-03-21 16:20:22 +01:00
|
|
|
from("$projectDir/build/bin/$dir/phoenix-cliReleaseExecutable") {
|
2024-03-21 14:11:10 +01:00
|
|
|
include("*.kexe")
|
2024-03-20 16:30:35 +01:00
|
|
|
rename("phoenix-cli.kexe", "phoenix-cli")
|
|
|
|
}
|
|
|
|
into("${archiveBaseName.get()}-${archiveVersion.get()}-${archiveClassifier.get()}")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentOs.isLinux) {
|
|
|
|
val packageLinuxX64 by tasks.register("packageLinuxX64", Zip::class) {
|
|
|
|
dependsOn(":linuxX64Binaries")
|
|
|
|
configureZip("linuxX64", "linux-x64")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentOs.isMacOsX) {
|
|
|
|
val packageMacosX64 by tasks.register("packageMacosX64", Zip::class) {
|
|
|
|
dependsOn(":macosX64Binaries")
|
2024-03-20 16:52:50 +01:00
|
|
|
configureZip("macosX64", "macos-x64")
|
|
|
|
}
|
|
|
|
val packageMacosArm by tasks.register("packageMacosArm64", Zip::class) {
|
|
|
|
dependsOn(":macosArm64Binaries")
|
|
|
|
configureZip("macosArm64", "macos-arm64")
|
2024-03-20 16:30:35 +01:00
|
|
|
}
|
|
|
|
}
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
|
2024-03-25 17:52:09 +01:00
|
|
|
application {
|
|
|
|
mainClass = "fr.acinq.lightning.bin.MainKt"
|
2024-08-14 21:44:24 +02:00
|
|
|
|
|
|
|
// Set java.library.path to include the directory where the shared library is generated
|
2024-08-16 01:52:25 +02:00
|
|
|
applicationDefaultJvmArgs = listOf("-Djava.library.path=${layout.buildDirectory.dir("libs").get().asFile}")
|
|
|
|
applicationDefaultJvmArgs = listOf("-DLIBS_PATH=${layout.buildDirectory.dir("libs").get().asFile.absolutePath.replace("\\", "/")}")
|
2024-03-25 17:52:09 +01:00
|
|
|
}
|
|
|
|
|
2024-03-26 16:37:25 +01:00
|
|
|
val cliScripts by tasks.register("cliScripts", CreateStartScripts::class) {
|
|
|
|
mainClass.set("fr.acinq.lightning.cli.PhoenixCliKt")
|
|
|
|
outputDir = tasks.startScripts.get().outputDir
|
|
|
|
classpath = tasks.startScripts.get().classpath
|
|
|
|
applicationName = "phoenix-cli"
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.startScripts {
|
|
|
|
dependsOn(cliScripts)
|
|
|
|
}
|
|
|
|
|
2024-08-16 01:52:25 +02:00
|
|
|
val setLibPath by tasks.register<Exec>("runLinuxExecutable") {
|
|
|
|
val libsDir = layout.buildDirectory.dir("libs").get().asFile
|
|
|
|
val linuxLibsPath = libsDir.absolutePath.replace("\\", "/")
|
|
|
|
|
|
|
|
// Set the environment variable
|
|
|
|
environment("LIBS_PATH", linuxLibsPath)
|
|
|
|
|
|
|
|
// Mark the task as always out-of-date
|
|
|
|
outputs.upToDateWhen { false }
|
|
|
|
|
|
|
|
// Execute the command
|
|
|
|
commandLine("sh", "-c", "LIBS_PATH=$linuxLibsPath; export LIBS_PATH=$linuxLibsPath")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-14 21:44:24 +02:00
|
|
|
val compileNative by tasks.register<Exec>("compileNative") {
|
|
|
|
group = "build"
|
|
|
|
description = "Compile the native C++ code into a shared library"
|
|
|
|
|
2024-08-16 01:52:25 +02:00
|
|
|
val outputDir = layout.buildDirectory.dir("libs").get().asFile
|
2024-08-14 21:44:24 +02:00
|
|
|
val nativeSourceDir = file("src/commonMain/kotlin/fr/acinq/lightning/vsock/native")
|
|
|
|
|
|
|
|
// Locate the JNI headers - adjust these paths based on your actual JDK location
|
|
|
|
val jdkHome = System.getenv("JAVA_HOME") ?: "/usr/lib/jvm/default-java"
|
|
|
|
val jniIncludeDir = file("$jdkHome/include")
|
|
|
|
val jniPlatformIncludeDir = file("$jniIncludeDir/linux") // or "win32" for Windows, "darwin" for macOS
|
|
|
|
|
|
|
|
inputs.dir(nativeSourceDir)
|
|
|
|
outputs.dir(outputDir)
|
|
|
|
|
|
|
|
commandLine("g++", "-I$jniIncludeDir", "-I$jniPlatformIncludeDir", "-shared", "-o", outputDir.resolve("libjniVSockImpl.so"), nativeSourceDir.resolve("VSockImpl.cpp"), "-fPIC")
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType<Tar> {
|
|
|
|
dependsOn(compileNative)
|
2024-08-16 01:52:25 +02:00
|
|
|
dependsOn(setLibPath)
|
2024-08-14 21:44:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType<Zip> {
|
|
|
|
dependsOn(compileNative)
|
2024-08-16 01:52:25 +02:00
|
|
|
dependsOn(setLibPath)
|
2024-08-14 21:44:24 +02:00
|
|
|
}
|
|
|
|
|
2024-03-25 17:52:09 +01:00
|
|
|
distributions {
|
|
|
|
main {
|
|
|
|
distributionBaseName = "phoenix"
|
|
|
|
distributionClassifier = "jvm"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-08 18:44:24 +01:00
|
|
|
// forward std input when app is run via gradle (otherwise keyboard input will return EOF)
|
|
|
|
tasks.withType<JavaExec> {
|
|
|
|
standardInput = System.`in`
|
|
|
|
}
|
|
|
|
|
|
|
|
sqldelight {
|
|
|
|
databases {
|
2024-03-18 17:21:03 +01:00
|
|
|
create("PhoenixDatabase") {
|
2024-03-08 18:44:24 +01:00
|
|
|
packageName.set("fr.acinq.phoenix.db")
|
2024-03-18 17:21:03 +01:00
|
|
|
srcDirs.from("src/commonMain/sqldelight/phoenixdb")
|
2024-03-08 18:44:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 16:01:45 +01:00
|
|
|
|