mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
[Gradle] Support for Apple Silicon targets
^KT-45302 Verification Pending
This commit is contained in:
committed by
Space
parent
91e47f1fd7
commit
5dcaaf47cb
@@ -48,9 +48,20 @@ internal val androidPresetEntry = KotlinPresetEntry(
|
||||
)
|
||||
|
||||
// Note: modifying these sets should also be reflected in the MPP plugin code, see 'setupDefaultPresets'
|
||||
private val nativeTargetsWithHostTests = setOf(KonanTarget.LINUX_X64, KonanTarget.MACOS_X64, KonanTarget.MINGW_X64)
|
||||
private val nativeTargetsWithHostTests =
|
||||
setOf(KonanTarget.LINUX_X64, KonanTarget.MACOS_X64, KonanTarget.MACOS_ARM64, KonanTarget.MINGW_X64)
|
||||
private val nativeTargetsWithSimulatorTests =
|
||||
setOf(KonanTarget.IOS_X64, KonanTarget.WATCHOS_X86, KonanTarget.WATCHOS_X64, KonanTarget.TVOS_X64)
|
||||
setOf(
|
||||
KonanTarget.IOS_X64,
|
||||
KonanTarget.IOS_SIMULATOR_ARM64,
|
||||
|
||||
KonanTarget.WATCHOS_X86,
|
||||
KonanTarget.WATCHOS_X64,
|
||||
KonanTarget.WATCHOS_SIMULATOR_ARM64,
|
||||
|
||||
KonanTarget.TVOS_X64,
|
||||
KonanTarget.TVOS_SIMULATOR_ARM64
|
||||
)
|
||||
|
||||
internal val nativePresetEntries = HostManager().targets
|
||||
.map { (_, target) ->
|
||||
@@ -70,4 +81,4 @@ internal val nativePresetEntries = HostManager().targets
|
||||
internal val allPresetEntries = listOf(
|
||||
jvmPresetEntry,
|
||||
androidPresetEntry
|
||||
) + nativePresetEntries
|
||||
) + nativePresetEntries
|
||||
|
||||
@@ -36,7 +36,7 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
name: String,
|
||||
children: List<KotlinSourceSet>,
|
||||
parent: KotlinSourceSet? = null
|
||||
) : KotlinSourceSet =
|
||||
): KotlinSourceSet =
|
||||
sourceSets.maybeCreate(name).apply {
|
||||
parent?.let { dependsOn(parent) }
|
||||
children.forEach {
|
||||
@@ -54,13 +54,32 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
return DefaultSourceSets(main, test)
|
||||
}
|
||||
|
||||
fun macos(
|
||||
namePrefix: String = "macos",
|
||||
configure: KotlinNativeTarget.() -> Unit = {}
|
||||
) {
|
||||
val targets = listOf(
|
||||
macosX64("${namePrefix}X64"),
|
||||
macosArm64("${namePrefix}Arm64")
|
||||
)
|
||||
|
||||
createIntermediateSourceSets(namePrefix, targets.defaultSourceSets(), mostCommonSourceSets())
|
||||
targets.forEach { it.configure() }
|
||||
}
|
||||
|
||||
fun macos() = macos("macos") { }
|
||||
fun macos(namePrefix: String) = macos(namePrefix) { }
|
||||
fun macos(namePrefix: String, configure: Closure<*>) = macos(namePrefix) { ConfigureUtil.configure(configure, this) }
|
||||
fun macos(configure: Closure<*>) = macos { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun ios(
|
||||
namePrefix: String = "ios",
|
||||
configure: KotlinNativeTarget.() -> Unit = {}
|
||||
) {
|
||||
val targets = listOf(
|
||||
iosArm64("${namePrefix}Arm64"),
|
||||
iosX64("${namePrefix}X64")
|
||||
iosX64("${namePrefix}X64"),
|
||||
iosSimulatorArm64("${namePrefix}SimulatorArm64")
|
||||
)
|
||||
createIntermediateSourceSets(namePrefix, targets.defaultSourceSets(), mostCommonSourceSets())
|
||||
targets.forEach { it.configure() }
|
||||
@@ -77,7 +96,8 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
) {
|
||||
val targets = listOf(
|
||||
tvosArm64("${namePrefix}Arm64"),
|
||||
tvosX64("${namePrefix}X64")
|
||||
tvosX64("${namePrefix}X64"),
|
||||
tvosSimulatorArm64("${namePrefix}SimulatorArm64")
|
||||
)
|
||||
createIntermediateSourceSets(namePrefix, targets.defaultSourceSets(), mostCommonSourceSets())
|
||||
targets.forEach { it.configure() }
|
||||
@@ -94,7 +114,8 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
) {
|
||||
val device32 = watchosArm32("${namePrefix}Arm32")
|
||||
val device64 = watchosArm64("${namePrefix}Arm64")
|
||||
val simulator = watchosX64("${namePrefix}X64")
|
||||
val simulatorX64 = watchosX64("${namePrefix}X64")
|
||||
val simulatorArm64 = watchosSimulatorArm64("${namePrefix}SimulatorArm64")
|
||||
val deviceTargets = listOf(device32, device64)
|
||||
|
||||
val deviceSourceSets = createIntermediateSourceSets(
|
||||
@@ -104,11 +125,11 @@ interface KotlinTargetContainerWithNativeShortcuts : KotlinTargetContainerWithPr
|
||||
|
||||
createIntermediateSourceSets(
|
||||
namePrefix,
|
||||
listOf(deviceSourceSets, simulator.defaultSourceSets()),
|
||||
listOf(deviceSourceSets, simulatorX64.defaultSourceSets(), simulatorArm64.defaultSourceSets()),
|
||||
mostCommonSourceSets()
|
||||
)
|
||||
|
||||
listOf(device32, device64, simulator).forEach { it.configure() }
|
||||
listOf(device32, device64, simulatorX64, simulatorArm64).forEach { it.configure() }
|
||||
}
|
||||
|
||||
fun watchos() = watchos("watchos") { }
|
||||
|
||||
@@ -153,6 +153,21 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
fun iosX64(name: String, configure: Closure<*>) = iosX64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun iosX64(configure: Closure<*>) = iosX64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun iosSimulatorArm64(
|
||||
name: String = "iosSimulatorArm64",
|
||||
configure: KotlinNativeTargetWithSimulatorTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithSimulatorTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("iosSimulatorArm64") as KotlinNativeTargetWithSimulatorTestsPreset,
|
||||
configure
|
||||
)
|
||||
|
||||
fun iosSimulatorArm64() = iosSimulatorArm64("iosSimulatorArm64") { }
|
||||
fun iosSimulatorArm64(name: String) = iosSimulatorArm64(name) { }
|
||||
fun iosSimulatorArm64(name: String, configure: Closure<*>) = iosSimulatorArm64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun iosSimulatorArm64(configure: Closure<*>) = iosSimulatorArm64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun watchosArm32(
|
||||
name: String = "watchosArm32",
|
||||
configure: KotlinNativeTarget.() -> Unit = { }
|
||||
@@ -213,6 +228,21 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
fun watchosX64(name: String, configure: Closure<*>) = watchosX64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun watchosX64(configure: Closure<*>) = watchosX64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun watchosSimulatorArm64(
|
||||
name: String = "watchosSimulatorArm64",
|
||||
configure: KotlinNativeTargetWithSimulatorTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithSimulatorTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("watchosSimulatorArm64") as KotlinNativeTargetWithSimulatorTestsPreset,
|
||||
configure
|
||||
)
|
||||
|
||||
fun watchosSimulatorArm64() = watchosSimulatorArm64("watchosSimulatorArm64") { }
|
||||
fun watchosSimulatorArm64(name: String) = watchosSimulatorArm64(name) { }
|
||||
fun watchosSimulatorArm64(name: String, configure: Closure<*>) = watchosSimulatorArm64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun watchosSimulatorArm64(configure: Closure<*>) = watchosSimulatorArm64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun tvosArm64(
|
||||
name: String = "tvosArm64",
|
||||
configure: KotlinNativeTarget.() -> Unit = { }
|
||||
@@ -243,6 +273,21 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
fun tvosX64(name: String, configure: Closure<*>) = tvosX64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun tvosX64(configure: Closure<*>) = tvosX64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun tvosSimulatorArm64(
|
||||
name: String = "tvosSimulatorArm64",
|
||||
configure: KotlinNativeTargetWithSimulatorTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithSimulatorTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("tvosSimulatorArm64") as KotlinNativeTargetWithSimulatorTestsPreset,
|
||||
configure
|
||||
)
|
||||
|
||||
fun tvosSimulatorArm64() = tvosSimulatorArm64("tvosSimulatorArm64") { }
|
||||
fun tvosSimulatorArm64(name: String) = tvosSimulatorArm64(name) { }
|
||||
fun tvosSimulatorArm64(name: String, configure: Closure<*>) = tvosSimulatorArm64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun tvosSimulatorArm64(configure: Closure<*>) = tvosSimulatorArm64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun linuxX64(
|
||||
name: String = "linuxX64",
|
||||
configure: KotlinNativeTargetWithHostTests.() -> Unit = { }
|
||||
@@ -303,6 +348,21 @@ interface KotlinTargetContainerWithPresetFunctions : KotlinTargetsContainerWithP
|
||||
fun macosX64(name: String, configure: Closure<*>) = macosX64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun macosX64(configure: Closure<*>) = macosX64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun macosArm64(
|
||||
name: String = "macosArm64",
|
||||
configure: KotlinNativeTargetWithHostTests.() -> Unit = { }
|
||||
): KotlinNativeTargetWithHostTests =
|
||||
configureOrCreate(
|
||||
name,
|
||||
presets.getByName("macosArm64") as KotlinNativeTargetWithHostTestsPreset,
|
||||
configure
|
||||
)
|
||||
|
||||
fun macosArm64() = macosArm64("macosArm64") { }
|
||||
fun macosArm64(name: String) = macosArm64(name) { }
|
||||
fun macosArm64(name: String, configure: Closure<*>) = macosArm64(name) { ConfigureUtil.configure(configure, this) }
|
||||
fun macosArm64(configure: Closure<*>) = macosArm64 { ConfigureUtil.configure(configure, this) }
|
||||
|
||||
fun linuxArm64(
|
||||
name: String = "linuxArm64",
|
||||
configure: KotlinNativeTarget.() -> Unit = { }
|
||||
|
||||
@@ -185,8 +185,9 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
|
||||
add(KotlinJvmWithJavaTargetPreset(project))
|
||||
|
||||
// Note: modifying these sets should also be reflected in the DSL code generator, see 'presetEntries.kt'
|
||||
val nativeTargetsWithHostTests = setOf(LINUX_X64, MACOS_X64, MINGW_X64)
|
||||
val nativeTargetsWithSimulatorTests = setOf(IOS_X64, WATCHOS_X86, WATCHOS_X64, TVOS_X64)
|
||||
val nativeTargetsWithHostTests = setOf(LINUX_X64, MACOS_X64, MACOS_ARM64, MINGW_X64)
|
||||
val nativeTargetsWithSimulatorTests =
|
||||
setOf(IOS_X64, IOS_SIMULATOR_ARM64, WATCHOS_X86, WATCHOS_X64, WATCHOS_SIMULATOR_ARM64, TVOS_X64, TVOS_SIMULATOR_ARM64)
|
||||
|
||||
HostManager().targets
|
||||
.forEach { (_, konanTarget) ->
|
||||
|
||||
@@ -640,16 +640,15 @@ class KotlinNativeTargetWithSimulatorTestsConfigurator :
|
||||
get() = KotlinNativeSimulatorTestRun::class.java
|
||||
|
||||
override fun isTestTaskEnabled(target: KotlinNativeTargetWithSimulatorTests): Boolean =
|
||||
HostManager.hostIsMac
|
||||
HostManager.hostIsMac && HostManager.host.architecture == target.konanTarget.architecture
|
||||
|
||||
override fun configureTestTask(target: KotlinNativeTargetWithSimulatorTests, testTask: KotlinNativeSimulatorTest) {
|
||||
super.configureTestTask(target, testTask)
|
||||
|
||||
testTask.deviceId = when (target.konanTarget) {
|
||||
KonanTarget.IOS_X64 -> "iPhone 8"
|
||||
KonanTarget.WATCHOS_X86 -> "Apple Watch Series 5 - 44mm"
|
||||
KonanTarget.WATCHOS_X64 -> "Apple Watch Series 5 - 44mm"
|
||||
KonanTarget.TVOS_X64 -> "Apple TV"
|
||||
KonanTarget.IOS_X64, KonanTarget.IOS_SIMULATOR_ARM64 -> "iPhone 8"
|
||||
KonanTarget.WATCHOS_X86, KonanTarget.WATCHOS_X64, KonanTarget.WATCHOS_SIMULATOR_ARM64 -> "Apple Watch Series 5 - 44mm"
|
||||
KonanTarget.TVOS_X64, KonanTarget.TVOS_SIMULATOR_ARM64 -> "Apple TV"
|
||||
else -> error("Simulator tests are not supported for platform ${target.konanTarget.name}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user