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

Default hierarchy template #9

Merged
merged 2 commits into from
Dec 15, 2023
Merged
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
21 changes: 9 additions & 12 deletions buildSrc/src/main/kotlin/multiplatform-convention.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ kotlin {
* │ common │
* └───┬────┘
* ┌──────────┴───────────┐
* │ ┌──────┴───────┐
* │ │ nativeCommon
* │ └──────┬───────┘
* │ ┌───────┐
* │ │ native
* │ └───────┘
* │ ┌──────────┴──────────┐
* ┌─────┴─────┐ ┌───┴───┐ ┌───────┐
* │ jvmCommon │ │ apple │ │ native
* └─────┬─────┘ └───┬───┘ └───────┘
* ┌─────┴─────┐ ┌───┴───┐ ┌─────┴──────┐
* │ jvmCommon │ │ apple │ │ linuxMingw
* └─────┬─────┘ └───┬───┘ └─────┬──────┘
* ┌────┴────┐ │ ┌─────────────┼─────────────┐
* ╔════╩════╗ ╔══╩══╗ │ ╔════╩═════╗ ╔═════╩══════╗ ╔════╩═════╗
* ║ android ║ ║ jvm ║ │ ║ linuxX64 ║ ║ linuxArm64 ║ ║ mingwX64 ║
Expand All @@ -29,17 +29,14 @@ kotlin {
*/

@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyHierarchyTemplate {
applyDefaultHierarchyTemplate {
common {
group("jvmCommon") {
withAndroidTarget()
withJvm()
}
group("nativeCommon") {
group("apple") {
withApple()
}
group("native") {
group("native") {
group("linuxMingw") {
withLinux()
withMingw()
}
Expand Down
1 change: 1 addition & 0 deletions couchbase-lite-ee/src/linuxMingwMain/kotlin
1 change: 1 addition & 0 deletions couchbase-lite-ee/src/linuxMingwTest/kotlin
1 change: 0 additions & 1 deletion couchbase-lite-ee/src/nativeCommonMain/kotlin

This file was deleted.

1 change: 0 additions & 1 deletion couchbase-lite-ee/src/nativeTest/kotlin

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2022-2023 Jeff Lockhart
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotbase.util

import kotlinx.cinterop.*

internal inline operator fun <reified T : CStructVar> CPointer<T>?.plus(index: Int): CPointer<T>? =
interpretCPointer(this.rawValue + index * sizeOf<T>())

internal inline operator fun <reified T : CStructVar> CPointer<T>.get(index: Int): T =
(this + index)!!.pointed

internal inline fun <reified T : CStructVar, R> CPointer<T>.toList(
size: Int,
transform: (CPointer<T>) -> R
): List<R> {
val array = this
return buildList(size) {
repeat(size) { i ->
add(transform(array[i].ptr))
}
}
}

internal inline fun <reified T : Any> CPointer<*>?.to(): T = this!!.asStableRef<T>().get()

This file was deleted.

25 changes: 5 additions & 20 deletions couchbase-lite/src/nativeMain/kotlin/kotbase/util/Utils.native.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,9 @@
*/
package kotbase.util

import kotlinx.cinterop.*
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.identityHashCode

internal inline operator fun <reified T : CStructVar> CPointer<T>?.plus(index: Int): CPointer<T>? =
interpretCPointer(this.rawValue + index * sizeOf<T>())

internal inline operator fun <reified T : CStructVar> CPointer<T>.get(index: Int): T =
(this + index)!!.pointed

internal inline fun <reified T : CStructVar, R> CPointer<T>.toList(
size: Int,
transform: (CPointer<T>) -> R
): List<R> {
val array = this
return buildList(size) {
repeat(size) { i ->
add(transform(array[i].ptr))
}
}
}

internal inline fun <reified T : Any> CPointer<*>?.to(): T = this!!.asStableRef<T>().get()
@OptIn(ExperimentalNativeApi::class)
internal fun Any?.identityHashCodeHex(): String =
"0x${identityHashCode().toUInt().toString(16)}"
10 changes: 5 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ https://www.jetbrains.com/lp/compose-multiplatform/).
https://blog.jetbrains.com/kotlin/2023/08/compose-multiplatform-1-5-0-release/) for copying resources since version
1.5.0. However, the `getting-started-compose` example still [uses CocoaPods for linking the Couchbase Lite
framework](
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started-compose/shared/build.gradle.kts#L22-L25).
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started-compose/shared/build.gradle.kts#L23-L26).
See the [`getting-started`](
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/build.gradle.kts#L17-L33) version for
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/build.gradle.kts#L14-L30) version for
an example of how to link the Couchbase Lite framework without using CocoaPods.

### JVM Desktop App :fontawesome-brands-java:
Expand All @@ -203,7 +203,7 @@ Using the apps with Sync Gateway and Couchbase Server obviously requires you hav
See also — [Install Sync Gateway](https://docs.couchbase.com/sync-gateway/current/get-started-install.html)

Once you have Sync Gateway configured, update the `ReplicatorConfiguration` [in the app](
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/src/commonMain/kotlin/dev/kotbase/gettingstarted/shared/SharedDbWork.kt#L90)
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/src/commonMain/kotlin/dev/kotbase/gettingstarted/shared/SharedDbWork.kt#L90-L93)
with the server's URL endpoint and authentication credentials.

## Kotlin Multiplatform Tips
Expand All @@ -212,7 +212,7 @@ with the server's URL endpoint and authentication credentials.

The apps utilize the Kotlin Multiplatform [`expect`/`actual` feature](
https://kotlinlang.org/docs/multiplatform-connect-to-apis.html) to populate the created document with [the platform](
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/src/commonMain/kotlin/dev/kotbase/gettingstarted/shared/SharedDbWork.kt#L30)
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/src/commonMain/kotlin/dev/kotbase/gettingstarted/shared/SharedDbWork.kt#L29)
the app is running on.

See common [`expect fun getPlatform()`](
Expand All @@ -234,7 +234,7 @@ https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/sr

The `getting-started` app uses [KMP-NativeCoroutines](https://github.com/rickclephas/KMP-NativeCoroutines) to consume
Kotlin `Flow`s in Swift. See [`@NativeCoroutines` annotation](
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/src/commonMain/kotlin/dev/kotbase/gettingstarted/shared/SharedDbWork.kt#L85)
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/shared/src/commonMain/kotlin/dev/kotbase/gettingstarted/shared/SharedDbWork.kt#L84)
in Kotlin and [`asyncSequence(for:)`](
https://github.com/jeffdgr8/kotbase/blob/main/examples/getting-started/iosApp/iosApp/ContentView.swift#L98) in Swift
code.
Expand Down
2 changes: 1 addition & 1 deletion testing-support-ee/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ kotlin {
api(libs.androidx.test.runner)
}
}
nativeCommonMain {
nativeMain {
dependencies {
implementation(libs.korlibs.korio)
}
Expand Down
2 changes: 1 addition & 1 deletion testing-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ kotlin {
api(libs.androidx.test.runner)
}
}
nativeCommonMain {
nativeMain {
dependencies {
implementation(libs.korlibs.korio)
}
Expand Down