@@ -6,7 +6,9 @@ import org.gradle.internal.os.OperatingSystem
6
6
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
7
7
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
8
8
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
9
-
9
+ import java.nio.file.Path
10
+ import kotlin.io.path.createDirectories
11
+ import kotlin.io.path.writeText
10
12
11
13
plugins {
12
14
alias(libs.plugins.kotlinMultiplatform)
@@ -128,23 +130,24 @@ val moveJDBCJNIFiles by tasks.registering(Copy::class) {
128
130
kotlin {
129
131
powersyncTargets()
130
132
131
- targets.withType< KotlinNativeTarget > {
132
- compilations.named( " main " ) {
133
- compileTaskProvider {
134
- compilerOptions.freeCompilerArgs.add( " -Xexport-kdoc " )
133
+ targets.configureEach {
134
+ compilations.configureEach {
135
+ compileTaskProvider.configure {
136
+ dependsOn(generateVersionConstant )
135
137
}
136
138
}
137
139
138
- /*
139
- If we ever need macOS support:
140
- {
141
- binaries.withType<TestExecutable>().configureEach {
142
- linkTaskProvider.dependsOn(downloadPowersyncDesktopBinaries)
143
- linkerOpts("-lpowersync")
144
- linkerOpts("-L", binariesFolder.map { it.dir("powersync") }.get().asFile.path)
140
+ if (this is KotlinNativeTarget ) {
141
+ compilations.named(" main" ) {
142
+ compileTaskProvider.configure {
143
+ compilerOptions.freeCompilerArgs.add(" -Xexport-kdoc" )
144
+ }
145
145
}
146
146
}
147
- */
147
+ }
148
+
149
+ targets.withType<KotlinNativeTarget > {
150
+
148
151
}
149
152
150
153
explicitApi()
@@ -168,21 +171,27 @@ kotlin {
168
171
}
169
172
}
170
173
171
- commonMain.dependencies {
172
- implementation(libs.uuid)
173
- implementation(libs.kotlin.stdlib)
174
- implementation(libs.ktor.client.core)
175
- implementation(libs.ktor.client.contentnegotiation)
176
- implementation(libs.ktor.serialization.json)
177
- implementation(libs.kotlinx.io)
178
- implementation(libs.rsocket.core)
179
- implementation(libs.rsocket.transport.websocket)
180
- implementation(libs.kotlinx.coroutines.core)
181
- implementation(libs.kotlinx.datetime)
182
- implementation(libs.stately.concurrency)
183
- implementation(libs.configuration.annotations)
184
- api(projects.persistence)
185
- api(libs.kermit)
174
+ commonMain.configure {
175
+ kotlin {
176
+ srcDir(layout.buildDirectory.dir(" generated/constants" ))
177
+ }
178
+
179
+ dependencies {
180
+ implementation(libs.uuid)
181
+ implementation(libs.kotlin.stdlib)
182
+ implementation(libs.ktor.client.core)
183
+ implementation(libs.ktor.client.contentnegotiation)
184
+ implementation(libs.ktor.serialization.json)
185
+ implementation(libs.kotlinx.io)
186
+ implementation(libs.rsocket.core)
187
+ implementation(libs.rsocket.transport.websocket)
188
+ implementation(libs.kotlinx.coroutines.core)
189
+ implementation(libs.kotlinx.datetime)
190
+ implementation(libs.stately.concurrency)
191
+ implementation(libs.configuration.annotations)
192
+ api(projects.persistence)
193
+ api(libs.kermit)
194
+ }
186
195
}
187
196
188
197
androidMain {
@@ -302,3 +311,29 @@ setupGithubRepository()
302
311
dokka {
303
312
moduleName.set(" PowerSync Core" )
304
313
}
314
+
315
+ val generateVersionConstant by tasks.registering {
316
+ val target = project.layout.buildDirectory.dir(" generated/constants" )
317
+ val packageName = " com.powersync.build"
318
+
319
+ outputs.dir(target)
320
+ val currentVersion = version.toString()
321
+
322
+ doLast {
323
+ val dir = target.get().asFile
324
+ dir.mkdir()
325
+ val rootPath = dir.toPath()
326
+
327
+ val source = """
328
+ package $packageName
329
+
330
+ internal const val LIBRARY_VERSION: String = "$currentVersion "
331
+
332
+ """ .trimIndent()
333
+
334
+ val packageRoot = packageName.split(' .' ).fold(rootPath, Path ::resolve)
335
+ packageRoot.createDirectories()
336
+
337
+ packageRoot.resolve(" BuildConstants.kt" ).writeText(source)
338
+ }
339
+ }
0 commit comments