Skip to content

Commit faf1e61

Browse files
committed
fix everything
1 parent 5e6b4a1 commit faf1e61

File tree

8 files changed

+95
-75
lines changed

8 files changed

+95
-75
lines changed

buildSrc/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ repositories {
1010
}
1111

1212
dependencies {
13-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
13+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
1414
}

buildSrc/src/main/kotlin/Libraries.kt

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import Versions.korVersion
2-
import Versions.kotlinxCollectionsImmutableVersion
1+
import Versions.KOR_VERSION
2+
import Versions.KOTLINX_COLLECTIONS_IMMUTABLE_VERSION
33

44
object Libraries {
55

6-
const val kotlinReflect = "org.jetbrains.kotlin:kotlin-reflect"
7-
const val kotlinxCollectionsImmutable =
8-
"org.jetbrains.kotlinx:kotlinx-collections-immutable:$kotlinxCollectionsImmutableVersion"
6+
const val KOTLIN_REFLECT = "org.jetbrains.kotlin:kotlin-reflect"
7+
const val KOTLINX_COLLECTIONS_IMMUTABLE =
8+
"org.jetbrains.kotlinx:kotlinx-collections-immutable:$KOTLINX_COLLECTIONS_IMMUTABLE_VERSION"
99

10-
11-
const val korio = "com.soywiz.korlibs.korio:korio:$korVersion"
12-
const val klogger = "com.soywiz.korlibs.klogger:klogger:$korVersion"
13-
14-
// TEST
15-
const val kotlinTestCommon = "org.jetbrains.kotlin:kotlin-test-common"
16-
const val kotlinTestAnnotationsCommon = "org.jetbrains.kotlin:kotlin-test-annotations-common"
17-
const val kotlinTestJunit = "org.jetbrains.kotlin:kotlin-test-junit"
18-
const val kotlinTestJs = "org.jetbrains.kotlin:kotlin-test-js"
10+
const val KORGE_FOUNDATION = "com.soywiz.korge:korge-foundation:$KOR_VERSION"
1911
}

buildSrc/src/main/kotlin/Versions.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Versions {
22

3-
const val kotlinxCollectionsImmutableVersion = "0.3.5"
3+
const val KOTLINX_COLLECTIONS_IMMUTABLE_VERSION = "0.3.5"
44

5-
const val korVersion = "4.0.8"
5+
const val KOR_VERSION = "5.3.0"
66
}

cobalt.core/build.gradle.kts

+35-47
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,57 @@
1-
import Libraries.klogger
2-
import Libraries.korio
3-
import Libraries.kotlinReflect
4-
import Libraries.kotlinxCollectionsImmutable
5-
import org.jetbrains.kotlin.konan.target.HostManager
1+
import Libraries.KORGE_FOUNDATION
2+
import Libraries.KOTLINX_COLLECTIONS_IMMUTABLE
3+
import Libraries.KOTLIN_REFLECT
64

75
plugins {
86
kotlin("multiplatform")
97
id("maven-publish")
108
id("signing")
119
}
1210

