Skip to content

Commit ede21b3

Browse files
committed
合并 #39、本地验证以及调整 sample 结构
1 parent 15b78c3 commit ede21b3

File tree

18 files changed

+401
-70
lines changed

18 files changed

+401
-70
lines changed

buildSrc/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
13
plugins {
24
`kotlin-dsl`
35
`kotlin-dsl-precompiled-script-plugins`
@@ -31,6 +33,8 @@ dependencies {
3133
implementation("love.forte.gradle.common:gradle-common-publication:$gradleCommon")
3234
}
3335

36+
val compileKotlin: KotlinCompile by tasks
37+
compileKotlin.kotlinOptions.freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn")
3438

3539
// tasks.test {
3640
// useJUnitPlatform()

buildSrc/src/main/kotlin/IProject.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object IProject : ProjectDetail() {
99
const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions"
1010
const val HOMEPAGE = "https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin"
1111

12-
override val version: Version = version(0, 5, 1) - version("local-test-4")
12+
override val version: Version = version(0, 6, 0) - version("local-test-1")
1313

1414
override val homepage: String get() = HOMEPAGE
1515

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ kotlin.mpp.stability.nowarn=true
44
kotlin.native.ignoreDisabledTargets=true
55

66
org.gradle.jvmargs=-Xmx8G -Xms2G -XX:MaxMetaspaceSize=1G -Dfile.encoding=UTF-8
7+
8+
# test
9+
kotlin.js.ir.output.granularity=per-file

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
2+
13
plugins {
24
kotlin("multiplatform")
35
id("suspend-transform.multiplatform-maven-publish")
@@ -48,6 +50,10 @@ kotlin {
4850
mingwX64()
4951
watchosDeviceArm64()
5052

53+
// wasm
54+
@OptIn(ExperimentalWasmDsl::class)
55+
wasmJs()
56+
5157
// withKotlinTargets { target ->
5258
// targets.findByName(target.name)?.compilations?.all {
5359
// // 'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. You can use -Xexpect-actual-classes flag to suppress this warning. Also see: https://youtrack.jetbrains.com/issue/KT-61573

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

Lines changed: 79 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55

66
kotlin {
77
explicitApi()
8+
applyDefaultHierarchyTemplate()
89

910
jvm {
1011
compilations.all {
@@ -20,78 +21,95 @@ kotlin {
2021
nodejs()
2122
}
2223

23-
val mainPresets = mutableSetOf<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>()
24-
val testPresets = mutableSetOf<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>()
24+
// tier1
25+
linuxX64()
26+
macosX64()
27+
macosArm64()
28+
iosSimulatorArm64()
29+
iosX64()
2530

26-
// K/N target supports
27-
// https://kotlinlang.org/docs/native-target-support.html
28-
val supportTargets = setOf(
29-
// Tier 1
30-
"linuxX64",
31-
"macosX64",
32-
"macosArm64",
33-
"iosSimulatorArm64",
34-
"iosX64",
31+
// tier2
32+
linuxArm64()
33+
watchosSimulatorArm64()
34+
watchosX64()
35+
watchosArm32()
36+
watchosArm64()
37+
tvosSimulatorArm64()
38+
tvosX64()
39+
tvosArm64()
40+
iosArm64()
3541

36-
// Tier 2
37-
"linuxArm64",
38-
"watchosSimulatorArm64",
39-
"watchosX64",
40-
"watchosArm32",
41-
"watchosArm64",
42-
"tvosSimulatorArm64",
43-
"tvosX64",
44-
"tvosArm64",
45-
"iosArm64",
42+
// tier3
43+
androidNativeArm32()
44+
androidNativeArm64()
45+
androidNativeX86()
46+
androidNativeX64()
47+
mingwX64()
48+
watchosDeviceArm64()
4649

47-
// Tier 3
48-
"androidNativeArm32",
49-
"androidNativeArm64",
50-
"androidNativeX86",
51-
"androidNativeX64",
52-
"mingwX64",
53-
"watchosDeviceArm64",
54-
)
50+
// wasm
51+
// @OptIn(ExperimentalWasmDsl::class)
52+
// wasmJs()
5553

56-
targets {
57-
presets.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeTargetPreset<*>>()
58-
.filter { it.name in supportTargets }
59-
.forEach { presets ->
60-
val target = fromPreset(presets, presets.name)
61-
val mainSourceSet = target.compilations["main"].kotlinSourceSets.first()
62-
val testSourceSet = target.compilations["test"].kotlinSourceSets.first()
63-
mainPresets.add(mainSourceSet)
64-
testPresets.add(testSourceSet)
65-
}
66-
}
54+
// val mainPresets = mutableSetOf<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>()
55+
// val testPresets = mutableSetOf<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>()
56+
//
57+
// // K/N target supports
58+
// // https://kotlinlang.org/docs/native-target-support.html
59+
// val supportTargets = setOf(
60+
// // Tier 1
61+
// "linuxX64",
62+
// "macosX64",
63+
// "macosArm64",
64+
// "iosSimulatorArm64",
65+
// "iosX64",
66+
//
67+
// // Tier 2
68+
// "linuxArm64",
69+
// "watchosSimulatorArm64",
70+
// "watchosX64",
71+
// "watchosArm32",
72+
// "watchosArm64",
73+
// "tvosSimulatorArm64",
74+
// "tvosX64",
75+
// "tvosArm64",
76+
// "iosArm64",
77+
//
78+
// // Tier 3
79+
// "androidNativeArm32",
80+
// "androidNativeArm64",
81+
// "androidNativeX86",
82+
// "androidNativeX64",
83+
// "mingwX64",
84+
// "watchosDeviceArm64",
85+
// )
86+
//
87+
// targets {
88+
// presets.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeTargetPreset<*>>()
89+
// .filter { it.name in supportTargets }
90+
// .forEach { presets ->
91+
// val target = fromPreset(presets, presets.name)
92+
// val mainSourceSet = target.compilations["main"].kotlinSourceSets.first()
93+
// val testSourceSet = target.compilations["test"].kotlinSourceSets.first()
94+
// mainPresets.add(mainSourceSet)
95+
// testPresets.add(testSourceSet)
96+
// }
97+
// }
6798

6899
sourceSets {
69-
val commonMain by getting {
70-
dependencies {
71-
implementation(project(":runtime:suspend-transform-annotation"))
72-
implementation(libs.kotlinx.coroutines.core)
73-
}
100+
commonMain.dependencies {
101+
implementation(project(":runtime:suspend-transform-annotation"))
102+
implementation(libs.kotlinx.coroutines.core)
74103
}
75104

76-
val commonTest by getting {
77-
dependencies {
78-
implementation(kotlin("test"))
79-
implementation(libs.kotlinx.coroutines.test)
80-
}
105+
commonTest.dependencies {
106+
implementation(kotlin("test"))
107+
implementation(libs.kotlinx.coroutines.test)
81108
}
82109

83-
getByName("jvmMain") {
84-
dependencies {
85-
implementation(libs.kotlinx.coroutines.jdk8)
86-
}
110+
jvmMain.dependencies {
111+
implementation(libs.kotlinx.coroutines.jdk8)
87112
}
88-
89-
val nativeMain by creating { dependsOn(commonMain) }
90-
val nativeTest by creating { dependsOn(commonTest) }
91-
92-
configure(mainPresets) { dependsOn(nativeMain) }
93-
configure(testPresets) { dependsOn(nativeTest) }
94-
95113
}
96114

97115
}

samples/sample-js/build.gradle.kts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import love.forte.plugin.suspendtrans.ClassInfo
2+
import love.forte.plugin.suspendtrans.SuspendTransformConfiguration
3+
import love.forte.plugin.suspendtrans.TargetPlatform
4+
import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension
5+
6+
plugins {
7+
kotlin("multiplatform")
8+
}
9+
10+
11+
buildscript {
12+
this@buildscript.repositories {
13+
mavenLocal()
14+
mavenCentral()
15+
}
16+
dependencies {
17+
classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:0.6.0-local-test-1")
18+
}
19+
}
20+
21+
repositories {
22+
mavenLocal()
23+
}
24+
25+
apply(plugin = "love.forte.plugin.suspend-transform")
26+
27+
kotlin {
28+
js(IR) {
29+
nodejs()
30+
useEsModules()
31+
generateTypeScriptDefinitions()
32+
binaries.executable()
33+
compilations.all {
34+
kotlinOptions {
35+
useEsClasses = true
36+
}
37+
}
38+
}
39+
40+
sourceSets {
41+
named("jsMain") {
42+
dependencies {
43+
implementation(kotlin("stdlib"))
44+
// val pluginVersion = "0.4.0"
45+
// api("love.forte.plugin.suspend-transform:suspend-transform-runtime:$pluginVersion")
46+
// api("love.forte.plugin.suspend-transform:suspend-transform-annotation:$pluginVersion")
47+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
48+
}
49+
}
50+
}
51+
}
52+
53+
54+
55+
extensions.getByType<SuspendTransformGradleExtension>().apply {
56+
transformers[TargetPlatform.JS] = mutableListOf(
57+
SuspendTransformConfiguration.jsPromiseTransformer.copy(
58+
copyAnnotationExcludes = listOf(
59+
ClassInfo("kotlin.js", "JsExport.Ignore")
60+
)
61+
)
62+
)
63+
64+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@file:OptIn(ExperimentalJsExport::class)
2+
3+
import kotlinx.coroutines.CoroutineScope
4+
import kotlinx.coroutines.delay
5+
import love.forte.plugin.suspendtrans.annotation.JsPromise
6+
import kotlin.coroutines.CoroutineContext
7+
import kotlin.coroutines.EmptyCoroutineContext
8+
9+
@JsExport
10+
abstract class IForteScarlet {
11+
@JsPromise
12+
@JsExport.Ignore
13+
abstract suspend fun stringToInt(value: String): Int
14+
}
15+
16+
17+
/**
18+
*
19+
* @author ForteScarlet
20+
*/
21+
@Suppress("NON_EXPORTABLE_TYPE")
22+
@JsExport
23+
class ForteScarlet : CoroutineScope, IForteScarlet() {
24+
override val coroutineContext: CoroutineContext
25+
get() = EmptyCoroutineContext
26+
27+
@JsPromise
28+
@JsExport.Ignore
29+
override suspend fun stringToInt(value: String): Int {
30+
delay(5)
31+
return value.toInt()
32+
}
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import kotlin.js.Promise
2+
3+
suspend fun main() {
4+
// runInAsync(block = SuspendFun()).await()
5+
Promise // keep import
6+
7+
println(ForteScarlet().stringToInt("1"))
8+
// println(ForteScarlet().stringToIntAsync("1"))
9+
// println(ForteScarlet().stringToIntAsync("1").await())
10+
}

samples/sample-jvm/build.gradle.kts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension
2+
3+
plugins {
4+
`java-library`
5+
kotlin("jvm")
6+
// id("love.forte.plugin.suspend-transform")
7+
// id("suspend-transform.jvm-maven-publish")
8+
// id(project(":suspend-transform-plugin-gradle"))
9+
}
10+
11+
12+
buildscript {
13+
this@buildscript.repositories {
14+
mavenLocal()
15+
mavenCentral()
16+
}
17+
dependencies {
18+
//this.implementation()
19+
classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:0.6.0-local-test-1")
20+
}
21+
}
22+
23+
24+
//withType<JavaCompile> {
25+
// sourceCompatibility = "11"
26+
// targetCompatibility = "11"
27+
//}
28+
29+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
30+
kotlinOptions.freeCompilerArgs += "-Xjvm-default=all"
31+
}
32+
33+
repositories {
34+
mavenLocal()
35+
}
36+
37+
apply(plugin = "love.forte.plugin.suspend-transform")
38+
39+
dependencies {
40+
api(kotlin("stdlib"))
41+
// val pluginVersion = "0.4.0"
42+
// api("love.forte.plugin.suspend-transform:suspend-transform-runtime:$pluginVersion")
43+
// api("love.forte.plugin.suspend-transform:suspend-transform-annotation:$pluginVersion")
44+
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
45+
}
46+
47+
extensions.getByType<SuspendTransformGradleExtension>().apply {
48+
println(this)
49+
this.useJvmDefault()
50+
}

0 commit comments

Comments
 (0)