forked from icerockdev/moko-resources
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppleSdk.kt
More file actions
89 lines (82 loc) · 3.79 KB
/
Copy pathAppleSdk.kt
File metadata and controls
89 lines (82 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
* https://github.com/JetBrains/kotlin/blob/e1df52bc0255d24651141f5a2094d3ab7e61d4d2/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/AppleSdk.kt
* */
@file:Suppress("Wrapping")
package dev.icerock.gradle.utils
import org.jetbrains.kotlin.konan.target.KonanTarget
internal object AppleSdk {
@Suppress("ThrowsCount", "LongMethod", "CyclomaticComplexMethod")
fun defineNativeTargets(platform: String, archs: List<String>): List<KonanTarget> {
class UnknownArchitectureException(platform: String, arch: String) :
IllegalArgumentException("Architecture $arch is not supported for platform $platform")
val targets: MutableSet<KonanTarget> = mutableSetOf()
when {
platform.startsWith("iphoneos") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"arm64", "arm64e" -> KonanTarget.IOS_ARM64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
platform.startsWith("iphonesimulator") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"arm64", "arm64e" -> KonanTarget.IOS_SIMULATOR_ARM64
"x86_64" -> KonanTarget.IOS_X64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
platform.startsWith("watchos") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"armv7k" -> KonanTarget.WATCHOS_ARM32
"arm64_32" -> KonanTarget.WATCHOS_ARM64
"arm64" -> KonanTarget.WATCHOS_DEVICE_ARM64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
platform.startsWith("watchsimulator") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"arm64", "arm64e" -> KonanTarget.WATCHOS_SIMULATOR_ARM64
"x86_64" -> KonanTarget.WATCHOS_X64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
platform.startsWith("appletvos") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"arm64", "arm64e" -> KonanTarget.TVOS_ARM64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
platform.startsWith("appletvsimulator") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"arm64", "arm64e" -> KonanTarget.TVOS_SIMULATOR_ARM64
"x86_64" -> KonanTarget.TVOS_X64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
platform.startsWith("macosx") -> {
targets.addAll(archs.map { arch ->
when (arch) {
"arm64" -> KonanTarget.MACOS_ARM64
"x86_64" -> KonanTarget.MACOS_X64
else -> throw UnknownArchitectureException(platform, arch)
}
})
}
else -> throw IllegalArgumentException("Platform $platform is not supported")
}
return targets.toList()
}
}