Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions aws-crt-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import aws.sdk.kotlin.gradle.kmp.configureIosSimulatorTasks
import aws.sdk.kotlin.gradle.kmp.configureKmpTargets
import aws.sdk.kotlin.gradle.util.typedProp
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.konan.target.Family
import org.jetbrains.kotlin.konan.target.HostManager

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand Down Expand Up @@ -70,8 +72,7 @@ kotlin {
// see: https://github.com/JetBrains/kotlin-native/issues/2423#issuecomment-466300153
targets.withType<KotlinNativeTarget> {
val knTarget = this
logger.info("configuring Kotlin/Native target $knTarget: ${knTarget.name}")
val cmakeInstallTask = configureCrtCMakeBuild(knTarget, CMakeBuildType.Release)

val targetInstallDir = project.cmakeInstallDir(knTarget)
val headerDir = targetInstallDir.resolve("include")
val libDir = targetInstallDir.resolve("lib")
Expand All @@ -85,11 +86,20 @@ kotlin {
compilerOpts("-L${libDir.absolutePath}")
extraOpts("-libraryPath", libDir.absolutePath)
}

// cinterop tasks processes header files which requires the corresponding CMake build/install to run
val cinteropTask = tasks.named(interopSettings.interopProcessingTaskName)
cinteropTask.configure {
dependsOn(cmakeInstallTask)
val interopTaskName = interopSettings.interopProcessingTaskName

if (!knTarget.isBuildableOnHost) {
logger.warn("Kotlin/Native target $knTarget is enabled but not buildable on host ${HostManager.host}, disabling cinterop")
tasks.named(interopTaskName).configure {
onlyIf { false }
}
} else {
logger.info("Configuring Kotlin/Native target $knTarget: ${knTarget.name}")
val cmakeInstallTask = configureCrtCMakeBuild(knTarget, CMakeBuildType.Release)
// cinterop tasks processes header files which requires the corresponding CMake build/install to run
tasks.named(interopTaskName).configure {
dependsOn(cmakeInstallTask)
}
}
}
}
Expand Down Expand Up @@ -143,3 +153,18 @@ tasks.withType<AbstractTestTask> {
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}

// Returns whether this target can be built on the current host
private val KotlinNativeTarget.isBuildableOnHost: Boolean
get() = run {
val family = konanTarget.family
return if (HostManager.hostIsMac) {
family in setOf(Family.OSX, Family.IOS, Family.TVOS, Family.WATCHOS)
} else if (HostManager.hostIsLinux) {
family == Family.LINUX
} else if (HostManager.hostIsMingw) {
family == Family.MINGW
} else {
throw Exception("Unsupported host: ${HostManager.host}")
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin-version = "2.2.0"

aws-kotlin-repo-tools-version = "0.4.47"
aws-kotlin-repo-tools-version = "0.4.48"

# libs
crt-java-version = "0.38.1"
Expand Down