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

Support compiling the SDK with Kotlin 2 (#1721) #1727

Merged
merged 1 commit into from
Apr 23, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ This release will bump the Realm file format from version 23 to 24. Opening a fi
* Deprecated Jenkins and switching to Github Action ([JIRA]https://jira.mongodb.org/browse/RKOTLIN-825).
- Remove CMake required version.
* Updated URL to documentation.
* Refactored to allow compilation with Kotlin 2.0



## 1.14.1 (2024-03-19)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ expect enum class ErrorCategory : CodeDescription {
RLM_ERR_CAT_WEBSOCKET_ERROR,
RLM_ERR_CAT_SYNC_ERROR;

override val nativeValue: Int
override val description: String?

companion object {
internal fun of(nativeValue: Int): ErrorCategory?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ expect enum class ErrorCode : CodeDescription {
RLM_ERR_CALLBACK,
RLM_ERR_UNKNOWN;

override val nativeValue: Int
override val description: String?

companion object {
fun of(nativeValue: Int): ErrorCode?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ expect enum class SyncConnectionErrorCode : CodeDescription {
RLM_SYNC_ERR_CONNECTION_SWITCH_TO_FLX_SYNC,
RLM_SYNC_ERR_CONNECTION_SWITCH_TO_PBS;

override val nativeValue: Int
override val description: String?

companion object {
internal fun of(nativeValue: Int): SyncConnectionErrorCode?
}
Expand Down Expand Up @@ -86,6 +89,9 @@ expect enum class SyncSessionErrorCode : CodeDescription {
RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION,
RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED;

override val nativeValue: Int
override val description: String?

companion object {
internal fun of(nativeValue: Int): SyncSessionErrorCode?
}
Expand Down Expand Up @@ -122,6 +128,9 @@ expect enum class WebsocketErrorCode : CodeDescription {
RLM_ERR_WEBSOCKET_RETRY_ERROR,
RLM_ERR_WEBSOCKET_FATAL_ERROR;

override val nativeValue: Int
override val description: String?

companion object {
fun of(nativeValue: Int): WebsocketErrorCode?
}
Expand All @@ -141,6 +150,9 @@ expect enum class WebsocketCallbackResult : CodeDescription {
RLM_ERR_SYNC_SOCKET_NOT_SUPPORTED,
RLM_ERR_SYNC_SOCKET_INVALID_ARGUMENT;

override val nativeValue: Int
override val description: String?

companion object {
fun of(nativeValue: Int): WebsocketCallbackResult?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.realm.kotlin.internal.interop

actual enum class ErrorCategory(
override val description: String,
override val nativeValue: Int
actual override val description: String?,
actual override val nativeValue: Int
) : CodeDescription {
RLM_ERR_CAT_LOGIC("Logic", realm_error_category_e.RLM_ERR_CAT_LOGIC),
RLM_ERR_CAT_RUNTIME("Runtime", realm_error_category_e.RLM_ERR_CAT_RUNTIME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.realm.kotlin.internal.interop

actual enum class ErrorCode(override val description: String, override val nativeValue: Int) :
actual enum class ErrorCode(actual override val description: String?, actual override val nativeValue: Int) :
CodeDescription {
RLM_ERR_NONE("None", realm_errno_e.RLM_ERR_NONE),
RLM_ERR_RUNTIME("Runtime", realm_errno_e.RLM_ERR_RUNTIME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import io.realm.kotlin.internal.interop.realm_sync_socket_callback_result_e
import io.realm.kotlin.internal.interop.realm_web_socket_errno_e

actual enum class SyncConnectionErrorCode(
override val description: String,
override val nativeValue: Int
actual override val description: String?,
actual override val nativeValue: Int
) : CodeDescription {
RLM_SYNC_ERR_CONNECTION_CONNECTION_CLOSED("ConnectionClosed", realm_sync_errno_connection_e.RLM_SYNC_ERR_CONNECTION_CONNECTION_CLOSED),
RLM_SYNC_ERR_CONNECTION_OTHER_ERROR("OtherError", realm_sync_errno_connection_e.RLM_SYNC_ERR_CONNECTION_OTHER_ERROR),
Expand All @@ -51,8 +51,8 @@ actual enum class SyncConnectionErrorCode(
}

actual enum class SyncSessionErrorCode(
override val description: String,
override val nativeValue: Int
actual override val description: String?,
actual override val nativeValue: Int
) : CodeDescription {
RLM_SYNC_ERR_SESSION_SESSION_CLOSED("SessionClosed", realm_sync_errno_session_e.RLM_SYNC_ERR_SESSION_SESSION_CLOSED),
RLM_SYNC_ERR_SESSION_OTHER_SESSION_ERROR("OtherSessioError", realm_sync_errno_session_e.RLM_SYNC_ERR_SESSION_OTHER_SESSION_ERROR),
Expand Down Expand Up @@ -100,8 +100,8 @@ actual enum class SyncSessionErrorCode(
}

actual enum class WebsocketErrorCode(
override val description: String,
override val nativeValue: Int
actual override val description: String?,
actual override val nativeValue: Int
) : CodeDescription {
RLM_ERR_WEBSOCKET_OK("Ok", realm_web_socket_errno_e.RLM_ERR_WEBSOCKET_OK),
RLM_ERR_WEBSOCKET_GOINGAWAY("GoingAway", realm_web_socket_errno_e.RLM_ERR_WEBSOCKET_GOINGAWAY),
Expand Down Expand Up @@ -139,7 +139,7 @@ actual enum class WebsocketErrorCode(
}
}

actual enum class WebsocketCallbackResult(override val description: String, override val nativeValue: Int) : CodeDescription {
actual enum class WebsocketCallbackResult(actual override val description: String?, actual override val nativeValue: Int) : CodeDescription {

RLM_ERR_SYNC_SOCKET_SUCCESS(
"Websocket callback success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import realm_wrapper.realm_error_category
* Error categories are composed of multiple categories in once, it is a flag property.
*/
actual enum class ErrorCategory(
override val description: String,
override val nativeValue: Int
actual override val description: String?,
actual override val nativeValue: Int
) : CodeDescription {
RLM_ERR_CAT_LOGIC("Logic", realm_error_category.RLM_ERR_CAT_LOGIC.value.toInt()),
RLM_ERR_CAT_RUNTIME("Runtime", realm_error_category.RLM_ERR_CAT_RUNTIME.value.toInt()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package io.realm.kotlin.internal.interop
import realm_wrapper.realm_errno

actual enum class ErrorCode(
override val description: String,
actual override val description: String?,
nativeError: realm_errno
) : CodeDescription {
RLM_ERR_NONE("None", realm_errno.RLM_ERR_NONE),
Expand Down Expand Up @@ -186,7 +186,7 @@ actual enum class ErrorCode(
RLM_ERR_CALLBACK("Callback", realm_errno.RLM_ERR_CALLBACK),
RLM_ERR_UNKNOWN("Unknown", realm_errno.RLM_ERR_UNKNOWN);

override val nativeValue: Int = nativeError.value.toInt()
actual override val nativeValue: Int = nativeError.value.toInt()

val asNativeEnum: realm_errno = nativeError

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import realm_wrapper.realm_sync_socket_callback_result
import realm_wrapper.realm_web_socket_errno

actual enum class SyncConnectionErrorCode(
override val description: String,
actual override val description: String?,
errorCode: realm_sync_errno_connection
) : CodeDescription {
RLM_SYNC_ERR_CONNECTION_CONNECTION_CLOSED("ConnectionClosed", realm_sync_errno_connection.RLM_SYNC_ERR_CONNECTION_CONNECTION_CLOSED),
Expand All @@ -41,7 +41,7 @@ actual enum class SyncConnectionErrorCode(
RLM_SYNC_ERR_CONNECTION_SWITCH_TO_FLX_SYNC("SwitchToFlxSync", realm_sync_errno_connection.RLM_SYNC_ERR_CONNECTION_SWITCH_TO_FLX_SYNC),
RLM_SYNC_ERR_CONNECTION_SWITCH_TO_PBS("SwitchToPbs", realm_sync_errno_connection.RLM_SYNC_ERR_CONNECTION_SWITCH_TO_PBS);

override val nativeValue: Int = errorCode.value.toInt()
actual override val nativeValue: Int = errorCode.value.toInt()

actual companion object {
internal actual fun of(nativeValue: Int): SyncConnectionErrorCode? =
Expand All @@ -52,7 +52,7 @@ actual enum class SyncConnectionErrorCode(
}

actual enum class SyncSessionErrorCode(
override val description: String,
actual override val description: String?,
errorCode: realm_sync_errno_session
) : CodeDescription {
RLM_SYNC_ERR_SESSION_SESSION_CLOSED("SessionClosed", realm_sync_errno_session.RLM_SYNC_ERR_SESSION_SESSION_CLOSED),
Expand Down Expand Up @@ -92,7 +92,7 @@ actual enum class SyncSessionErrorCode(
RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION("BadSchemaVersion", realm_sync_errno_session.RLM_SYNC_ERR_SESSION_BAD_SCHEMA_VERSION),
RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED("SchemaVersionChanged", realm_sync_errno_session.RLM_SYNC_ERR_SESSION_SCHEMA_VERSION_CHANGED);

override val nativeValue: Int = errorCode.value.toInt()
actual override val nativeValue: Int = errorCode.value.toInt()

actual companion object {
internal actual fun of(nativeValue: Int): SyncSessionErrorCode? =
Expand All @@ -103,7 +103,7 @@ actual enum class SyncSessionErrorCode(
}

actual enum class WebsocketErrorCode(
override val description: String,
actual override val description: String?,
errorCode: realm_web_socket_errno,
) : CodeDescription {
RLM_ERR_WEBSOCKET_OK("Ok", realm_web_socket_errno.RLM_ERR_WEBSOCKET_OK),
Expand Down Expand Up @@ -132,7 +132,7 @@ actual enum class WebsocketErrorCode(
RLM_ERR_WEBSOCKET_RETRY_ERROR("RetryError", realm_web_socket_errno.RLM_ERR_WEBSOCKET_RETRY_ERROR),
RLM_ERR_WEBSOCKET_FATAL_ERROR("FatalError", realm_web_socket_errno.RLM_ERR_WEBSOCKET_FATAL_ERROR);

override val nativeValue: Int = errorCode.value.toInt()
actual override val nativeValue: Int = errorCode.value.toInt()

val asNativeEnum: realm_web_socket_errno = errorCode

Expand All @@ -145,7 +145,7 @@ actual enum class WebsocketErrorCode(
}

actual enum class WebsocketCallbackResult(
override val description: String,
actual override val description: String?,
nativeError: realm_sync_socket_callback_result
) : CodeDescription {

Expand Down Expand Up @@ -182,7 +182,7 @@ actual enum class WebsocketCallbackResult(
realm_sync_socket_callback_result.RLM_ERR_SYNC_SOCKET_INVALID_ARGUMENT
);

override val nativeValue: Int = nativeError.value.toInt()
actual override val nativeValue: Int = nativeError.value.toInt()
val asNativeEnum: realm_sync_socket_callback_result = nativeError

actual companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@ private fun gatherTargetInfo(kotlinCompilation: KotlinCompilation<*>): TargetInf
Family.WATCHOS -> cocoapods.watchos.deploymentTarget
Family.LINUX,
Family.MINGW,
Family.ANDROID,
Family.WASM,
Family.ZEPHYR -> null // Not supported yet
Family.ANDROID -> null // Not supported yet
// TODO 1.9-DEPRECATION Revert to exhaustive branch strategy when leaving 1.9 support
// Remaining options are removed in Kotlin 2, so cannot reference them but need
// an else clause to be exhaustive
// Family.WASM,
// Family.ZEPHYR,
else -> null
}
}
TargetInfo(
Expand Down Expand Up @@ -349,8 +353,6 @@ fun nativeTarget(target: KonanTarget) = when (target.family) {
Family.LINUX -> "Linux"
Family.MINGW -> "MinGW"
Family.ANDROID -> "Android(native)"
Family.WASM -> "Wasm"
Family.ZEPHYR -> "Zephyr"
else -> unknown(target.family.name)
}

Expand All @@ -361,9 +363,6 @@ fun nativeArch(target: KonanTarget): String = try {
Architecture.X86 -> io.realm.kotlin.gradle.analytics.Architecture.X86.serializedName
Architecture.ARM64 -> io.realm.kotlin.gradle.analytics.Architecture.ARM64.serializedName
Architecture.ARM32 -> io.realm.kotlin.gradle.analytics.Architecture.ARM.serializedName
Architecture.MIPS32 -> "Mips"
Architecture.MIPSEL32 -> "MipsEL32"
Architecture.WASM32 -> "Wasm"
else -> unknown(target.architecture.name)
}
} catch (e: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,38 @@ public open class ConfigurationImpl(
logger: ContextLogger
) : InternalConfiguration {

override val path: String
final override val path: String

override val name: String
final override val name: String

override val schema: Set<KClass<out BaseRealmObject>>
final override val schema: Set<KClass<out BaseRealmObject>>

override val log: LogConfiguration
final override val log: LogConfiguration

override val maxNumberOfActiveVersions: Long
final override val maxNumberOfActiveVersions: Long

override val schemaVersion: Long
final override val schemaVersion: Long

override val schemaMode: SchemaMode
final override val schemaMode: SchemaMode

override val logger: ContextLogger = logger

override val encryptionKey: ByteArray?
get(): ByteArray? = userEncryptionKey

override val mapOfKClassWithCompanion: Map<KClass<out BaseRealmObject>, RealmObjectCompanion>
final override val mapOfKClassWithCompanion: Map<KClass<out BaseRealmObject>, RealmObjectCompanion>

override val mediator: Mediator
final override val mediator: Mediator

override val notificationDispatcherFactory: CoroutineDispatcherFactory
final override val notificationDispatcherFactory: CoroutineDispatcherFactory

override val writeDispatcherFactory: CoroutineDispatcherFactory
final override val writeDispatcherFactory: CoroutineDispatcherFactory

override val compactOnLaunchCallback: CompactOnLaunchCallback?
final override val compactOnLaunchCallback: CompactOnLaunchCallback?

override val initialDataCallback: InitialDataCallback?
override val inMemory: Boolean
override val initialRealmFileConfiguration: InitialRealmFileConfiguration?
final override val initialDataCallback: InitialDataCallback?
final override val inMemory: Boolean
final override val initialRealmFileConfiguration: InitialRealmFileConfiguration?

override fun createNativeConfiguration(): RealmConfigurationPointer {
val nativeConfig: RealmConfigurationPointer = RealmInterop.realm_config_new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class RealmConfigurationImpl(
automaticBacklinkHandling: Boolean,
initialDataCallback: InitialDataCallback?,
inMemory: Boolean,
override val initialRealmFileConfiguration: InitialRealmFileConfiguration?,
initialRealmFileConfiguration: InitialRealmFileConfiguration?,
logger: ContextLogger
) : ConfigurationImpl(
directory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import platform.Foundation.dataWithContentsOfFile
import platform.Foundation.timeIntervalSince1970
import platform.posix.memcpy
import platform.posix.pthread_threadid_np
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.identityHashCode
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KType
Expand Down Expand Up @@ -194,4 +195,5 @@ private fun NSData.toByteArray(): ByteArray = ByteArray([email protected].

public actual fun isWindows(): Boolean = false

@OptIn(ExperimentalNativeApi::class)
internal actual fun identityHashCode(obj: Any?): Int = obj.identityHashCode()
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package io.realm.kotlin.internal.platform

import kotlin.experimental.ExperimentalNativeApi

@OptIn(ExperimentalNativeApi::class)
public actual typealias WeakReference<T> = kotlin.native.ref.WeakReference<T>
Loading
Loading