Skip to content

Commit ea91ce3

Browse files
authored
合并拉取请求 #8
runtime模块和annotation模块支持native平台目标
2 parents 2ba2340 + 77c99d7 commit ea91ce3

File tree

6 files changed

+94
-56
lines changed

6 files changed

+94
-56
lines changed

.idea/gradle.xml

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,70 @@
1+
import org.gradle.api.InvalidUserCodeException
12
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
3+
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
4+
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
5+
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainerWithPresets
6+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
7+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
28

3-
fun KotlinMultiplatformExtension.configAllNativeTargets() {
4-
iosArm32()
5-
iosArm64()
6-
iosX64()
7-
watchosArm32()
8-
watchosArm64()
9-
watchosX86()
10-
tvosArm64()
11-
tvosX64()
12-
linuxX64()
13-
linuxArm32Hfp()
14-
linuxArm64()
15-
linuxMips32()
16-
linuxMipsel32()
17-
mingwX64()
18-
mingwX86()
19-
macosX64()
20-
wasm32()
21-
}
9+
private val coroutinesUnsupportedTargets = setOf(
10+
"androidNativeArm32",
11+
"androidNativeArm64",
12+
"androidNativeX64",
13+
"androidNativeX86",
14+
"linuxArm32Hfp",
15+
"linuxArm64",
16+
"linuxMips32",
17+
"linuxMipsel32",
18+
"mingwX86",
19+
"wasm32",
20+
)
21+
22+
fun KotlinMultiplatformExtension.configAllNativeTargets(
23+
filter: KotlinNativeTargetPreset.() -> Boolean = { true },
24+
configureEach: KotlinNativeTarget.() -> Unit = { }
25+
) {
26+
presets.all {
27+
if (this !is KotlinNativeTargetPreset || !filter(this)) return@all
28+
println(this)
29+
println(this.name)
30+
configureOrCreate(name, this, configureEach)
31+
}
32+
}
33+
34+
fun KotlinMultiplatformExtension.configAllNativeTargetsCoroutinesSupported(configureEach: KotlinNativeTarget.() -> Unit = { }) {
35+
configAllNativeTargets(filter = { name !in coroutinesUnsupportedTargets }, configureEach = configureEach)
36+
}
37+
38+
internal fun KotlinTarget.isProducedFromPreset(kotlinTargetPreset: KotlinTargetPreset<*>): Boolean =
39+
preset == kotlinTargetPreset
40+
41+
internal fun <T : KotlinTarget> KotlinTargetsContainerWithPresets.configureOrCreate(
42+
targetName: String,
43+
targetPreset: KotlinTargetPreset<T>,
44+
configure: T.() -> Unit
45+
): T {
46+
val existingTarget = targets.findByName(targetName)
47+
when {
48+
existingTarget?.isProducedFromPreset(targetPreset) ?: false -> {
49+
@Suppress("UNCHECKED_CAST")
50+
configure(existingTarget as T)
51+
return existingTarget
52+
}
53+
54+
existingTarget == null -> {
55+
val newTarget = targetPreset.createTarget(targetName)
56+
targets.add(newTarget)
57+
configure(newTarget)
58+
return newTarget
59+
}
60+
61+
else -> {
62+
throw InvalidUserCodeException(
63+
"The target '$targetName' already exists, but it was not created with the '${targetPreset.name}' preset. " +
64+
"To configure it, access it by name in `kotlin.targets`" +
65+
(" or use the preset function '${existingTarget.preset?.name}'."
66+
.takeIf { existingTarget.preset != null } ?: ".")
67+
)
68+
}
69+
}
70+
}

runtime/suspend-transform-annotation/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ kotlin {
2121
nodejs()
2222
}
2323

24+
configAllNativeTargets()
25+
2426
sourceSets {
2527
val commonMain by getting
2628
}

runtime/suspend-transform-runtime/build.gradle.kts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ kotlin {
2020
nodejs()
2121
//binaries.executable()
2222
}
23-
24-
// Only Jvm and JS
25-
// configAllNativeTargets()
26-
// val nativeTargetSourceNames = targets.flatMapTo(mutableSetOf()) { target ->
27-
// if (target.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native) {
28-
// val name = target.name
29-
// listOf("${name}Main", "${name}Test")
30-
// } else {
31-
// emptyList()
32-
// }
33-
// }
23+
24+
configAllNativeTargetsCoroutinesSupported()
25+
26+
// val nativeTargetSourceNames = targets.flatMapTo(mutableSetOf()) { target ->
27+
// if (target.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native) {
28+
// val name = target.name
29+
// listOf("${name}Main", "${name}Test")
30+
// } else {
31+
// emptyList()
32+
// }
33+
// }
3434

3535
sourceSets {
3636
val commonMain by getting {

suspend-transform-plugin-sample/build.gradle.kts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
plugins {
22
`java-library`
33
kotlin("jvm")
4-
id("love.forte.plugin.suspend-transform")
5-
id("suspend-transform.jvm-maven-publish")
4+
// id("love.forte.plugin.suspend-transform")
5+
// id("suspend-transform.jvm-maven-publish")
66
// id(project(":suspend-transform-plugin-gradle"))
77
}
88

9-
// buildscript {
10-
// this@buildscript.repositories {
11-
// mavenLocal()
12-
// mavenCentral()
13-
// }
14-
// dependencies {
15-
// classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:0.0.1")
16-
// }
17-
// }
9+
buildscript {
10+
this@buildscript.repositories {
11+
mavenLocal()
12+
mavenCentral()
13+
}
14+
dependencies {
15+
//this.implementation()
16+
//classpath(project(":plugins:suspend-transform-plugin-gradle"))
17+
}
18+
}
1819

1920
//withType<JavaCompile> {
2021
// sourceCompatibility = "11"

suspend-transform-tests/suspend-transform-test-js/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
kotlin("js")
3-
id("love.forte.plugin.suspend-transform")
3+
//id("love.forte.plugin.suspend-transform")
44
// id(project(":suspend-transform-plugin-gradle"))
55
}
66

0 commit comments

Comments
 (0)