Make selective native targets... again

This commit is contained in:
Alexander Nozik 2023-02-26 22:03:57 +03:00
parent a6755e33f5
commit d0079ba307

View File

@ -47,7 +47,6 @@ public val Project.isInDevelopment: Boolean
|| version.toString().endsWith("SNAPSHOT") || version.toString().endsWith("SNAPSHOT")
private const val defaultJdkVersion = 11 private const val defaultJdkVersion = 11
public open class KScienceExtension(public val project: Project) { public open class KScienceExtension(public val project: Project) {
@ -294,28 +293,50 @@ public data class KScienceNativeTarget(
} }
public class KScienceNativeConfiguration { public class KScienceNativeConfiguration {
internal var targets: MutableMap<KotlinNativePreset, KScienceNativeTarget> = listOf(
KScienceNativeTarget.linuxX64,
KScienceNativeTarget.mingwX64, internal companion object {
KScienceNativeTarget.macosX64, private fun defaultNativeTargets(): Map<KotlinNativePreset, KScienceNativeTarget> {
KScienceNativeTarget.macosArm64,
KScienceNativeTarget.iosX64, val hostOs = System.getProperty("os.name")
KScienceNativeTarget.iosArm64, return when {
KScienceNativeTarget.iosSimulatorArm64, hostOs.startsWith("Windows") -> listOf(
).associateByTo(mutableMapOf()) { it.preset } KScienceNativeTarget.linuxX64,
KScienceNativeTarget.mingwX64
)
hostOs == "Mac OS X" -> listOf(
KScienceNativeTarget.macosX64,
KScienceNativeTarget.macosArm64,
KScienceNativeTarget.iosX64,
KScienceNativeTarget.iosArm64,
KScienceNativeTarget.iosSimulatorArm64,
)
hostOs == "Linux" -> listOf(KScienceNativeTarget.linuxX64)
else -> {
emptyList()
}
}.associateBy { it.preset }
}
}
internal var targets: Map<KotlinNativePreset, KScienceNativeTarget> = defaultNativeTargets()
/** /**
* Replace all targets * Replace all targets
*/ */
public fun setTargets(vararg target: KScienceNativeTarget) { public fun setTargets(vararg target: KScienceNativeTarget) {
targets = target.associateByTo(mutableMapOf()) { it.preset } targets = target.associateBy { it.preset }
} }
/** /**
* Add a native target * Add a native target
*/ */
public fun target(target: KScienceNativeTarget) { public fun target(target: KScienceNativeTarget) {
targets[target.preset] = target targets += target.preset to target
} }
public fun target( public fun target(
@ -441,51 +462,52 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
val nativeConfiguration = KScienceNativeConfiguration().apply(block) val nativeConfiguration = KScienceNativeConfiguration().apply(block)
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
sourceSets { val nativeTargets: List<KotlinNativeTarget> =
val nativeTargets: List<KotlinNativeTarget> = nativeConfiguration.targets.values.map { nativeTarget ->
nativeConfiguration.targets.values.map { nativeTarget -> when (nativeTarget.preset) {
when (nativeTarget.preset) { KotlinNativePreset.linuxX64 -> linuxX64(
KotlinNativePreset.linuxX64 -> linuxX64( nativeTarget.targetName,
nativeTarget.targetName, nativeTarget.targetConfiguration
nativeTarget.targetConfiguration )
)
KotlinNativePreset.mingwX64 -> mingwX64( KotlinNativePreset.mingwX64 -> mingwX64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.macosX64 -> macosX64( KotlinNativePreset.macosX64 -> macosX64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.macosArm64 -> macosArm64( KotlinNativePreset.macosArm64 -> macosArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.iosX64 -> iosX64( KotlinNativePreset.iosX64 -> iosX64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.iosArm64 -> iosArm64( KotlinNativePreset.iosArm64 -> iosArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.iosSimulatorArm64 -> iosSimulatorArm64( KotlinNativePreset.iosSimulatorArm64 -> iosSimulatorArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
// else -> { // else -> {
// logger.error("Native preset ${nativeTarget.preset} not recognised.") // logger.error("Native preset ${nativeTarget.preset} not recognised.")
// null // null
// } // }
}
} }
}
sourceSets {
val commonMain by getting val commonMain by getting
val commonTest by getting val commonTest by getting