Skip to content

Commit

Permalink
feat!: upgrade to Kotlin 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Sep 9, 2024
1 parent 79e9f10 commit 60d2780
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 89 deletions.
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ max_line_length = off
[.editorconfig]
max_line_length = off

[*.{json,yml,toml,xml}]
[*.toml]
max_line_length = off
indent_size = 2

[*.{json,yml,xml}]
indent_size = 2

# noinspection EditorConfigKeyCorrectness
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text eol=lf
* text=auto eol=lf

gradlew linguist-generated
gradlew.bat linguist-generated eol=crlf
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ updates:
- package-ecosystem: gradle
directory: /
schedule:
interval: monthly
interval: weekly
day: saturday
commit-message:
prefix: build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependency-graph-reports/
local.properties

### Kotlin ###
.kotlin/
kotlin-js-store/

### JetBrains ###
Expand Down
10 changes: 5 additions & 5 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension

plugins {
alias(libs.plugins.kotlin.mpp) apply false
Expand Down Expand Up @@ -32,14 +29,6 @@ plugins.withType<NodeJsRootPlugin> {
the<NodeJsRootExtension>().download = false
}

plugins.withType<YarnPlugin> {
the<YarnRootExtension>().apply {
download = false
yarnLockAutoReplace = true
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
}
}

tasks.dokkaHtmlMultiModule {
moduleName.set("KBigInt")
includes.from("README.md")
Expand All @@ -52,6 +41,6 @@ tasks.dokkaHtmlMultiModule {
}

tasks.wrapper {
gradleVersion = "8.7"
gradleVersion = "8.10"
distributionType = Wrapper.DistributionType.BIN
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The version of the project.
project.version=0.3.1
project.version=0.4.0

# Specifies the JVM arguments used for the daemon process.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
Expand All @@ -16,6 +16,8 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.enableCInteropCommonization=true
# Ignore disabled Kotlin/Native targets
kotlin.native.ignoreDisabledTargets=true
# Use npm instead of yarn
kotlin.js.yarn=false

# Enables the AndroidX package structure.
android.useAndroidX=true
Expand Down
49 changes: 14 additions & 35 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
[versions]
kotlin-stdlib = "1.9.23"
kotlin-serialization = "1.6.3"
#noinspection GradleDependency
android-gradle = {strictly = "8.2.0"}
kotlin-stdlib = "2.0.20"
kotlin-serialization = "1.7.2"
android-gradle = {strictly = "8.5.2"}
dokka = "1.9.20"

[libraries.kotlin-stdlib]
module = "org.jetbrains.kotlin:kotlin-stdlib"
version.ref = "kotlin-stdlib"

[libraries.kotlin-serialization-core]
module = "org.jetbrains.kotlinx:kotlinx-serialization-core"
version.ref = "kotlin-serialization"

[libraries.kotlin-serialization-json]
module = "org.jetbrains.kotlinx:kotlinx-serialization-json"
version.ref = "kotlin-serialization"

[libraries.kotlin-test]
module = "org.jetbrains.kotlin:kotlin-test"
version.ref = "kotlin-stdlib"

[plugins.kotlin-mpp]
id = "org.jetbrains.kotlin.multiplatform"
version.ref = "kotlin-stdlib"

[plugins.kotlin-serialization]
id = "org.jetbrains.kotlin.plugin.serialization"
version.ref = "kotlin-stdlib"

[plugins.android-library]
id = "com.android.library"
version.ref = "android-gradle"

[plugins.dokka]
id = "org.jetbrains.dokka"
version.ref = "dokka"
[libraries]
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin-stdlib" }
kotlin-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlin-serialization" }
kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlin-serialization" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-stdlib" }

[plugins]
kotlin-mpp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin-stdlib" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-stdlib" }
android-library = { id = "com.android.library", version.ref = "android-gradle" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions kbigint-serialization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ val decoded = json.decodeFromJsonElement(encoded)

### Serializable type alias

The serializable type alias defined can be used explicitly in type parameters.
The serializable type alias can be used explicitly in type parameters.

**NOTE: this method only works in JVM & Android.**
*NOTE: this method may or may not work.*

```kotlin
import io.github.observeroftime.kbigint.serialization.KBigInt
Expand Down
5 changes: 4 additions & 1 deletion kbigint-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kotlin {
publishLibraryVariants("release")
}

js(IR) {
js {
moduleName = project.name

browser {
Expand All @@ -43,6 +43,9 @@ kotlin {
}

useEsModules()

@Suppress("OPT_IN_USAGE")
compilerOptions.target.set("es2015")
}

when {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.observeroftime.kbigint.serialization

import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand Down Expand Up @@ -28,15 +29,15 @@ class KBigIntSerializerTest {
}

@Test
@JvmOnly
@Ignore
fun testEncodeAlias() {
val element = Json.encodeToJsonElement<KBigInt>(KBigInt(N))
assertTrue { element.jsonPrimitive.isString }
assertEquals(N, element.jsonPrimitive.content)
}

@Test
@JvmOnly
@Ignore
fun testDecodeAlias() {
assertEquals(KBigInt(N), Json.decodeFromJsonElement<KBigInt>(JsonPrimitive(N)))
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 4 additions & 1 deletion kbigint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kotlin {
publishLibraryVariants("release")
}

js(IR) {
js {
moduleName = project.name

browser {
Expand All @@ -45,6 +45,9 @@ kotlin {
}

useEsModules()

@Suppress("OPT_IN_USAGE")
compilerOptions.target.set("es2015")
}

when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import net.libtom.libtommath.*
@ObjCName("KBigInt")
@OptIn(ExperimentalForeignApi::class, ExperimentalObjCName::class)
actual class KBigInt private constructor(private var value: mp_int) : Comparable<KBigInt> {
@Suppress("unused") // false positive
private constructor() : this(nativeHeap.alloc<mp_int>())

@Suppress("unused")
@OptIn(ExperimentalNativeApi::class)
private val cleaner = createCleaner(value, ::dispose)
private val cleaner = createCleaner(value) {
mp_clear(it.ptr)
nativeHeap.free(it)
}

@Throws(IllegalStateException::class)
private constructor(value: CValuesRef<mp_int>) : this() {
Expand Down Expand Up @@ -478,11 +482,7 @@ actual class KBigInt private constructor(private var value: mp_int) : Comparable

actual override fun hashCode(): Int = toString().hashCode()

private inline fun dispose(value: mp_int) {
mp_clear(value.ptr)
nativeHeap.free(value)
}

@Suppress("NOTHING_TO_INLINE")
@Throws(IllegalStateException::class)
private inline fun mp_err.check() {
if (this != mp_err.MP_OKAY)
Expand Down

0 comments on commit 60d2780

Please sign in to comment.