forked from ACINQ/phoenixd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
204 lines (185 loc) · 6.61 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import Versions.ktor
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
import java.io.ByteArrayOutputStream
buildscript {
dependencies {
classpath("app.cash.sqldelight:gradle-plugin:${Versions.sqlDelight}")
}
repositories {
google()
mavenCentral()
}
}
plugins {
kotlin("multiplatform") version Versions.kotlin
kotlin("plugin.serialization") version Versions.kotlin
id("app.cash.sqldelight") version Versions.sqlDelight
}
allprojects {
group = "fr.acinq.lightning"
version = "0.1.1"
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()
}
}
/** 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/"))
}
kotlin {
jvm()
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
}
executable("phoenix-cli") {
entryPoint = "fr.acinq.lightning.cli.main"
optimized = false // without this, release mode throws 'Index 0 out of bounds for length 0' in StaticInitializersOptimization.kt
}
}
}
val currentOs = org.gradle.internal.os.OperatingSystem.current()
if (currentOs.isLinux) {
linuxX64 {
phoenixBinaries()
}
}
if (currentOs.isMacOsX) {
macosX64 {
phoenixBinaries()
}
macosArm64 {
phoenixBinaries()
}
}
sourceSets {
commonMain {
kotlin.srcDir(buildVersionsTask.map { it.destinationDir })
dependencies {
implementation("fr.acinq.lightning:lightning-kmp:${Versions.lightningKmp}")
// 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"))
implementation("com.squareup.okio:okio:${Versions.okio}")
implementation("com.github.ajalt.clikt:clikt:${Versions.clikt}")
implementation("app.cash.sqldelight:coroutines-extensions:${Versions.sqlDelight}")
}
}
jvmMain {
dependencies {
implementation("app.cash.sqldelight:sqlite-driver:${Versions.sqlDelight}")
implementation(ktor("client-okhttp"))
}
}
nativeMain {
dependencies {
implementation("app.cash.sqldelight:native-driver:${Versions.sqlDelight}")
}
}
if (currentOs.isLinux) {
linuxMain {
dependencies {
implementation(ktor("client-curl"))
}
}
}
if (currentOs.isMacOsX) {
macosMain {
dependencies {
implementation(ktor("client-darwin"))
}
}
}
}
fun Zip.configureZip(dir: String, classifier: String) {
group = "package"
description = "build and package $dir release executables"
archiveBaseName = "phoenix"
archiveClassifier = classifier
from("$projectDir/build/bin/$dir/phoenixdReleaseExecutable") {
include("*.kexe")
rename("phoenixd.kexe", "phoenixd")
}
from("$projectDir/build/bin/$dir/phoenix-cliReleaseExecutable") {
include("*.kexe")
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")
configureZip("macosX64", "macos-x64")
}
val packageMacosArm by tasks.register("packageMacosArm64", Zip::class) {
dependsOn(":macosArm64Binaries")
configureZip("macosArm64", "macos-arm64")
}
}
}
// forward std input when app is run via gradle (otherwise keyboard input will return EOF)
tasks.withType<JavaExec> {
standardInput = System.`in`
}
sqldelight {
databases {
create("PhoenixDatabase") {
packageName.set("fr.acinq.phoenix.db")
srcDirs.from("src/commonMain/sqldelight/phoenixdb")
}
}
}