Skip to content

Commit 820df7d

Browse files
authored
Update core extension, download binaries (#303)
1 parent 5c70d5b commit 820df7d

File tree

6 files changed

+89
-28
lines changed

6 files changed

+89
-28
lines changed

.github/workflows/prebuild_assets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Compile SQLite with Gradle
6262
if: steps.cache_prebuild.outputs.cache-hit != 'true'
6363
run: |
64-
./gradlew --scan internal:prebuild-binaries:compileAll
64+
./gradlew --scan --configure-on-demand internal:prebuild-binaries:compileAll
6565
shell: bash
6666
- uses: actions/upload-artifact@v5
6767
id: upload

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@ jobs:
138138
disable-animations: false
139139
avd-name: $AVD_NAME
140140
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
141-
script: ./gradlew --scan core-tests-android:connectedCheck
141+
script: ./gradlew --scan --configure-on-demand core-tests-android:connectedCheck

common/build.gradle.kts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,46 @@ val downloadPowersyncDesktopBinaries by tasks.registering(Download::class) {
3131
val coreVersion =
3232
libs.versions.powersync.core
3333
.get()
34-
val linux_aarch64 =
35-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_aarch64.linux.so"
36-
val linux_x64 =
37-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_x64.linux.so"
38-
val macos_aarch64 =
39-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_aarch64.macos.dylib"
40-
val macos_x64 =
41-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_x64.macos.dylib"
42-
val windows_x64 =
43-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/powersync_x64.dll"
34+
35+
fun downloadUrl(filename: String): String {
36+
return "https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/$filename"
37+
}
38+
39+
val linux_aarch64 = "libpowersync_aarch64.linux.so"
40+
val linux_x64 = "libpowersync_x64.linux.so"
41+
val macos_aarch64 = "libpowersync_aarch64.macos.dylib"
42+
val macos_x64 = "libpowersync_x64.macos.dylib"
43+
val windows_aarch64 = "powersync_aarch64.dll"
44+
val windows_x64 = "powersync_x64.dll"
4445

4546
val includeAllPlatformsForJvmBuild =
4647
project.findProperty("powersync.binaries.allPlatforms") == "true"
4748
val os = OperatingSystem.current()
4849

4950
// The jar we're releasing for JVM clients needs to include the core extension. For local tests, it's enough to only
5051
// download the extension for the OS running the build. For releases, we want to include them all.
51-
// We're not compiling native code for JVM builds here (we're doing that for Android only), so we just have to
52-
// fetch prebuilt binaries from the powersync-sqlite-core repository.
52+
// We're not compiling native code for JVM builds here, so we just have to fetch prebuilt binaries from the
53+
// powersync-sqlite-core repository.
5354
if (includeAllPlatformsForJvmBuild) {
54-
src(listOf(linux_aarch64, linux_x64, macos_aarch64, macos_x64, windows_x64))
55+
val allSources = sequenceOf(linux_aarch64, linux_x64, macos_aarch64, macos_x64, windows_aarch64, windows_x64)
56+
.map(::downloadUrl)
57+
.toList()
58+
src(allSources)
5559
} else {
5660
val (aarch64, x64) =
5761
when {
5862
os.isLinux -> linux_aarch64 to linux_x64
5963
os.isMacOsX -> macos_aarch64 to macos_x64
60-
os.isWindows -> null to windows_x64
64+
os.isWindows -> windows_aarch64 to windows_x64
6165
else -> error("Unknown operating system: $os")
6266
}
6367
val arch = System.getProperty("os.arch")
64-
src(
65-
when (arch) {
66-
"aarch64" -> listOfNotNull(aarch64)
67-
"amd64", "x86_64" -> listOfNotNull(x64)
68-
else -> error("Unsupported architecture: $arch")
69-
},
70-
)
68+
val filename = when (arch) {
69+
"aarch64" -> aarch64
70+
"amd64", "x86_64" -> x64
71+
else -> error("Unsupported architecture: $arch")
72+
}
73+
src(downloadUrl(filename))
7174
}
7275
dest(binariesFolder.map { it.dir("powersync") })
7376
onlyIfModified(true)

common/src/commonMain/kotlin/com/powersync/db/internal/PowerSyncVersion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal data class PowerSyncVersion(
1818
override fun toString(): String = "$major.$minor.$patch"
1919

2020
companion object {
21-
val MINIMUM: PowerSyncVersion = PowerSyncVersion(0, 4, 0)
21+
val MINIMUM: PowerSyncVersion = PowerSyncVersion(0, 4, 10)
2222

2323
fun parse(from: String): PowerSyncVersion {
2424
val versionInts: List<Int> =

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ serialization = "1.9.0"
1818
kotlinx-io = "0.8.0"
1919
ktor = "3.3.3"
2020
uuid = "0.8.4"
21-
powersync-core = "0.4.9"
21+
powersync-core = "0.4.10"
2222
rsocket = "0.20.0"
2323
turbine = "1.2.1"
2424
kotest = "5.9.1" # we can't upgrade to 6.x because that requires Java 11 or above (we need Java 8 support)

internal/prebuild-binaries/build.gradle.kts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import com.powersync.compile.JniTarget
1010
import kotlin.io.path.absolutePathString
1111

1212
plugins {
13+
base // For the clean task
1314
alias(libs.plugins.downloadPlugin)
1415
}
1516

17+
val lastKotlinSdkRelease = project.property("LIBRARY_VERSION") as String
18+
1619
val sqlite3McVersion = "2.2.6"
1720
val sqlite3BaseVersion = "3.51.1"
1821
val sqlite3ReleaseYear = "2025"
@@ -41,6 +44,14 @@ val downloadSqlite3MultipleCipherSources by tasks.registering(Download::class) {
4144
overwrite(false)
4245
}
4346

47+
val downloadPrebuiltsFromRelease by tasks.registering(Download::class) {
48+
val zipFileName = "prebuilts-$lastKotlinSdkRelease.zip"
49+
src("https://github.com/powersync-ja/powersync-kotlin/releases/download/v$lastKotlinSdkRelease/prebuilt_libraries.zip")
50+
dest(layout.buildDirectory.dir("downloads").map { it.file(zipFileName) })
51+
onlyIfNewer(true)
52+
overwrite(false)
53+
}
54+
4455
val unzipSQLiteSources by tasks.registering(UnzipSqlite::class) {
4556
val zip = downloadSQLiteSources.map { it.outputs.files.singleFile }
4657
inputs.file(zip)
@@ -62,6 +73,33 @@ val unzipSqlite3MultipleCipherSources by tasks.registering(UnzipSqlite::class) {
6273
)
6374
}
6475

76+
abstract class ExtractPrebuilts: Copy() {
77+
@get:OutputDirectory
78+
abstract val outputDir: DirectoryProperty
79+
80+
init {
81+
into(outputDir)
82+
}
83+
}
84+
85+
val unzipPrebuiltsFromLastRelease by tasks.registering(ExtractPrebuilts::class) {
86+
val zip = downloadPrebuiltsFromRelease.map { it.outputs.files.singleFile }
87+
88+
from(zipTree(zip)) {
89+
include("internal/prebuild-binaries/build/output/**")
90+
91+
eachFile {
92+
relativePath = RelativePath(
93+
relativePath.isFile,
94+
// Remove segments: [internal, prebuild-binaries, build, output]
95+
*relativePath.segments.drop(4).toTypedArray()
96+
)
97+
}
98+
}
99+
100+
outputDir.set(layout.buildDirectory.dir("downloads/from_last_release"))
101+
}
102+
65103
val prepareAndroidBuild by tasks.registering(Copy::class) {
66104
from(unzipSqlite3MultipleCipherSources.flatMap { it.destination }) {
67105
include(
@@ -186,7 +224,6 @@ val compileAll by tasks.registering {
186224
dependsOn(compileJni)
187225
}
188226

189-
val hasPrebuiltAssets = providers.gradleProperty("hasPrebuiltAssets").map { it.toBooleanStrict() }
190227

191228
val nativeSqliteConfiguration by configurations.creating {
192229
isCanBeResolved = false
@@ -202,12 +239,33 @@ val androidBuildSourceConfiguration by configurations.creating {
202239
}
203240

204241
artifacts {
242+
val hasPrebuiltAssets = providers.gradleProperty("hasPrebuiltAssets").map { it.toBooleanStrict() }
243+
val isInCI = providers.environmentVariable("CI").isPresent
244+
245+
// There are three ways to obtain the static and JNI libraries:
246+
//
247+
// 1. We can download and compile from source. This requires special toolchain dependencies (see readme) and is
248+
// slow.
249+
// 2. We can download compiled binaries from the last GitHub release. We don't want to do this in CI to ensure
250+
// updates to the build are reflected in tests. It's a good fit for builds on developer machines though.
251+
// 3. In CI, we run 1 in a separate step and re-use its outputs across multiple builds. -PhasPrebuiltAssets=true is
252+
// passed for consumers of those artifacts.
205253
if (hasPrebuiltAssets.getOrElse(false)) {
206-
// In CI builds, we set hasPrebuiltAssets=true. In that case, contents of build/output have been downloaded from
207-
// cache and don't need to be rebuilt.
254+
// Case 3: Re-use downloaded assets.
208255
add(nativeSqliteConfiguration.name, layout.buildDirectory.dir("output/static"))
209256
add(jniSqlite3McConfiguration.name, layout.buildDirectory.dir("output/jni"))
257+
} else if (!isInCI) {
258+
// Developer machine, case 2. Download from last release.
259+
add(
260+
nativeSqliteConfiguration.name,
261+
unzipPrebuiltsFromLastRelease.flatMap { it.outputDir.dir("static") }
262+
)
263+
add(
264+
jniSqlite3McConfiguration.name,
265+
unzipPrebuiltsFromLastRelease.flatMap { it.outputDir.dir("jni") }
266+
)
210267
} else {
268+
// Case 1, compile from source.
211269
add(nativeSqliteConfiguration.name, compileNative)
212270
add(jniSqlite3McConfiguration.name, compileJni)
213271
}

0 commit comments

Comments
 (0)