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(
internal companion object {
private fun defaultNativeTargets(): Map<KotlinNativePreset, KScienceNativeTarget> {
val hostOs = System.getProperty("os.name")
return when {
hostOs.startsWith("Windows") -> listOf(
KScienceNativeTarget.linuxX64, KScienceNativeTarget.linuxX64,
KScienceNativeTarget.mingwX64, KScienceNativeTarget.mingwX64
)
hostOs == "Mac OS X" -> listOf(
KScienceNativeTarget.macosX64, KScienceNativeTarget.macosX64,
KScienceNativeTarget.macosArm64, KScienceNativeTarget.macosArm64,
KScienceNativeTarget.iosX64, KScienceNativeTarget.iosX64,
KScienceNativeTarget.iosArm64, KScienceNativeTarget.iosArm64,
KScienceNativeTarget.iosSimulatorArm64, KScienceNativeTarget.iosSimulatorArm64,
).associateByTo(mutableMapOf()) { it.preset } )
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,7 +462,6 @@ 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) {
@ -486,6 +506,8 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
// } // }
} }
} }
sourceSets {
val commonMain by getting val commonMain by getting
val commonTest by getting val commonTest by getting