Skip to content

Commit 0bce9cc

Browse files
authored
Merge pull request #141 from powersync-ja/macos
Enable macOS support
2 parents 3eda581 + d8ac805 commit 0bce9cc

File tree

22 files changed

+116
-81
lines changed

22 files changed

+116
-81
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
matrix:
1717
include:
1818
- os: macos-latest
19-
targets: iosSimulatorArm64Test jvmTest lintKotlin
19+
targets: iosSimulatorArm64Test macosArm64Test jvmTest
2020
- os: ubuntu-latest
21-
targets: testDebugUnitTest testReleaseUnitTest jvmTest
21+
targets: testDebugUnitTest testReleaseUnitTest jvmTest lintKotlin
2222
- os: windows-latest
2323
targets: jvmTest
2424
runs-on: ${{ matrix.os }}

PowerSyncKotlin/build.gradle.kts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ kotlin {
1717
iosX64(),
1818
iosArm64(),
1919
iosSimulatorArm64(),
20+
macosArm64(),
21+
macosX64(),
2022
).forEach {
2123
it.binaries.framework {
2224
export(project(":core"))
@@ -41,6 +43,26 @@ kotlin {
4143
}
4244
}
4345

46+
repositories {
47+
maven {
48+
name = "PowerSyncSQLiterFork"
49+
url = uri("https://powersync-ja.github.io/SQLiter")
50+
content {
51+
includeModuleByRegex("co.touchlab", "sqliter-driver.*")
52+
}
53+
}
54+
}
55+
56+
configurations.all {
57+
resolutionStrategy {
58+
// This version has not been released yet (https://github.com/touchlab/SQLiter/pull/124), so we're pointing this
59+
// towards our fork with the repositories block above.
60+
// The API is identical, but we have to make sure this particular project builds the xcframework with the
61+
// patched SQLiter version to avoid linker errors on macOS.
62+
force("co.touchlab:sqliter-driver:1.3.2-powersync")
63+
}
64+
}
65+
4466
kmmbridge {
4567
artifactManager.set(SonatypePortalPublishArtifactManager(project, repositoryName = null))
4668
artifactManager.finalizeValue()
File renamed without changes.

compose/build.gradle.kts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.powersync.plugins.sonatype.setupGithubRepository
2+
import com.powersync.plugins.utils.powersyncTargets
23

34
plugins {
45
alias(libs.plugins.kotlinMultiplatform)
@@ -10,15 +11,7 @@ plugins {
1011
}
1112

1213
kotlin {
13-
androidTarget {
14-
publishLibraryVariants("release", "debug")
15-
}
16-
17-
jvm()
18-
19-
iosX64()
20-
iosArm64()
21-
iosSimulatorArm64()
14+
powersyncTargets(includeTargetsWithoutComposeSupport = false)
2215

2316
explicitApi()
2417

connectors/supabase/build.gradle.kts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.powersync.plugins.sonatype.setupGithubRepository
2+
import com.powersync.plugins.utils.powersyncTargets
23
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
34

45
plugins {
@@ -10,12 +11,7 @@ plugins {
1011
}
1112

1213
kotlin {
13-
androidTarget {
14-
publishLibraryVariants("release", "debug")
15-
}
16-
17-
jvm()
18-
14+
powersyncTargets()
1915
targets.withType<KotlinNativeTarget> {
2016
compilations.named("main") {
2117
compileTaskProvider {
@@ -24,10 +20,6 @@ kotlin {
2420
}
2521
}
2622

27-
iosX64()
28-
iosArm64()
29-
iosSimulatorArm64()
30-
3123
explicitApi()
3224

3325
sourceSets {

core/build.gradle.kts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import com.powersync.plugins.sonatype.setupGithubRepository
2+
import com.powersync.plugins.utils.powersyncTargets
23
import de.undercouch.gradle.tasks.download.Download
34
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
45
import org.gradle.internal.os.OperatingSystem
5-
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
6-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
76
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
87
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
98
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
@@ -84,15 +83,22 @@ val downloadPowersyncFramework by tasks.registering(Download::class) {
8483
onlyIfModified(true)
8584
}
8685

87-
val unzipPowersyncFramework by tasks.registering(Copy::class) {
86+
val unzipPowersyncFramework by tasks.registering(Exec::class) {
8887
dependsOn(downloadPowersyncFramework)
8988

90-
from(
91-
zipTree(downloadPowersyncFramework.get().dest).matching {
92-
include("powersync-sqlite-core.xcframework/**")
93-
},
94-
)
95-
into(binariesFolder.map { it.dir("framework") })
89+
val zipfile = downloadPowersyncFramework.get().dest
90+
inputs.file(zipfile)
91+
val destination = File(zipfile.parentFile, "extracted")
92+
doFirst {
93+
destination.deleteRecursively()
94+
destination.mkdir()
95+
}
96+
97+
// We're using unzip here because the Gradle copy task doesn't support symlinks.
98+
executable = "unzip"
99+
args(zipfile.absolutePath)
100+
workingDir(destination)
101+
outputs.dir(destination)
96102
}
97103

98104
val sqliteJDBCFolder =
@@ -150,26 +156,7 @@ val moveJDBCJNIFiles by tasks.registering(Copy::class) {
150156
}
151157

152158
kotlin {
153-
androidTarget {
154-
publishLibraryVariants("release", "debug")
155-
156-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
157-
compilerOptions {
158-
jvmTarget.set(JvmTarget.JVM_17)
159-
}
160-
}
161-
jvm {
162-
@OptIn(ExperimentalKotlinGradlePluginApi::class)
163-
compilerOptions {
164-
jvmTarget.set(JvmTarget.JVM_1_8)
165-
// https://jakewharton.com/kotlins-jdk-release-compatibility-flag/
166-
freeCompilerArgs.add("-Xjdk-release=8")
167-
}
168-
}
169-
170-
iosX64()
171-
iosArm64()
172-
iosSimulatorArm64()
159+
powersyncTargets()
173160

174161
targets.withType<KotlinNativeTarget> {
175162
compilations.named("main") {
@@ -184,7 +171,20 @@ kotlin {
184171
linkerOpts("-framework", "powersync-sqlite-core")
185172
val frameworkRoot =
186173
binariesFolder
187-
.map { it.dir("framework/powersync-sqlite-core.xcframework/ios-arm64_x86_64-simulator") }
174+
.map { it.dir("framework/extracted/powersync-sqlite-core.xcframework/ios-arm64_x86_64-simulator") }
175+
.get()
176+
.asFile.path
177+
178+
linkerOpts("-F", frameworkRoot)
179+
linkerOpts("-rpath", frameworkRoot)
180+
}
181+
} else if (konanTarget.family == Family.OSX) {
182+
binaries.withType<TestExecutable>().configureEach {
183+
linkTaskProvider.configure { dependsOn(unzipPowersyncFramework) }
184+
linkerOpts("-framework", "powersync-sqlite-core")
185+
var frameworkRoot =
186+
binariesFolder
187+
.map { it.dir("framework/extracted/powersync-sqlite-core.xcframework/macos-arm64_x86_64") }
188188
.get()
189189
.asFile.path
190190

@@ -253,8 +253,8 @@ kotlin {
253253
}
254254
}
255255

256-
iosMain.dependencies {
257-
implementation(libs.ktor.client.ios)
256+
appleMain.dependencies {
257+
implementation(libs.ktor.client.darwin)
258258
}
259259

260260
commonTest.dependencies {
@@ -271,8 +271,9 @@ kotlin {
271271
// tests.
272272
jvmTest.get().dependsOn(commonIntegrationTest)
273273

274-
// We're linking the xcframework for the simulator tests, so they can use integration tests too
275-
iosSimulatorArm64Test.orNull?.dependsOn(commonIntegrationTest)
274+
// We have special setup in this build configuration to make these tests link the PowerSync extension, so they
275+
// can run integration tests along with the executable for unit testing.
276+
appleTest.orNull?.dependsOn(commonIntegrationTest)
276277
}
277278
}
278279

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)