Skip to content

Commit 59b76d0

Browse files
committed
Merging
2 parents 945921e + 512a5b1 commit 59b76d0

File tree

18 files changed

+663
-41
lines changed

18 files changed

+663
-41
lines changed
29.9 KB
Binary file not shown.
10.1 KB
Binary file not shown.
12.1 KB
Binary file not shown.
18.9 KB
Binary file not shown.

KotlinCpp/knarch/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ import org.jetbrains.kotlin.CompileCppToBitcode
2020

2121
targetList.each { targetName ->
2222
if(
23-
targetName.contains("ios") || targetName.contains("macos")
23+
targetName.contains("ios") || targetName.contains("macos") || targetName.contains("mingw")
2424
) {
2525
task("${targetName}TLRuntime", type: CompileCppToBitcode) {
2626
name "tlruntime"
2727
srcRoot file('src/main')
2828
target targetName
29-
if (!isWindows())
29+
if (!isWindows()) {
3030
compilerArgs '-fPIC'
31+
} else {
32+
// When compiling on windows you need to have installed msys2, then use that to install sqlite3
33+
compilerArgs '-Ic:\\msys64\\mingw64\\include'
34+
}
3135
compilerArgs '-I' + project.file("${konanDevPath}/common/src/hash/headers")
3236
compilerArgs '-I' + project.file("${konanDevPath}/runtime/src/main/cpp")
3337
if (rootProject.hasProperty("${targetName}LibffiDir"))
@@ -37,7 +41,8 @@ targetList.each { targetName ->
3741
}
3842

3943
task distTlRuntime(type: Copy) {
40-
dependsOn.addAll(targetList.findAll {it.contains("ios") || it.contains("macos")}.collect { "${it}TLRuntime" })
44+
dependsOn.addAll(targetList.findAll {it.contains("ios") || it.contains("macos") || it.contains("mingw")}
45+
.collect { "${it}TLRuntime" })
4146
}
4247

4348

KotlinCpp/knarch/src/main/cpp/KonanHelper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <stdio.h>
2121
#include <string.h>
2222
#include <unistd.h>
23-
23+
#include <stdarg.h>
2424

2525
#include <iterator>
2626
#include <string>
@@ -42,8 +42,6 @@
4242

4343
#include "utf8.h"
4444

45-
#include <dispatch/dispatch.h>
46-
4745
extern "C" {
4846
//TODO: Review everything that uses this and make sure we need
4947
char *CreateCStringFromStringWithSize(KString kstring, size_t *utf8Size) {

KotlinCpp/knarch/src/main/cpp/SQLiteConnection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "utf8.h"
2727

2828
#include <stdlib.h>
29-
#include <sys/mman.h>
3029

3130
#include <string.h>
3231
#include <unistd.h>
@@ -315,6 +314,10 @@ KLong SQLiter_SQLiteConnection_nativeOpen(KString pathStr, KInt openFlags,
315314
sqliteFlags = SQLITE_OPEN_READWRITE;
316315
}
317316

317+
// This ensures that regardless of how sqlite was compiled it will support uri file paths.
318+
// this is important for using in memory databases.
319+
sqliteFlags |= SQLITE_OPEN_URI;
320+
318321
size_t utf8Size;
319322
char * path = CreateCStringFromStringWithSize(pathStr, &utf8Size);
320323
char * label = CreateCStringFromStringWithSize(labelStr, &utf8Size);

SQLiter/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ buildscript {
1313
apply plugin: 'org.jetbrains.kotlin.multiplatform'
1414

1515
repositories {
16-
// mavenLocal()
1716
mavenCentral()
1817
maven {
1918
url 'https://oss.sonatype.org/content/repositories/snapshots/'
@@ -37,6 +36,16 @@ kotlin {
3736
}
3837
}
3938

39+
fromPreset(presets.mingwX64, 'mingw'){
40+
compilations.each {
41+
it.extraOpts("-linker-options", "-Lc:\\msys64\\mingw64\\lib")
42+
it.extraOpts("-linker-options", "-lsqlite3")
43+
}
44+
compilations.test {
45+
it.extraOpts("-native-library", "../KotlinCpp/bcdist/mingw_x64/tlruntime.bc")
46+
}
47+
}
48+
4049
fromPreset(presets.iosX64, 'iosX64'){
4150
compilations.test {
4251
it.extraOpts("-linker-options", "-lsqlite3")
@@ -83,6 +92,11 @@ kotlin {
8392
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
8493
}
8594
}
95+
mingwMain {
96+
dependencies {
97+
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
98+
}
99+
}
86100

87101
nativeCommonMain { }
88102
nativeCommonTest { }
@@ -91,11 +105,15 @@ kotlin {
91105
dependsOn nativeCommonMain
92106
}
93107

108+
configure([mingwMain]) {
109+
dependsOn nativeCommonMain
110+
}
111+
94112
configure([iosX64Main, iosArm64Main, macosMain, iosArm32Main]) {
95113
dependsOn appleMain
96114
}
97115

98-
configure([iosX64Test, iosArm64Test, macosTest, iosArm32Test]) {
116+
configure([iosX64Test, iosArm64Test, macosTest, iosArm32Test, mingwTest]) {
99117
dependsOn nativeCommonTest
100118
}
101119
}
@@ -125,6 +143,7 @@ task mergeCppAll(dependsOn:build) {
125143
mergeCppOutput("iosArm64", "ios_arm64")
126144
mergeCppOutput("iosX64", "ios_x64")
127145
mergeCppOutput("macos", "macos_x64")
146+
mergeCppOutput("mingw", "mingw_x64")
128147
}
129148
}
130149

SQLiter/gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
kotlin.code.style=official
1818

1919
GROUP=co.touchlab
20-
VERSION_NAME=0.6.1
20+
VERSION_NAME=0.6.2
2121

22-
STATELY_VERSION=0.7.1
23-
KOTLIN_VERSION=1.3.30
22+
STATELY_VERSION=0.7.2
23+
KOTLIN_VERSION=1.3.31
2424

2525
POM_URL=https://github.com/touchlab/SQLiter
2626
POM_DESCRIPTION=Simple SQLite Driver
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package co.touchlab.sqliter
2+
3+
import co.touchlab.sqliter.internal.File
4+
import co.touchlab.sqliter.internal.FileFilter
5+
import co.touchlab.sqliter.internal.Utils
6+
7+
actual object DatabaseFileContext {
8+
actual fun deleteDatabase(name: String, basePath:String?) {
9+
deleteDatabaseFile(databaseFile(name, basePath))
10+
}
11+
12+
internal fun databasePath(databaseName:String, inMemory:Boolean, datapathPath:String?):String {
13+
return if(inMemory) {
14+
"file:$databaseName?mode=memory&cache=shared"
15+
} else {
16+
databaseFile(databaseName, datapathPath).path
17+
}
18+
}
19+
20+
internal fun databaseFile(databaseName:String, datapathPath:String?):File {
21+
return File(datapathPath ?: Utils.getUserDirectory(), databaseName)
22+
}
23+
24+
internal fun deleteDatabaseFile(file:File):Boolean {
25+
var deleted = false
26+
deleted = deleted or file.delete()
27+
deleted = deleted or File(file.getPath() + "-journal").delete()
28+
deleted = deleted or File(file.getPath() + "-shm").delete()
29+
deleted = deleted or File(file.getPath() + "-wal").delete()
30+
31+
val dir = file.getParentFile()
32+
if (dir != null) {
33+
val prefix = file.getName() + "-mj"
34+
val files = dir.listFiles(object: FileFilter {
35+
override fun accept(candidate: File):Boolean {
36+
return candidate.getName().startsWith(prefix)
37+
}
38+
})
39+
if (files != null) {
40+
for (masterJournal in files) {
41+
deleted = deleted or masterJournal.delete()
42+
}
43+
}
44+
}
45+
return deleted
46+
}
47+
}

0 commit comments

Comments
 (0)