Luca
11/01/2023, 8:28 PMobject Targets {
val iosTargets = arrayOf("iosArm64", "iosX64", "iosSimulatorArm64")
val tvosTargets = arrayOf("tvosArm64", "tvosX64", "tvosSimulatorArm64")
val watchosTargets = arrayOf(
"watchosArm32", "watchosArm64", "watchosX64", "watchosSimulatorArm64", "watchosDeviceArm64"
)
val macosTargets = arrayOf("macosX64", "macosArm64")
val darwinTargets = iosTargets + tvosTargets + watchosTargets + macosTargets
val linuxTargets = arrayOf("linuxX64", "linuxArm64")
val mingwTargets = arrayOf("mingwX64")
val androidTargets = arrayOf(
"androidNativeArm32", "androidNativeArm64", "androidNativeX86", "androidNativeX64",
)
val nativeTargets = linuxTargets + darwinTargets + mingwTargets + androidTargets
}
kotlin {
for (target in Targets.nativeTargets) {
targets.add(presets.getByName(target).createTarget(target))
}
}
createTarget
is being depreciated and this has been useful for me to cut down boilerplate especially when I share object Targets
across multiple modulesdsavvinov
11/02/2023, 3:42 PMobject Targets {
fun KotlinMultiplatformExtension.iosTargets() {
iosArm64()
iosSimulatorArm64()
iosX64()
}
fun KotlinMultiplatformExtension.watchosTargets() {
watchosArm32()
watchosArm64()
watchosX64()
watchosSimulatorArm64()
watchosDeviceArm64()
}
// ... etc ..
fun KotlinMultiplatformExtension.allNativeTargets() {
iosTargets()
watchosTargets()
// ...
}
}
kotlin {
with(Targets) { allNativeTargets() }
}
Of course, you can play with the specific organization/syntax to suit your liking (e.g., pass KotlinMultiplatformExtension
as parameter instead of receiver, or omit the Target
object to not have with
-call, etc.)
P.S. If you really need to operate with collections of strings, then you’ll have write a when
which maps those strings to invocations of specific targets on KotlinMultiplatformExtension
(see, for example, how Apollo Kotlin project does that)
ILuca
11/02/2023, 4:07 PM