11+
val javaVersion = JavaVersion.VERSION_11
12+
13+
java {
14+
sourceCompatibility = javaVersion
15+
targetCompatibility = javaVersion
16+
}
17+
1318
kotlin {
1419

15-
targets {
16-
js(IR) {
17-
compilations.all {
18-
kotlinOptions {
19-
sourceMap = true
20-
moduleKind = "umd"
21-
metaInfo = true
22-
}
23-
}
24-
browser {
25-
testTask {
26-
useMocha()
27-
}
20+
jvm {
21+
withJava()
22+
compilations.all {
23+
kotlinOptions {
24+
apiVersion = "1.9"
25+
languageVersion = "1.9"
26+
jvmTarget = javaVersion.toString()
27+
2828
}
29-
nodejs()
30-
}
31-
jvm {
32-
// Intentionally left blank.
3329
}
34-
if (HostManager.hostIsMac) {
35-
macosX64()
36-
macosArm64()
37-
iosX64()
38-
iosArm64()
39-
iosSimulatorArm64()
40-
watchosArm32()
41-
watchosArm64()
42-
watchosX64()
43-
watchosSimulatorArm64()
44-
watchosDeviceArm64()
45-
tvosArm64()
46-
tvosX64()
47-
tvosSimulatorArm64()
48-
}
49-
if (HostManager.hostIsMingw || HostManager.hostIsMac) {
50-
mingwX64 {
51-
binaries.findTest(DEBUG)!!.linkerOpts = mutableListOf("-Wl,--subsystem,windows")
30+
}
31+
32+
js(IR) {
33+
compilations.all {
34+
kotlinOptions {
35+
sourceMap = true
36+
moduleKind = "umd"
37+
metaInfo = true
5238
}
5339
}
54-
if (HostManager.hostIsLinux || HostManager.hostIsMac) {
55-
linuxX64()
56-
linuxArm64()
40+
browser {
41+
testTask {
42+
useMocha()
43+
}
5744
}
45+
nodejs()
5846
}
5947

6048
sourceSets {
6149
val commonMain by getting {
6250
dependencies {
63-
api(kotlinReflect)
64-
api(kotlinxCollectionsImmutable)
51+
api(KOTLIN_REFLECT)
52+
api(KOTLINX_COLLECTIONS_IMMUTABLE)
6553

66-
api(korio)
67-
api(klogger)
54+
api(KORGE_FOUNDATION)
6855
}
6956
}
7057
val commonTest by getting {
@@ -73,6 +60,7 @@ kotlin {
7360
}
7461
}
7562
}
63+
7664
}
7765

7866
publishing {

cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/api/UUID.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ interface UUID {
1212
/**
1313
* Creates a random [UUID].
1414
*/
15-
fun randomUUID(): UUID = DefaultUUID(korlibs.io.util.UUID.randomUUID())
15+
fun randomUUID(): UUID = DefaultUUID.randomDefaultUUID()
1616

1717
/**
1818
* Tries to create a [UUID] from a [String].
1919
* This will throw an exception if the [UUID] cannot be created.
2020
*/
21-
fun fromString(str: String): UUID = DefaultUUID(korlibs.io.util.UUID(str))
21+
fun fromString(str: String): UUID = DefaultUUID(str)
2222
}
2323
}
24+
25+
26+
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
11
package org.hexworks.cobalt.core.internal
22

33
import org.hexworks.cobalt.core.api.UUID
4+
import kotlin.random.Random
45

56

6-
internal class DefaultUUID(private val backend: korlibs.io.util.UUID) : UUID {
7-
override fun toString() = backend.toString()
8-
}
7+
@Suppress("EXPERIMENTAL_API_USAGE")
8+
@OptIn(ExperimentalStdlibApi::class, ExperimentalUnsignedTypes::class)
9+
class DefaultUUID(val data: UByteArray) : UUID {
10+
override fun equals(other: Any?): Boolean = other is DefaultUUID && this.data.contentEquals(other.data)
11+
override fun hashCode(): Int = this.data.contentHashCode()
12+
13+
companion object {
14+
private const val HEX = "0123456789ABCDEF"
15+
16+
private val regex =
17+
Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOption.IGNORE_CASE)
18+
19+
val NIL: UUID get() = DefaultUUID("00000000-0000-0000-0000-000000000000")
20+
21+
private fun fix(data: UByteArray, version: Int, variant: Int): UByteArray {
22+
data[6] = ((data[6].toInt() and 0b0000_1111) or (version shl 4)).toUByte()
23+
data[8] = ((data[8].toInt() and 0x00_111111) or (variant shl 6)).toUByte()
24+
return data
25+
}
26+
27+
fun randomDefaultUUID(random: Random = Random): UUID = DefaultUUID(fix(UByteArray(16).apply {
28+
random.nextBytes(this.asByteArray())
29+
}, version = 4, variant = 1))
30+
31+
operator fun invoke(str: String): UUID {
32+
if (regex.matchEntire(str) == null) throw IllegalArgumentException("Invalid DefaultUUID")
33+
return DefaultUUID(str.replace("-", "").hexToUByteArray())
34+
}
35+
}
36+
37+
val version: Int get() = (data[6].toInt() ushr 4) and 0b1111
38+
val variant: Int get() = (data[8].toInt() ushr 6) and 0b11
39+
40+
override fun toString(): String = buildString(36) {
41+
for (n in 0 until 16) {
42+
val c = data[n].toInt()
43+
append(HEX[c shr 4])
44+
append(HEX[c and 0xF])
45+
if (n == 3 || n == 5 || n == 7 || n == 9) append('-')
46+
}
47+
}
48+
}

gradle.properties

-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ version=2023.1.0-RELEASE
44
kotlin.mpp.stability.nowarn=true
55
kotlin.js.compiler=both
66

7-
org.gradle.parallel=true
8-
org.gradle.daemon=true
9-
org.gradle.jvmargs=-Xmx3g
10-
org.gradle.configureondemand=true
11-
127
POM_PACKAGING=jar
138
POM_URL=https://github.com/Hexworks/cobalt
149
POM_SCM_URL=https://github.com/Hexworks/cobalt.git

script/release

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
./gradlew publish --no-daemon --no-parallel
1+
#!/usr/bin/env bash
2+
3+
./gradlew publish --no-parallel --no-daemon

0 commit comments

Comments
 (0)