Skip to content

Commit 354448e

Browse files
committed
Enable testing core on macOS
1 parent 4cae68a commit 354448e

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

core/build.gradle.kts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
66
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
77
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
88
import org.jetbrains.kotlin.konan.target.Family
9+
import org.jetbrains.kotlin.konan.target.KonanTarget
910

1011

1112
plugins {
@@ -171,16 +172,21 @@ kotlin {
171172
linkerOpts("-rpath", frameworkRoot)
172173
}
173174
}
174-
/*
175-
If we ever need macOS support:
176-
{
175+
176+
if (konanTarget.family == Family.OSX) {
177177
binaries.withType<TestExecutable>().configureEach {
178-
linkTaskProvider.dependsOn(downloadPowersyncDesktopBinaries)
179-
linkerOpts("-lpowersync")
180-
linkerOpts("-L", binariesFolder.map { it.dir("powersync") }.get().asFile.path)
178+
linkTaskProvider.configure { dependsOn(unzipPowersyncFramework) }
179+
linkerOpts("-framework", "powersync-sqlite-core")
180+
val frameworkRoot =
181+
binariesFolder
182+
.map { it.dir("framework/powersync-sqlite-core.xcframework/macos-arm64_x86_64") }
183+
.get()
184+
.asFile.path
185+
186+
linkerOpts("-F", frameworkRoot)
187+
linkerOpts("-rpath", frameworkRoot)
181188
}
182189
}
183-
*/
184190
}
185191

186192
explicitApi()
@@ -230,8 +236,9 @@ kotlin {
230236
implementation(libs.sqlite.jdbc)
231237
}
232238

233-
iosMain.dependencies {
234-
implementation(libs.ktor.client.ios)
239+
appleMain.dependencies {
240+
implementation(libs.ktor.client.apple)
241+
implementation(libs.kotlinx.io)
235242
}
236243

237244
commonTest.dependencies {
@@ -251,7 +258,7 @@ kotlin {
251258
jvmMain.get().dependsOn(commonJDBC)
252259

253260
// We're linking the xcframework for the simulator tests, so they can use integration tests too
254-
iosSimulatorArm64Test.orNull?.dependsOn(commonIntegrationTest)
261+
appleTest.orNull?.dependsOn(commonIntegrationTest)
255262
}
256263
}
257264

File renamed without changes.

core/src/iosMain/kotlin/com/powersync/DatabaseDriverFactory.ios.kt renamed to core/src/appleMain/kotlin/com/powersync/DatabaseDriverFactory.apple.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import kotlinx.cinterop.staticCFunction
2626
import kotlinx.cinterop.toKString
2727
import kotlinx.cinterop.value
2828
import kotlinx.coroutines.CoroutineScope
29+
import kotlinx.io.files.Path
30+
import kotlinx.io.files.SystemFileSystem
31+
import kotlinx.io.files.SystemPathSeparator
2932
import platform.Foundation.NSBundle
3033

3134
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
@@ -60,13 +63,23 @@ public actual class DatabaseDriverFactory {
6063
// a pointer for C hooks
6164
val deferredDriver = DeferredDriver()
6265

66+
val resultingPath = when(dbDirectory) {
67+
null -> dbFilename
68+
else -> {
69+
val path = Path(dbDirectory)
70+
SystemFileSystem.createDirectories(path)
71+
72+
dbDirectory + SystemPathSeparator + dbFilename
73+
}
74+
}
75+
6376
val driver =
6477
PsSqlDriver(
6578
driver =
6679
NativeSqliteDriver(
6780
configuration =
6881
DatabaseConfiguration(
69-
name = dbFilename,
82+
name = resultingPath,
7083
version = schema.version.toInt(),
7184
create = { connection ->
7285
wrapConnection(connection) {
File renamed without changes.
File renamed without changes.

core/src/commonIntegrationTest/kotlin/com/powersync/DatabaseTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.powersync
22

33
import app.cash.turbine.turbineScope
4-
import com.powersync.db.getString
54
import com.powersync.db.schema.Schema
65
import com.powersync.testutils.UserRow
76
import kotlinx.coroutines.CompletableDeferred

core/src/commonIntegrationTest/kotlin/com/powersync/SyncIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import kotlinx.coroutines.channels.Channel
2828
import kotlinx.coroutines.flow.receiveAsFlow
2929
import kotlinx.coroutines.runBlocking
3030
import kotlinx.coroutines.test.runTest
31+
import kotlinx.io.files.SystemTemporaryDirectory
3132
import kotlinx.serialization.encodeToString
3233
import kotlinx.serialization.json.JsonObject
3334
import kotlin.test.AfterTest

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.
7676
uuid = { module = "com.benasher44:uuid", version.ref = "uuid" }
7777

7878
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
79-
ktor-client-ios = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
79+
ktor-client-apple = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
8080
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
8181
ktor-client-contentnegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
8282
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }

0 commit comments

Comments
 (0)