11import java.io.ByteArrayOutputStream
22import org.gradle.internal.os.OperatingSystem
33import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
4+ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
45import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
56
67val os: OperatingSystem = OperatingSystem .current()
78val libsDir = layout.buildDirectory.get().dir(" tmp" ).dir(" libs" )
89val libtommathDir = projectDir.resolve(" src/nativeInterop/libtommath" )
910
11+ fun KotlinNativeTarget.libtommath () {
12+ compilations.configureEach {
13+ cinterops.create(" tommath" ) {
14+ includeDirs.allHeaders(libtommathDir)
15+ extraOpts(" -libraryPath" , libsDir.dir(konanTarget.name))
16+ }
17+ }
18+ }
19+
1020plugins {
1121 `maven- publish`
1222 signing
@@ -50,27 +60,17 @@ kotlin {
5060 compilerOptions.target.set(" es2015" )
5161 }
5262
53- when {
54- os.isLinux -> listOf (linuxX64(), linuxArm64())
55- os.isWindows -> listOf (mingwX64())
56- os.isMacOsX -> listOf (
57- macosArm64(),
58- macosX64(),
59- iosArm64(),
60- iosSimulatorArm64()
61- )
62- else -> {
63- val arch = System .getProperty(" os.arch" )
64- throw GradleException (" Unsupported platform: $os ($arch )" )
65- }
66- }.forEach {
67- it.compilations.configureEach {
68- cinterops.create(" tommath" ) {
69- includeDirs.allHeaders(libtommathDir)
70- extraOpts(" -libraryPath" , libsDir.dir(konanTarget.name))
71- }
72- }
73- }
63+ linuxX64 { libtommath() }
64+ linuxArm64 { libtommath() }
65+
66+ mingwX64 { libtommath() }
67+
68+ macosArm64 { libtommath() }
69+ macosX64 { libtommath() }
70+ iosArm64 { libtommath() }
71+ iosSimulatorArm64 { libtommath() }
72+
73+ applyDefaultHierarchyTemplate()
7474
7575 jvmToolchain(17 )
7676
@@ -106,7 +106,7 @@ kotlin {
106106
107107android {
108108 namespace = group.toString()
109- compileSdk = 34
109+ compileSdk = 35
110110 defaultConfig {
111111 minSdk = 21
112112 }
@@ -129,7 +129,6 @@ if (os.isLinux) {
129129
130130 environment[" ARFLAGS" ] = " rcs"
131131 environment[" CFLAGS" ] = " -O2 -DMP_NO_FILE -DMP_USE_ENUMS"
132- environment[" CC" ] = " gcc"
133132 }
134133
135134 copy {
@@ -151,7 +150,28 @@ if (os.isLinux) {
151150 environment[" ARFLAGS" ] = " rcs"
152151 environment[" CFLAGS" ] = " -O2 -DMP_NO_FILE -DMP_USE_ENUMS"
153152 environment[" CROSS_COMPILE" ] = " aarch64-linux-gnu-"
154- environment[" CC" ] = " aarch64-linux-gnu-gcc"
153+ }
154+
155+ copy {
156+ from(libtommathDir.resolve(" libtommath.a" ))
157+ into(libsDir.dir(konanTarget.name))
158+ }
159+ }
160+ }
161+
162+ tasks.getByName<CInteropProcess >(" cinteropTommathMingwX64" ) {
163+ outputs.file(libsDir.dir(konanTarget.name).file(" libtommath.a" ))
164+
165+ doFirst {
166+ exec {
167+ executable = " make"
168+ workingDir = libtommathDir
169+ args(" clean" , " libtommath.a" )
170+
171+ environment[" ARFLAGS" ] = " rcs"
172+ environment[" CFLAGS" ] = " -O2 -DMP_NO_FILE -DMP_USE_ENUMS" +
173+ " -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast"
174+ environment[" CROSS_COMPILE" ] = " x86_64-w64-mingw32-"
155175 }
156176
157177 copy {
@@ -306,7 +326,7 @@ tasks.dokkaHtmlPartial {
306326 pluginsMapConfiguration.set(
307327 mapOf (
308328 " org.jetbrains.dokka.base.DokkaBase" to
309- """ {"footerMessage": "(c) 2024 ObserverOfTime"}"""
329+ """ {"footerMessage": "(c) 2025 ObserverOfTime"}"""
310330 )
311331 )
312332 dokkaSourceSets.configureEach {
0 commit comments