diff --git a/.run/lyng_site [jsBrowserDevelopmentRun].run.xml b/.run/lyng_site [jsBrowserDevelopmentRun].run.xml index 548e319..5518148 100644 --- a/.run/lyng_site [jsBrowserDevelopmentRun].run.xml +++ b/.run/lyng_site [jsBrowserDevelopmentRun].run.xml @@ -1,3 +1,20 @@ + + @@ -17,8 +34,11 @@ true true + false false false + true + true \ No newline at end of file diff --git a/docs/migrate_time_to_2_2.md b/docs/migrate_time_to_2_2.md new file mode 100644 index 0000000..f429f03 --- /dev/null +++ b/docs/migrate_time_to_2_2.md @@ -0,0 +1,25 @@ +# Migration of Instant and Clock + +## History + +Before kotlin 2.0, there was an excellent library, kotlinx.datetime, which was widely used everywhere, also in Lyng and its dependencies. + +When kotlin 2.0 was released, or soon after, JetBrains made an exptic decision to remove `Instant` and `Clock` from kotlinx.datetime and replace it with _yet experimental_ analogs in `kotlin.time`. + +The problem is, these were not quite the same (these weren't `@Serializable`!), so people didn't migrate with ease. Okay, then JetBrains decided to not only deprecate it but also make them unusable on Apple targets. It sort of split auditories of many published libraries to those who hate JetBrains and Apple and continue to use 1.9-2.0 compatible versions that no longer work with Kotlin 2.2 on Apple targets (but work pretty well with earlier Kotlin or on other platforms). + +Later JetBrains added serializers for their new `Instant` and `Clock` types, but strangely not in the stdlib, but in newer versions of `kotlinx.serialization`. This means that plain upgrade of dependencies to 2.2 is not enough to make them work. + +## Solution + +We hereby publish a new version of Lyng, 1.0.8-SNAPSHOT, which uses `ktlin.time.Instant` and `kotlin.time.Clock` instead of `kotlinx.datetime.Instant` and `kotlinx.datetime.Clock; it is in other aspects compatible also with Lynon encoded binaries. Still you might need to migrate your code to use `kotlinx.datetime` types. + +So, if you are getting errors with new version, plase do: + +- upgrade to Kotlin 2.2 +- upgrade to Lyng 1.0.8-SNAPSHOT +- replace in your code imports (or other uses) of`kotlinx.datetime.Clock` to `kotlin.time.Clock` and `kotlinx.datetime.Instant` to `kotlin.time.Instant`. + +This should solve the problem and hopefully we'll see no more suh a brillant ideas from IDEA ideologspersons. + +Sorry for inconvenicence and send a ray of hate to JetBrains ;) \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e2203e8..ba411a1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ kotlin = "2.2.21" android-minSdk = "24" android-compileSdk = "34" kotlinx-coroutines = "1.10.2" -mp_bintools = "0.1.12" +mp_bintools = "0.3.2" firebaseCrashlyticsBuildtools = "3.0.3" okioVersion = "3.10.2" compiler = "3.2.0-alpha11" diff --git a/lyngio/build.gradle.kts b/lyngio/build.gradle.kts index 654e347..5732e25 100644 --- a/lyngio/build.gradle.kts +++ b/lyngio/build.gradle.kts @@ -38,7 +38,7 @@ kotlin { publishLibraryVariants("release") @OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) + jvmTarget.set(JvmTarget.JVM_17) } } iosX64() @@ -71,11 +71,7 @@ kotlin { sourceSets { all { languageSettings.optIn("kotlin.ExperimentalUnsignedTypes") -// languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") - // Correct opt-in markers for coroutines -// languageSettings.optIn("kotlinx.coroutines.DelicateCoroutinesApi") -// languageSettings.optIn("kotlin.contracts.ExperimentalContracts") -// languageSettings.optIn("kotlinx.coroutines.FlowPreview") + languageSettings.optIn("kotlin.time.ExperimentalTime") } val commonMain by getting { dependencies { @@ -115,8 +111,8 @@ android { minSdk = libs.versions.android.minSdk.get().toInt() } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } lint { // Prevent Android Lint from failing the build due to Kotlin toolchain diff --git a/lyngio/src/commonMain/kotlin/net/sergeych/lyng/io/fs/LyngFsModule.kt b/lyngio/src/commonMain/kotlin/net/sergeych/lyng/io/fs/LyngFsModule.kt index 9bc3ca1..5c30fc2 100644 --- a/lyngio/src/commonMain/kotlin/net/sergeych/lyng/io/fs/LyngFsModule.kt +++ b/lyngio/src/commonMain/kotlin/net/sergeych/lyng/io/fs/LyngFsModule.kt @@ -163,7 +163,7 @@ private suspend fun buildFsModule(module: ModuleScope, policy: FsAccessPolicy) { fsGuard { val self = this.thisObj as ObjPath val m = self.ensureMetadata() - m.createdAtMillis?.let { ObjInstant(kotlinx.datetime.Instant.fromEpochMilliseconds(it)) } ?: ObjNull + m.createdAtMillis?.let { ObjInstant(kotlin.time.Instant.fromEpochMilliseconds(it)) } ?: ObjNull } } // createdAtMillis(): Int? — milliseconds since epoch or null diff --git a/lynglib/build.gradle.kts b/lynglib/build.gradle.kts index 71b9f39..ccb5d87 100644 --- a/lynglib/build.gradle.kts +++ b/lynglib/build.gradle.kts @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.dsl.JvmTarget group = "net.sergeych" -version = "1.0.7-SNAPSHOT" +version = "1.0.8-SNAPSHOT" // Removed legacy buildscript classpath declarations; plugins are applied via the plugins DSL below @@ -51,7 +51,7 @@ kotlin { publishLibraryVariants("release") @OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) + jvmTarget.set(JvmTarget.JVM_17) } } iosX64() @@ -89,16 +89,16 @@ kotlin { languageSettings.optIn("kotlinx.coroutines.DelicateCoroutinesApi") languageSettings.optIn("kotlin.contracts.ExperimentalContracts") languageSettings.optIn("kotlinx.coroutines.FlowPreview") + languageSettings.optIn("kotlin.time.ExperimentalTime") } val commonMain by getting { kotlin.srcDir("$buildDir/generated/buildConfig/commonMain/kotlin") dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0") //put your multiplatform dependencies here api(libs.kotlinx.coroutines.core) api(libs.mp.bintools) - api("net.sergeych:mp_stools:1.5.2") } } val commonTest by getting { @@ -116,6 +116,18 @@ kotlin { } } +android { + namespace = "net.sergeych.lynglib" + compileSdk = libs.versions.android.compileSdk.get().toInt() + defaultConfig { + minSdk = libs.versions.android.minSdk.get().toInt() + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } +} + // ---- Build-time generation of stdlib text from .lyng files into a Kotlin constant ---- // Implemented as a proper task type compatible with Gradle Configuration Cache diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjInstant.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjInstant.kt index cb2e3d4..7af1f02 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjInstant.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjInstant.kt @@ -17,10 +17,6 @@ package net.sergeych.lyng.obj -import kotlinx.datetime.Clock -import kotlinx.datetime.Instant -import kotlinx.datetime.isDistantFuture -import kotlinx.datetime.isDistantPast import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonPrimitive import net.sergeych.lyng.Scope @@ -28,6 +24,10 @@ import net.sergeych.lynon.LynonDecoder import net.sergeych.lynon.LynonEncoder import net.sergeych.lynon.LynonSettings import net.sergeych.lynon.LynonType +import kotlin.time.Clock +import kotlin.time.Instant +import kotlin.time.isDistantFuture +import kotlin.time.isDistantPast class ObjInstant(val instant: Instant,val truncateMode: LynonSettings.InstantTruncateMode=LynonSettings.InstantTruncateMode.Microsecond) : Obj() { override val objClass: ObjClass get() = type diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/tools/bm.kt b/lynglib/src/commonMain/kotlin/net/sergeych/tools/bm.kt index 913d6e7..4db0ca5 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/tools/bm.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/tools/bm.kt @@ -17,7 +17,7 @@ package net.sergeych.tools -import kotlinx.datetime.Clock +import kotlin.time.Clock inline fun bm(text: String="", f: ()->Unit) { val start = Clock.System.now() diff --git a/lynglib/src/commonTest/kotlin/ScriptTest.kt b/lynglib/src/commonTest/kotlin/ScriptTest.kt index e6f36a8..7c24432 100644 --- a/lynglib/src/commonTest/kotlin/ScriptTest.kt +++ b/lynglib/src/commonTest/kotlin/ScriptTest.kt @@ -23,8 +23,6 @@ import kotlinx.coroutines.flow.toList import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout -import kotlinx.datetime.Clock -import kotlinx.datetime.Instant import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject @@ -36,7 +34,9 @@ import net.sergeych.lyng.pacman.InlineSourcesImportProvider import net.sergeych.mp_tools.globalDefer import net.sergeych.tools.bm import kotlin.test.* +import kotlin.time.Clock import kotlin.time.Duration.Companion.seconds +import kotlin.time.Instant /* * Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com diff --git a/lynglib/src/jvmTest/kotlin/SamplesTest.kt b/lynglib/src/jvmTest/kotlin/SamplesTest.kt index 9a834c6..449228a 100644 --- a/lynglib/src/jvmTest/kotlin/SamplesTest.kt +++ b/lynglib/src/jvmTest/kotlin/SamplesTest.kt @@ -18,12 +18,12 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext -import kotlinx.datetime.Clock import net.sergeych.lyng.Scope import java.nio.file.Files import java.nio.file.Paths import kotlin.io.path.extension import kotlin.test.Test +import kotlin.time.Clock suspend fun executeSampleTests(fileName: String) { val sample = withContext(Dispatchers.IO) {