From faf1e61449cdfe95adfe125bc893a4826ee3e35d Mon Sep 17 00:00:00 2001 From: Adam Arold Date: Thu, 25 Jan 2024 15:06:58 +0100 Subject: [PATCH] fix everything --- buildSrc/build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Libraries.kt | 20 ++--- buildSrc/src/main/kotlin/Versions.kt | 4 +- cobalt.core/build.gradle.kts | 82 ++++++++----------- .../org/hexworks/cobalt/core/api/UUID.kt | 7 +- .../cobalt/core/internal/DefaultUUID.kt | 46 ++++++++++- gradle.properties | 5 -- script/release | 4 +- 8 files changed, 95 insertions(+), 75 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 4cb4197..c999a4e 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -10,5 +10,5 @@ repositories { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") } diff --git a/buildSrc/src/main/kotlin/Libraries.kt b/buildSrc/src/main/kotlin/Libraries.kt index abc9930..d20f7f9 100644 --- a/buildSrc/src/main/kotlin/Libraries.kt +++ b/buildSrc/src/main/kotlin/Libraries.kt @@ -1,19 +1,11 @@ -import Versions.korVersion -import Versions.kotlinxCollectionsImmutableVersion +import Versions.KOR_VERSION +import Versions.KOTLINX_COLLECTIONS_IMMUTABLE_VERSION object Libraries { - const val kotlinReflect = "org.jetbrains.kotlin:kotlin-reflect" - const val kotlinxCollectionsImmutable = - "org.jetbrains.kotlinx:kotlinx-collections-immutable:$kotlinxCollectionsImmutableVersion" + const val KOTLIN_REFLECT = "org.jetbrains.kotlin:kotlin-reflect" + const val KOTLINX_COLLECTIONS_IMMUTABLE = + "org.jetbrains.kotlinx:kotlinx-collections-immutable:$KOTLINX_COLLECTIONS_IMMUTABLE_VERSION" - - const val korio = "com.soywiz.korlibs.korio:korio:$korVersion" - const val klogger = "com.soywiz.korlibs.klogger:klogger:$korVersion" - - // TEST - const val kotlinTestCommon = "org.jetbrains.kotlin:kotlin-test-common" - const val kotlinTestAnnotationsCommon = "org.jetbrains.kotlin:kotlin-test-annotations-common" - const val kotlinTestJunit = "org.jetbrains.kotlin:kotlin-test-junit" - const val kotlinTestJs = "org.jetbrains.kotlin:kotlin-test-js" + const val KORGE_FOUNDATION = "com.soywiz.korge:korge-foundation:$KOR_VERSION" } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 9d571e9..7690bc7 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,6 +1,6 @@ object Versions { - const val kotlinxCollectionsImmutableVersion = "0.3.5" + const val KOTLINX_COLLECTIONS_IMMUTABLE_VERSION = "0.3.5" - const val korVersion = "4.0.8" + const val KOR_VERSION = "5.3.0" } diff --git a/cobalt.core/build.gradle.kts b/cobalt.core/build.gradle.kts index eddab84..2773f60 100644 --- a/cobalt.core/build.gradle.kts +++ b/cobalt.core/build.gradle.kts @@ -1,8 +1,6 @@ -import Libraries.klogger -import Libraries.korio -import Libraries.kotlinReflect -import Libraries.kotlinxCollectionsImmutable -import org.jetbrains.kotlin.konan.target.HostManager +import Libraries.KORGE_FOUNDATION +import Libraries.KOTLINX_COLLECTIONS_IMMUTABLE +import Libraries.KOTLIN_REFLECT plugins { kotlin("multiplatform") @@ -10,61 +8,50 @@ plugins { id("signing") } +val javaVersion = JavaVersion.VERSION_11 + +java { + sourceCompatibility = javaVersion + targetCompatibility = javaVersion +} + kotlin { - targets { - js(IR) { - compilations.all { - kotlinOptions { - sourceMap = true - moduleKind = "umd" - metaInfo = true - } - } - browser { - testTask { - useMocha() - } + jvm { + withJava() + compilations.all { + kotlinOptions { + apiVersion = "1.9" + languageVersion = "1.9" + jvmTarget = javaVersion.toString() + } - nodejs() - } - jvm { - // Intentionally left blank. } - if (HostManager.hostIsMac) { - macosX64() - macosArm64() - iosX64() - iosArm64() - iosSimulatorArm64() - watchosArm32() - watchosArm64() - watchosX64() - watchosSimulatorArm64() - watchosDeviceArm64() - tvosArm64() - tvosX64() - tvosSimulatorArm64() - } - if (HostManager.hostIsMingw || HostManager.hostIsMac) { - mingwX64 { - binaries.findTest(DEBUG)!!.linkerOpts = mutableListOf("-Wl,--subsystem,windows") + } + + js(IR) { + compilations.all { + kotlinOptions { + sourceMap = true + moduleKind = "umd" + metaInfo = true } } - if (HostManager.hostIsLinux || HostManager.hostIsMac) { - linuxX64() - linuxArm64() + browser { + testTask { + useMocha() + } } + nodejs() } sourceSets { val commonMain by getting { dependencies { - api(kotlinReflect) - api(kotlinxCollectionsImmutable) + api(KOTLIN_REFLECT) + api(KOTLINX_COLLECTIONS_IMMUTABLE) - api(korio) - api(klogger) + api(KORGE_FOUNDATION) } } val commonTest by getting { @@ -73,6 +60,7 @@ kotlin { } } } + } publishing { diff --git a/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/api/UUID.kt b/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/api/UUID.kt index c79aed3..beeb13f 100644 --- a/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/api/UUID.kt +++ b/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/api/UUID.kt @@ -12,12 +12,15 @@ interface UUID { /** * Creates a random [UUID]. */ - fun randomUUID(): UUID = DefaultUUID(korlibs.io.util.UUID.randomUUID()) + fun randomUUID(): UUID = DefaultUUID.randomDefaultUUID() /** * Tries to create a [UUID] from a [String]. * This will throw an exception if the [UUID] cannot be created. */ - fun fromString(str: String): UUID = DefaultUUID(korlibs.io.util.UUID(str)) + fun fromString(str: String): UUID = DefaultUUID(str) } } + + + diff --git a/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/internal/DefaultUUID.kt b/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/internal/DefaultUUID.kt index 5c607fa..27b7a80 100644 --- a/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/internal/DefaultUUID.kt +++ b/cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/internal/DefaultUUID.kt @@ -1,8 +1,48 @@ package org.hexworks.cobalt.core.internal import org.hexworks.cobalt.core.api.UUID +import kotlin.random.Random -internal class DefaultUUID(private val backend: korlibs.io.util.UUID) : UUID { - override fun toString() = backend.toString() -} +@Suppress("EXPERIMENTAL_API_USAGE") +@OptIn(ExperimentalStdlibApi::class, ExperimentalUnsignedTypes::class) +class DefaultUUID(val data: UByteArray) : UUID { + override fun equals(other: Any?): Boolean = other is DefaultUUID && this.data.contentEquals(other.data) + override fun hashCode(): Int = this.data.contentHashCode() + + companion object { + private const val HEX = "0123456789ABCDEF" + + private val regex = + Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOption.IGNORE_CASE) + + val NIL: UUID get() = DefaultUUID("00000000-0000-0000-0000-000000000000") + + private fun fix(data: UByteArray, version: Int, variant: Int): UByteArray { + data[6] = ((data[6].toInt() and 0b0000_1111) or (version shl 4)).toUByte() + data[8] = ((data[8].toInt() and 0x00_111111) or (variant shl 6)).toUByte() + return data + } + + fun randomDefaultUUID(random: Random = Random): UUID = DefaultUUID(fix(UByteArray(16).apply { + random.nextBytes(this.asByteArray()) + }, version = 4, variant = 1)) + + operator fun invoke(str: String): UUID { + if (regex.matchEntire(str) == null) throw IllegalArgumentException("Invalid DefaultUUID") + return DefaultUUID(str.replace("-", "").hexToUByteArray()) + } + } + + val version: Int get() = (data[6].toInt() ushr 4) and 0b1111 + val variant: Int get() = (data[8].toInt() ushr 6) and 0b11 + + override fun toString(): String = buildString(36) { + for (n in 0 until 16) { + val c = data[n].toInt() + append(HEX[c shr 4]) + append(HEX[c and 0xF]) + if (n == 3 || n == 5 || n == 7 || n == 9) append('-') + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 16bea8b..751a57e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,6 @@ version=2023.1.0-RELEASE kotlin.mpp.stability.nowarn=true kotlin.js.compiler=both -org.gradle.parallel=true -org.gradle.daemon=true -org.gradle.jvmargs=-Xmx3g -org.gradle.configureondemand=true - POM_PACKAGING=jar POM_URL=https://github.com/Hexworks/cobalt POM_SCM_URL=https://github.com/Hexworks/cobalt.git diff --git a/script/release b/script/release index 5a36e87..1ec8c6c 100644 --- a/script/release +++ b/script/release @@ -1 +1,3 @@ -./gradlew publish --no-daemon --no-parallel +#!/usr/bin/env bash + +./gradlew publish --no-parallel --no-daemon