diff --git a/.editorconfig b/.editorconfig index 328730c..721da50 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/.gitattributes b/.gitattributes index f98497e..a20eada 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,4 @@ -* text eol=lf +* text=auto eol=lf gradlew linguist-generated gradlew.bat linguist-generated eol=crlf diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b997a50..4c4ae1c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,7 +15,7 @@ updates: - package-ecosystem: gradle directory: / schedule: - interval: monthly + interval: weekly day: saturday commit-message: prefix: build diff --git a/.gitignore b/.gitignore index 25c8282..2edee02 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ dependency-graph-reports/ local.properties ### Kotlin ### +.kotlin/ kotlin-js-store/ ### JetBrains ### diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 16af9e0..d2bbdcb 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -11,10 +11,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 6c1cd27..5ed15b0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 @@ -32,14 +29,6 @@ plugins.withType { the().download = false } -plugins.withType { - the().apply { - download = false - yarnLockAutoReplace = true - yarnLockMismatchReport = YarnLockMismatchReport.WARNING - } -} - tasks.dokkaHtmlMultiModule { moduleName.set("KBigInt") includes.from("README.md") @@ -52,6 +41,6 @@ tasks.dokkaHtmlMultiModule { } tasks.wrapper { - gradleVersion = "8.7" + gradleVersion = "8.10" distributionType = Wrapper.DistributionType.BIN } diff --git a/gradle.properties b/gradle.properties index cf4d74e..2433a83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 @@ -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 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6dc856c..9461a12 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e644113..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23..9355b41 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew index 1aa94a4..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,8 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 25da30d..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/kbigint-serialization/README.md b/kbigint-serialization/README.md index b9843fa..1e6fcea 100644 --- a/kbigint-serialization/README.md +++ b/kbigint-serialization/README.md @@ -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 diff --git a/kbigint-serialization/build.gradle.kts b/kbigint-serialization/build.gradle.kts index 619dca2..25e26cc 100644 --- a/kbigint-serialization/build.gradle.kts +++ b/kbigint-serialization/build.gradle.kts @@ -21,7 +21,7 @@ kotlin { publishLibraryVariants("release") } - js(IR) { + js { moduleName = project.name browser { @@ -43,6 +43,9 @@ kotlin { } useEsModules() + + @Suppress("OPT_IN_USAGE") + compilerOptions.target.set("es2015") } when { diff --git a/kbigint-serialization/src/androidUnitTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt b/kbigint-serialization/src/androidUnitTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt deleted file mode 100644 index 99d22e7..0000000 --- a/kbigint-serialization/src/androidUnitTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt +++ /dev/null @@ -1,4 +0,0 @@ -package io.github.observeroftime.kbigint.serialization - -@Target(AnnotationTarget.FUNCTION) -actual annotation class JvmOnly diff --git a/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt b/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt deleted file mode 100644 index dcb9bf6..0000000 --- a/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt +++ /dev/null @@ -1,4 +0,0 @@ -package io.github.observeroftime.kbigint.serialization - -@Target(AnnotationTarget.FUNCTION) -expect annotation class JvmOnly() diff --git a/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/KBigIntSerializerTest.kt b/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/KBigIntSerializerTest.kt index 9422e4e..d6e0944 100644 --- a/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/KBigIntSerializerTest.kt +++ b/kbigint-serialization/src/commonTest/kotlin/io/github/observeroftime/kbigint/serialization/KBigIntSerializerTest.kt @@ -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 @@ -28,7 +29,7 @@ class KBigIntSerializerTest { } @Test - @JvmOnly + @Ignore fun testEncodeAlias() { val element = Json.encodeToJsonElement(KBigInt(N)) assertTrue { element.jsonPrimitive.isString } @@ -36,7 +37,7 @@ class KBigIntSerializerTest { } @Test - @JvmOnly + @Ignore fun testDecodeAlias() { assertEquals(KBigInt(N), Json.decodeFromJsonElement(JsonPrimitive(N))) } diff --git a/kbigint-serialization/src/jsTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt b/kbigint-serialization/src/jsTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt deleted file mode 100644 index f617fd4..0000000 --- a/kbigint-serialization/src/jsTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.github.observeroftime.kbigint.serialization - -actual typealias JvmOnly = kotlin.test.Ignore diff --git a/kbigint-serialization/src/jvmTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt b/kbigint-serialization/src/jvmTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt deleted file mode 100644 index 99d22e7..0000000 --- a/kbigint-serialization/src/jvmTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt +++ /dev/null @@ -1,4 +0,0 @@ -package io.github.observeroftime.kbigint.serialization - -@Target(AnnotationTarget.FUNCTION) -actual annotation class JvmOnly diff --git a/kbigint-serialization/src/nativeTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt b/kbigint-serialization/src/nativeTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt deleted file mode 100644 index f617fd4..0000000 --- a/kbigint-serialization/src/nativeTest/kotlin/io/github/observeroftime/kbigint/serialization/JvmOnly.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.github.observeroftime.kbigint.serialization - -actual typealias JvmOnly = kotlin.test.Ignore diff --git a/kbigint/build.gradle.kts b/kbigint/build.gradle.kts index 5598de8..af933b8 100644 --- a/kbigint/build.gradle.kts +++ b/kbigint/build.gradle.kts @@ -23,7 +23,7 @@ kotlin { publishLibraryVariants("release") } - js(IR) { + js { moduleName = project.name browser { @@ -45,6 +45,9 @@ kotlin { } useEsModules() + + @Suppress("OPT_IN_USAGE") + compilerOptions.target.set("es2015") } when { diff --git a/kbigint/src/nativeMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt b/kbigint/src/nativeMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt index 9f9d236..988e7d0 100644 --- a/kbigint/src/nativeMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt +++ b/kbigint/src/nativeMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt @@ -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 { + @Suppress("unused") // false positive private constructor() : this(nativeHeap.alloc()) @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) : this() { @@ -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)