Skip to content

Commit 73d0866

Browse files
committed
Don't include cinterop at all
1 parent dacf29f commit 73d0866

File tree

2 files changed

+14
-73
lines changed

2 files changed

+14
-73
lines changed

core/build.gradle.kts

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,17 @@ val unzipSQLiteSources by tasks.registering(Copy::class) {
5656
into(sqliteSrcFolder)
5757
}
5858

59-
val buildCInteropDef by tasks.registering {
59+
val compileSqliteForTesting by tasks.registering(Exec::class) {
6060
dependsOn(unzipSQLiteSources)
6161

62-
val interopFolder =
63-
project.layout.buildDirectory
64-
.dir("interop/sqlite")
65-
.get()
66-
67-
val cFile = sqliteSrcFolder.file("sqlite3.c").asFile
68-
val defFile = interopFolder.file("sqlite3.def").asFile
62+
val input = sqliteSrcFolder.file("sqlite3.c")
63+
inputs.file(input)
64+
inputs.file(sqliteSrcFolder.file("sqlite3.h"))
6965

70-
doFirst {
71-
defFile.writeText(
72-
"""
73-
package = com.powersync.sqlite3
74-
---
66+
val output = sqliteSrcFolder.file("libsqlite3.dylib")
67+
outputs.file(output)
7568

76-
""".trimIndent() + cFile.readText(),
77-
)
78-
}
79-
outputs.files(defFile)
69+
commandLine("clang", "-shared", "-o", output.asFile.path, input.asFile.path)
8070
}
8171

8272
val binariesFolder = project.layout.buildDirectory.dir("binaries/desktop")
@@ -233,22 +223,6 @@ kotlin {
233223
compileTaskProvider {
234224
compilerOptions.freeCompilerArgs.add("-Xexport-kdoc")
235225
}
236-
237-
cinterops.create("sqlite") {
238-
val cInteropTask = tasks[interopProcessingTaskName]
239-
cInteropTask.dependsOn(buildCInteropDef)
240-
definitionFile =
241-
buildCInteropDef
242-
.get()
243-
.outputs.files.singleFile
244-
compilerOpts.addAll(
245-
listOf(
246-
"-DHAVE_GETHOSTUUID=0",
247-
"-DSQLITE_ENABLE_LOAD_EXTENSION=1",
248-
"-DSQLITE_ENABLE_FTS5",
249-
),
250-
)
251-
}
252226
}
253227

254228
if (konanTarget.family == Family.IOS && konanTarget.name.contains("simulator")) {
@@ -428,27 +402,4 @@ val testWithJava8 by tasks.registering(KotlinJvmTest::class) {
428402
}
429403
tasks.named("check").configure { dependsOn(testWithJava8) }
430404

431-
afterEvaluate {
432-
val buildTasks =
433-
tasks.matching {
434-
val taskName = it.name
435-
if (taskName.contains("Clean")) {
436-
return@matching false
437-
}
438-
if (taskName.contains("externalNative") ||
439-
taskName.contains("CMake") ||
440-
taskName.contains(
441-
"generateJsonModel",
442-
)
443-
) {
444-
return@matching true
445-
}
446-
return@matching false
447-
}
448-
449-
buildTasks.forEach {
450-
it.dependsOn(buildCInteropDef)
451-
}
452-
}
453-
454405
setupGithubRepository()

core/src/iosMain/kotlin/com/powersync/DatabaseDriverFactory.ios.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import co.touchlab.sqliter.DatabaseConfiguration.Logging
55
import co.touchlab.sqliter.DatabaseConnection
66
import co.touchlab.sqliter.interop.Logger
77
import co.touchlab.sqliter.interop.SqliteErrorType
8+
import co.touchlab.sqliter.sqlite3.sqlite3_commit_hook
9+
import co.touchlab.sqliter.sqlite3.sqlite3_enable_load_extension
10+
import co.touchlab.sqliter.sqlite3.sqlite3_load_extension
11+
import co.touchlab.sqliter.sqlite3.sqlite3_rollback_hook
12+
import co.touchlab.sqliter.sqlite3.sqlite3_update_hook
813
import com.powersync.db.internal.InternalSchema
914
import com.powersync.persistence.driver.NativeSqliteDriver
1015
import com.powersync.persistence.driver.wrapConnection
11-
import com.powersync.sqlite3.sqlite3
12-
import com.powersync.sqlite3.sqlite3_commit_hook
13-
import com.powersync.sqlite3.sqlite3_enable_load_extension
14-
import com.powersync.sqlite3.sqlite3_load_extension
15-
import com.powersync.sqlite3.sqlite3_rollback_hook
16-
import com.powersync.sqlite3.sqlite3_update_hook
1716
import kotlinx.cinterop.ByteVar
1817
import kotlinx.cinterop.CPointerVar
1918
import kotlinx.cinterop.ExperimentalForeignApi
@@ -103,7 +102,7 @@ public actual class DatabaseDriverFactory {
103102
connection: DatabaseConnection,
104103
driver: DeferredDriver,
105104
) {
106-
val basePointer = connection.getDbPointer().getPointer(MemScope())
105+
val ptr = connection.getDbPointer().getPointer(MemScope())
107106
// Try and find the bundle path for the SQLite core extension.
108107
val bundlePath =
109108
NSBundle.bundleWithIdentifier("co.powersync.sqlitecore")?.bundlePath
@@ -116,10 +115,6 @@ public actual class DatabaseDriverFactory {
116115
// Construct full path to the shared library inside the bundle
117116
val extensionPath = bundlePath.let { "$it/powersync-sqlite-core" }
118117

119-
// We have a mix of SQLite operations. The SQliteR lib links to the system SQLite with `-lsqlite3`
120-
// However we also include our own build of SQLite which is statically linked.
121-
// Loading of extensions is only available using our version of SQLite's API
122-
val ptr = basePointer.reinterpret<sqlite3>()
123118
// Enable extension loading
124119
// We don't disable this after the fact, this should allow users to load their own extensions
125120
// in future.
@@ -183,13 +178,8 @@ public actual class DatabaseDriverFactory {
183178
private fun deregisterSqliteBinding(connection: DatabaseConnection) {
184179
val basePtr = connection.getDbPointer().getPointer(MemScope())
185180

186-
// We have a mix of SQLite operations. The SQliteR lib links to the system SQLite with `-lsqlite3`
187-
// However we also include our own build of SQLite which is statically linked.
188-
// Loading of extensions is only available using our version of SQLite's API
189-
val ptr = basePtr.reinterpret<sqlite3>()
190-
191181
sqlite3_update_hook(
192-
ptr,
182+
basePtr.reinterpret(),
193183
null,
194184
null,
195185
)

0 commit comments

Comments
 (0)