Skip to content

Commit ec78874

Browse files
committed
Update docs on local builds
1 parent 0eb8b27 commit ec78874

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

Package.swift

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,35 @@
44
import PackageDescription
55
let packageName = "PowerSync"
66

7+
// Set this to the absolute path of your Kotlin SDK checkout if you want to use a local Kotlin
8+
// build. Also see docs/LocalBuild.md for details
9+
let localKotlinSdkOverride: String? = nil
10+
11+
// Our target and dependency setup is different when a local Kotlin SDK is used. Without the local
12+
// SDK, we have no package dependency on Kotlin and download the XCFramework from Kotlin releases as
13+
// a binary target.
14+
// With a local SDK, we point to a `Package.swift` within the Kotlin SDK containing a target pointing
15+
// towards a local framework build
16+
var conditionalDependencies: [Package.Dependency] = []
17+
var conditionalTargets: [Target] = []
18+
var kotlinTargetDependency = Target.Dependency.target(name: "PowerSyncKotlin")
19+
20+
if let kotlinSdkPath = localKotlinSdkOverride {
21+
// We can't depend on local XCFrameworks outside of this project's root, so there's a Package.swift
22+
// in the PowerSyncKotlin project pointing towards a local build.
23+
conditionalDependencies.append(.package(path: "\(kotlinSdkPath)/PowerSyncKotlin"))
24+
25+
kotlinTargetDependency = .product(name: "PowerSyncKotlin", package: "PowerSyncKotlin")
26+
} else {
27+
// Not using a local build, so download from releases
28+
conditionalTargets.append(.binaryTarget(
29+
name: "PowerSyncKotlin",
30+
// TODO: Use GitHub release once https://github.com/powersync-ja/powersync-kotlin/releases/tag/untagged-fde4386dec502ec27067 is published
31+
url: "https://fsn1.your-objectstorage.com/simon-public/powersync.zip",
32+
checksum: "b6770dc22ae31315adc599e653fea99614226312fe861dbd8764e922a5a83b09"
33+
))
34+
}
35+
736
let package = Package(
837
name: packageName,
938
platforms: [
@@ -18,31 +47,19 @@ let package = Package(
1847
],
1948
dependencies: [
2049
.package(url: "https://github.com/powersync-ja/powersync-sqlite-core-swift.git", "0.3.14"..<"0.4.0")
21-
],
50+
] + conditionalDependencies,
2251
targets: [
2352
// Targets are the basic building blocks of a package, defining a module or a test suite.
2453
// Targets can depend on other targets in this package and products from dependencies.
2554
.target(
2655
name: packageName,
2756
dependencies: [
28-
.target(name: "PowerSyncKotlin"),
57+
kotlinTargetDependency,
2958
.product(name: "PowerSyncSQLiteCore", package: "powersync-sqlite-core-swift")
3059
]),
3160
.testTarget(
3261
name: "PowerSyncTests",
3362
dependencies: ["PowerSync"]
3463
),
35-
// If you want to use a local build, comment out this reference and update the other.
36-
// See docs/LocalBuild.md
37-
.binaryTarget(
38-
name: "PowerSyncKotlin",
39-
// TODO: Use GitHub release once https://github.com/powersync-ja/powersync-kotlin/releases/tag/untagged-fde4386dec502ec27067 is published
40-
url: "https://fsn1.your-objectstorage.com/simon-public/powersync.zip",
41-
checksum: "b6770dc22ae31315adc599e653fea99614226312fe861dbd8764e922a5a83b09"
42-
),
43-
// .binaryTarget(
44-
// name: "PowerSyncKotlin",
45-
// path: "/path/to/powersync-kotlin/PowerSyncKotlin/build/XCFrameworks/debug/PowerSyncKotlin.xcframework"
46-
// )
47-
]
64+
] + conditionalTargets
4865
)

docs/LocalBuild.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ To do this, first create an XCFramework from your Kotlin checkout:
1010
./gradlew PowerSyncKotlin:assemblePowerSyncKotlinDebugXCFramework
1111
```
1212

13-
Then, point the `binaryTarget` dependency in `Package.swift` towards the path of your generated
14-
XCFramework:
13+
Next, you need to update the `Package.swift` to, instead of downloading a
14+
prebuilt XCFramework archive from a Kotlin release, use your local build.
15+
For this, set the `localKotlinSdkOverride` variable to your path:
1516

1617
```Swift
17-
.binaryTarget(
18-
name: "PowerSyncKotlin",
19-
path: "/path/to/powersync-kotlin/PowerSyncKotlin/build/XCFrameworks/debug/PowerSyncKotlin.xcframework"
20-
)
18+
let localKotlinSdkOverride: String? = "/path/to/powersync-kotlin/"
2119
```
2220

2321
Subsequent Kotlin changes should get picked up after re-assembling the Kotlin XCFramework.

0 commit comments

Comments
 (0)