Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add windows support #3

Open
wants to merge 1 commit into
base: daniel/splitOutAppleCode
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions SQLiter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ buildscript {
apply plugin: 'org.jetbrains.kotlin.multiplatform'

repositories {
// mavenLocal()
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
Expand All @@ -39,6 +38,16 @@ kotlin {
}
}

fromPreset(presets.mingwX64, 'mingw'){
compilations.each {
it.extraOpts("-linker-options", "-Lc:\\msys64\\mingw64\\lib")
it.extraOpts("-linker-options", "-lsqlite3")
}
compilations.test {
it.extraOpts("-native-library", "../KotlinCpp/bcdist/mingw_x64/tlruntime.bc")
}
}

fromPreset(presets.iosX64, 'iosX64'){
compilations.each {
it.extraOpts("-linker-options", "-lsqlite3")
Expand Down Expand Up @@ -91,6 +100,11 @@ kotlin {
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
}
mingwMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
}
}

nativeCommonMain { }
nativeCommonTest { }
Expand All @@ -99,11 +113,15 @@ kotlin {
dependsOn nativeCommonMain
}

configure([mingwMain]) {
dependsOn nativeCommonMain
}

configure([iosX64Main, iosArm64Main, macosMain, iosArm32Main]) {
dependsOn appleMain
}

configure([iosX64Test, iosArm64Test, macosTest, iosArm32Test]) {
configure([iosX64Test, iosArm64Test, macosTest, iosArm32Test, mingwTest]) {
dependsOn nativeCommonTest
}
}
Expand Down Expand Up @@ -133,6 +151,7 @@ task mergeCppAll(dependsOn:build) {
mergeCppOutput("iosArm64", "ios_arm64")
mergeCppOutput("iosX64", "ios_x64")
mergeCppOutput("macos", "macos_x64")
mergeCppOutput("mingw", "mingw_x64")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package co.touchlab.sqliter

import co.touchlab.sqliter.internal.File
import co.touchlab.sqliter.internal.FileFilter
import co.touchlab.sqliter.internal.Utils

actual object DatabaseFileContext {
actual fun deleteDatabase(name: String, basePath:String?) {
deleteDatabaseFile(databaseFile(name, basePath))
}

internal fun databasePath(databaseName:String, inMemory:Boolean, datapathPath:String?):String {
return if(inMemory) {
"file:$databaseName?mode=memory&cache=shared"
} else {
databaseFile(databaseName, datapathPath).path
}
}

internal fun databaseFile(databaseName:String, datapathPath:String?):File {
return File(datapathPath ?: Utils.getUserDirectory(), databaseName)
}

internal fun deleteDatabaseFile(file:File):Boolean {
var deleted = false
deleted = deleted or file.delete()
deleted = deleted or File(file.getPath() + "-journal").delete()
deleted = deleted or File(file.getPath() + "-shm").delete()
deleted = deleted or File(file.getPath() + "-wal").delete()

val dir = file.getParentFile()
if (dir != null) {
val prefix = file.getName() + "-mj"
val files = dir.listFiles(object: FileFilter {
override fun accept(candidate: File):Boolean {
return candidate.getName().startsWith(prefix)
}
})
if (files != null) {
for (masterJournal in files) {
deleted = deleted or masterJournal.delete()
}
}
}
return deleted
}
}
Loading