From 44d0abb119e23c7e6647c983969b521f2dba1359 Mon Sep 17 00:00:00 2001 From: Denis Lochmelis Date: Sun, 21 Jul 2024 14:48:04 +0200 Subject: [PATCH] Support mingwX64 target --- cli/build.gradle.kts | 1 + core/build.gradle.kts | 4 ++-- .../org/jetbrains/litmuskt/NativeUtils.kt | 6 ++++++ .../org/jetbrains/litmuskt/NativeUtils.kt | 6 ++++++ .../org/jetbrains/litmuskt/NativeUtils.kt | 17 +++++++++++++++++ .../org/jetbrains/litmuskt/NativeUtils.kt | 4 ---- jcstress/pom.xml | 2 +- testsuite/build.gradle.kts | 7 ++++--- 8 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 core/src/linuxMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt create mode 100644 core/src/macosMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt create mode 100644 core/src/mingwMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt diff --git a/cli/build.gradle.kts b/cli/build.gradle.kts index 74e957f..8d1010c 100644 --- a/cli/build.gradle.kts +++ b/cli/build.gradle.kts @@ -9,6 +9,7 @@ kotlin { // linuxArm64(), macosX64(), macosArm64(), + mingwX64(), ) nativeTargets.forEach { target -> target.binaries { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ed3f8a9..cd48963 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -6,10 +6,10 @@ plugins { kotlin { val nativeTargets = listOf( linuxX64(), - // 1) no machine currently available 2) CLI library does not support -// linuxArm64(), + linuxArm64(), macosX64(), macosArm64(), + mingwX64(), ) jvm { diff --git a/core/src/linuxMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt b/core/src/linuxMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt new file mode 100644 index 0000000..2bb17a3 --- /dev/null +++ b/core/src/linuxMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt @@ -0,0 +1,6 @@ +package org.jetbrains.litmuskt + +import platform.posix.sysconf +import platform.posix._SC_NPROCESSORS_ONLN + +actual fun cpuCount(): Int = sysconf(_SC_NPROCESSORS_ONLN).toInt() diff --git a/core/src/macosMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt b/core/src/macosMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt new file mode 100644 index 0000000..2bb17a3 --- /dev/null +++ b/core/src/macosMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt @@ -0,0 +1,6 @@ +package org.jetbrains.litmuskt + +import platform.posix.sysconf +import platform.posix._SC_NPROCESSORS_ONLN + +actual fun cpuCount(): Int = sysconf(_SC_NPROCESSORS_ONLN).toInt() diff --git a/core/src/mingwMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt b/core/src/mingwMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt new file mode 100644 index 0000000..5eca64f --- /dev/null +++ b/core/src/mingwMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt @@ -0,0 +1,17 @@ +package org.jetbrains.litmuskt + +import kotlinx.cinterop.ExperimentalForeignApi +import kotlinx.cinterop.alloc +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.ptr +import platform.windows.GetSystemInfo +import platform.windows.SYSTEM_INFO + +actual val affinityManager: AffinityManager? = null + +@OptIn(ExperimentalForeignApi::class) +actual fun cpuCount(): Int = memScoped { + val systemInfo = alloc() + GetSystemInfo(systemInfo.ptr) + systemInfo.dwNumberOfProcessors.toInt() +} diff --git a/core/src/nativeMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt b/core/src/nativeMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt index 236036b..36157a0 100644 --- a/core/src/nativeMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt +++ b/core/src/nativeMain/kotlin/org/jetbrains/litmuskt/NativeUtils.kt @@ -2,12 +2,8 @@ package org.jetbrains.litmuskt import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.toKString -import platform.posix._SC_NPROCESSORS_ONLN import platform.posix.errno import platform.posix.strerror -import platform.posix.sysconf - -actual fun cpuCount(): Int = sysconf(_SC_NPROCESSORS_ONLN).toInt() @OptIn(ExperimentalForeignApi::class) fun Int.syscallCheck() { diff --git a/jcstress/pom.xml b/jcstress/pom.xml index bbc22ef..820187d 100644 --- a/jcstress/pom.xml +++ b/jcstress/pom.xml @@ -73,7 +73,7 @@ THE POSSIBILITY OF SUCH DAMAGE. org.jetbrains.kotlin kotlin-stdlib - 1.9.20 + 2.0.0 org.jetbrains.litmuskt diff --git a/testsuite/build.gradle.kts b/testsuite/build.gradle.kts index d79d49f..88f8ddc 100644 --- a/testsuite/build.gradle.kts +++ b/testsuite/build.gradle.kts @@ -5,11 +5,12 @@ plugins { } kotlin { - // targets have to be the same as in :cli (because it depends on this subproject) linuxX64() -// linuxArm64() + linuxArm64() macosX64() macosArm64() + mingwX64() + jvm { withJava() } @@ -25,7 +26,7 @@ kotlin { // ======== ksp ======== -val kspTasks = setOf("kspJvm", "kspLinuxX64", "kspMacosX64", "kspMacosArm64") +val kspTasks = setOf("kspJvm", "kspLinuxX64", "kspMacosX64", "kspMacosArm64", "kspMingwX64") dependencies { for (kspTask in kspTasks) {