@@ -10,6 +10,8 @@ import aws.sdk.kotlin.gradle.kmp.configureIosSimulatorTasks
1010import aws.sdk.kotlin.gradle.kmp.configureKmpTargets
1111import aws.sdk.kotlin.gradle.util.typedProp
1212import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
13+ import org.jetbrains.kotlin.konan.target.Family
14+ import org.jetbrains.kotlin.konan.target.HostManager
1315
1416plugins {
1517 alias(libs.plugins.kotlin.multiplatform)
@@ -70,8 +72,7 @@ kotlin {
7072 // see: https://github.com/JetBrains/kotlin-native/issues/2423#issuecomment-466300153
7173 targets.withType<KotlinNativeTarget > {
7274 val knTarget = this
73- logger.info(" configuring Kotlin/Native target $knTarget : ${knTarget.name} " )
74- val cmakeInstallTask = configureCrtCMakeBuild(knTarget, CMakeBuildType .Release )
75+
7576 val targetInstallDir = project.cmakeInstallDir(knTarget)
7677 val headerDir = targetInstallDir.resolve(" include" )
7778 val libDir = targetInstallDir.resolve(" lib" )
@@ -85,11 +86,20 @@ kotlin {
8586 compilerOpts(" -L${libDir.absolutePath} " )
8687 extraOpts(" -libraryPath" , libDir.absolutePath)
8788 }
88-
89- // cinterop tasks processes header files which requires the corresponding CMake build/install to run
90- val cinteropTask = tasks.named(interopSettings.interopProcessingTaskName)
91- cinteropTask.configure {
92- dependsOn(cmakeInstallTask)
89+ val interopTaskName = interopSettings.interopProcessingTaskName
90+
91+ if (! knTarget.isBuildableOnHost) {
92+ logger.warn(" Kotlin/Native target $knTarget is enabled but not buildable on host ${HostManager .host} , disabling cinterop" )
93+ tasks.named(interopTaskName).configure {
94+ onlyIf { false }
95+ }
96+ } else {
97+ logger.info(" Configuring Kotlin/Native target $knTarget : ${knTarget.name} " )
98+ val cmakeInstallTask = configureCrtCMakeBuild(knTarget, CMakeBuildType .Release )
99+ // cinterop tasks processes header files which requires the corresponding CMake build/install to run
100+ tasks.named(interopTaskName).configure {
101+ dependsOn(cmakeInstallTask)
102+ }
93103 }
94104 }
95105 }
@@ -143,3 +153,18 @@ tasks.withType<AbstractTestTask> {
143153 exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat .FULL
144154 }
145155}
156+
157+ // Returns whether this target can be built on the current host
158+ private val KotlinNativeTarget .isBuildableOnHost: Boolean
159+ get() = run {
160+ val family = konanTarget.family
161+ return if (HostManager .hostIsMac) {
162+ family in setOf (Family .OSX , Family .IOS , Family .TVOS , Family .WATCHOS )
163+ } else if (HostManager .hostIsLinux) {
164+ family == Family .LINUX
165+ } else if (HostManager .hostIsMingw) {
166+ family == Family .MINGW
167+ } else {
168+ throw Exception (" Unsupported host: ${HostManager .host} " )
169+ }
170+ }
0 commit comments