-
Notifications
You must be signed in to change notification settings - Fork 42
Implement linux target #38
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
Merged
kpgalligan
merged 14 commits into
touchlab:main
from
chippmann:feature/support_linux_target
Jun 24, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e2055c1
Implement linux target and actual implementations
chippmann fd99e1f
Fix invalid link argument on macOS and add build and deploy configs f…
chippmann b438605
Testwise remove explicit search path
chippmann 9f1b6a8
Remove explicit install of sqlite as on gihub action vm's it's alread…
chippmann 9420853
Fix windows linking args and fix formatting
chippmann 4dc0a19
Prevent cross compilation on ci
chippmann 8e1ff39
Fix linking for mingw
chippmann 9e21b62
Cleanup some little issues copied from the osx impl
chippmann e48aa74
Format
chippmann 1bef315
Prevent cross compilation
chippmann a4667eb
Cleanup
chippmann 6813369
Re add watchosX64
chippmann e96d980
Add change made to mingw impl
chippmann 6239ec2
Set ubuntu version to 18.04 to use an older glib version
chippmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
sqliter-driver/src/linuxX64Main/kotlin/co/touchlab/sqliter/DatabaseFileContext.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package co.touchlab.sqliter | ||
|
||
import co.touchlab.sqliter.internal.File | ||
import co.touchlab.sqliter.internal.FileFilter | ||
import kotlinx.cinterop.memScoped | ||
import kotlinx.cinterop.refTo | ||
import kotlinx.cinterop.toKString | ||
import platform.posix.NULL | ||
import platform.posix.PATH_MAX | ||
import platform.posix.getcwd | ||
import platform.posix.getenv | ||
|
||
actual object DatabaseFileContext { | ||
actual fun deleteDatabase(name: String, basePath: String?) { | ||
deleteDatabaseFile(databaseFile(name, basePath)) | ||
} | ||
|
||
actual fun databasePath(databaseName: String, datapathPath: String?): String { | ||
return databaseFile(databaseName, datapathPath).path | ||
} | ||
|
||
internal fun databaseDirPath(): String { | ||
return getHomeDirPath() ?: memScoped { | ||
val buff = ByteArray(PATH_MAX) | ||
if (getcwd(buff.refTo(0), buff.size.toULong()) != NULL) { | ||
return buff.toKString() | ||
} | ||
throw IllegalStateException("Cannot get home dir or current dir") | ||
} | ||
} | ||
|
||
internal fun getHomeDirPath(): String? = getenv("HOME")?.toKString() | ||
|
||
internal fun databaseFile(databaseName: String, datapathPath: String?): File = | ||
File(datapathPath ?: databaseDirPath(), 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() | ||
|
||
//TODO: Implement file list | ||
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 | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
sqliter-driver/src/linuxX64Main/kotlin/co/touchlab/sqliter/concurrency/Lock.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package co.touchlab.sqliter.concurrency | ||
|
||
import kotlinx.cinterop.Arena | ||
import kotlinx.cinterop.alloc | ||
import kotlinx.cinterop.ptr | ||
import platform.posix.* | ||
import kotlin.native.concurrent.freeze | ||
|
||
/** | ||
* A simple lock. | ||
* Implementations of this class should be re-entrant. | ||
*/ | ||
actual class Lock actual constructor() { | ||
private val arena = Arena() | ||
private val attr = arena.alloc<pthread_mutexattr_t>() | ||
private val mutex = arena.alloc<pthread_mutex_t>() | ||
|
||
init { | ||
pthread_mutexattr_init(attr.ptr) | ||
pthread_mutexattr_settype(attr.ptr, PTHREAD_MUTEX_RECURSIVE.toInt()) | ||
pthread_mutex_init(mutex.ptr, attr.ptr) | ||
freeze() | ||
} | ||
|
||
actual fun lock() { | ||
pthread_mutex_lock(mutex.ptr) | ||
} | ||
|
||
actual fun unlock() { | ||
pthread_mutex_unlock(mutex.ptr) | ||
} | ||
|
||
actual fun tryLock(): Boolean = pthread_mutex_trylock(mutex.ptr) == 0 | ||
|
||
fun internalClose() { | ||
pthread_mutex_destroy(mutex.ptr) | ||
pthread_mutexattr_destroy(attr.ptr) | ||
arena.clear() | ||
} | ||
} | ||
|
||
actual inline fun Lock.close() { | ||
internalClose() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually here I'm not sure where the fallback path should lead to?
I just defined the
home
dir but of course this is suboptimal. But another arbitrary fallback dir is also IMO. But you did something similar on windows as well and one should configure the path anyways in most cases.Maybe you have a preference where the fallback path should be? Or is
home
fine for you?