Skip to content

Commit

Permalink
Merge pull request #45 from ForteScarlet/dev-k2
Browse files Browse the repository at this point in the history
Support K2
  • Loading branch information
ForteScarlet committed Jan 25, 2024
2 parents 7795d55 + 2e82f83 commit ec75285
Show file tree
Hide file tree
Showing 60 changed files with 3,851 additions and 281 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
jobs:
test-build-publish:
name: Test and build
# runs-on: ubuntu-latest
# runs-on: ubuntu-latest
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
Expand Down Expand Up @@ -96,17 +96,35 @@ jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
needs: [test-build-publish, publish-gradle-plugin]
needs: [ test-build-publish, publish-gradle-plugin ]
permissions:
contents: write
steps:
# 检出仓库代码
- name: Check out repo
uses: actions/checkout@v3

# Setup java
# https://github.com/marketplace/actions/setup-java-jdk
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11

- name: Create changelog
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.5
arguments: createChangelog

# https://github.com/softprops/action-gh-release
# Create gitHub release
- name: Create Github Release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.FORTE_TOKEN }}
draft: true
# body_path: .changelog/${{ github.ref_name }}.md
body_path: .changelog/${{ github.ref_name }}.md
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, 'preview') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gradle
.kotlin
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
Expand Down Expand Up @@ -28,4 +29,4 @@ out/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Foo {
### WasmJS

> [!warning]
> Since `v0.6.0`, In experiments, immature and unstable
```kotlin
Expand Down Expand Up @@ -258,6 +259,13 @@ suspendTransform {

**Gradle JVM** must be JDK11+

### K2

K2 is supported since `v0.7.0`.

> [!warning]
> In experiments.
## Effect

**source:**
Expand Down
8 changes: 8 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Foo {
### WasmJS

> [!warning]
> `v0.6.0` 开始支持,实验中,不成熟、不稳定。
```kotlin
Expand Down Expand Up @@ -257,6 +258,13 @@ suspendTransform {

Gradle JVM 必须满足 JDK11+

### K2

K2 编译器从 `v0.7.0` 开始支持。

> [!warning]
> 实验中。
## 效果

**源代码:**
Expand Down
13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ allprojects {

apply(plugin = "suspend-transform.nexus-publish")

tasks.create("createChangelog") {
group = "documentation"
doFirst {
val tag = "v${IProject.version}"
val changelogDir = rootProject.file(".changelog").apply { mkdirs() }
with(File(changelogDir, "$tag.md")) {
if (!exists()) {
createNewFile()
}
writeText("Kotlin version: `v${libs.versions.kotlin.get()}`")
}
}
}
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
gradlePluginPortal()
}

val kotlinVersion = "1.9.21"
val kotlinVersion: String = libs.versions.kotlin.get()
val dokkaPluginVersion = "1.9.10"
val gradleCommon = "0.2.0"
val nexusPublishPlugin = "1.3.0"
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/IProject.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import love.forte.gradle.common.core.project.ProjectDetail
import love.forte.gradle.common.core.project.Version
import love.forte.gradle.common.core.project.minus
import love.forte.gradle.common.core.project.version

object IProject : ProjectDetail() {
Expand All @@ -8,7 +9,7 @@ object IProject : ProjectDetail() {
const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions"
const val HOMEPAGE = "https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin"

override val version: Version = version(0, 6, 0)
override val version: Version = version(0, 7, 0) - version("dev2")

override val homepage: String get() = HOMEPAGE

Expand Down
74 changes: 66 additions & 8 deletions compiler/suspend-transform-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {

//testWithEmbedded0()


dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("compiler"))
Expand All @@ -22,25 +23,41 @@ dependencies {
kapt(libs.google.auto.service)
compileOnly(libs.google.auto.service.annotations)

testImplementation("junit:junit:4.13.2")
testImplementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))
testImplementation(kotlin("compiler-embeddable"))
testImplementation(kotlin("reflect"))
// testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
testImplementation(kotlin("test-junit5"))

testImplementation(kotlin("compiler"))
testImplementation(kotlin("reflect"))
// see https://github.com/Icyrockton/xjson
testImplementation(kotlin("compiler-internal-test-framework")) // compiler plugin test generator / test utils
testRuntimeOnly(kotlin("test"))
testRuntimeOnly(kotlin("script-runtime"))
testRuntimeOnly(kotlin("annotations-jvm"))
testImplementation(project(":runtime:suspend-transform-annotation"))
testImplementation(project(":runtime:suspend-transform-runtime"))

testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
// testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
// testImplementation("org.bitbucket.mstrobel:procyon-compilertools:0.6.0")
// testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:1.7.10.2-SNAPSHOT")

testImplementation(libs.kotlinx.coroutines.core)
// testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4")
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions.freeCompilerArgs += listOf("-Xjvm-default=all", "-opt-in=kotlin.RequiresOptIn")
compileKotlin.kotlinOptions.freeCompilerArgs += listOf(
"-Xjvm-default=all",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI",
)

tasks.withType(KotlinCompile::class.java).configureEach {
// see https://youtrack.jetbrains.com/issue/KTIJ-21563
// see https://youtrack.jetbrains.com/issue/KT-57297
// kotlinOptions {
// languageVersion = "1.9"
// apiVersion = "1.9"
// }
}

repositories {
maven {
Expand All @@ -62,3 +79,44 @@ buildConfig {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}


sourceSets {
test{
kotlin.srcDir("src/test")
kotlin.srcDir("src/test-gen")
java.srcDir("src/test-gen")
}
}

task<JavaExec>("generateTest") {
classpath = sourceSets.test.get().runtimeClasspath
mainClass = "love.forte.plugin.suspendtrans.GenerateTestsKt"
}

// add following properties for test
tasks.test {
useJUnitPlatform()
doFirst {
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib-jdk8", "kotlin-stdlib-jdk8")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-test", "kotlin-test")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-script-runtime", "kotlin-script-runtime")
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-annotations-jvm", "kotlin-annotations-jvm")
}
}

fun Test.setLibraryProperty(propName: String, jarName: String) {
val path = project.configurations
.testRuntimeClasspath.get()
.files
.find { """$jarName-\d.*jar""".toRegex().matches(it.name) }
?.absolutePath
?: return
systemProperty(propName, path)
}

/*
上面与测试相关的一些内容参考自 https://github.com/Icyrockton/xjson
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package love.forte.plugin.suspendtrans

const val PLUGIN_REPORT_ID = "love.forte.plugin.suspendtrans.SuspendTransform"
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package love.forte.plugin.suspendtrans

import com.google.auto.service.AutoService
import love.forte.plugin.suspendtrans.fir.SuspendTransformFirExtensionRegistrar
import love.forte.plugin.suspendtrans.ir.SuspendTransformIrGenerationExtension
import love.forte.plugin.suspendtrans.symbol.SuspendTransformSyntheticResolveExtension
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension

@OptIn(ExperimentalCompilerApi::class)
Expand All @@ -19,32 +21,34 @@ class SuspendTransformComponentRegistrar : CompilerPluginRegistrar() {
get() = true

override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
val suspendTransformConfiguration =/* defaultConfiguration ?: */
configuration.resolveToSuspendTransformConfiguration()
register(this, configuration)
}

val suspendTransformSyntheticResolveExtension =
SuspendTransformSyntheticResolveExtension(suspendTransformConfiguration)

val suspendTransformIrGenerationExtension = SuspendTransformIrGenerationExtension(suspendTransformConfiguration)
companion object {
fun register(storage: ExtensionStorage, configuration: CompilerConfiguration) {
val suspendTransformConfiguration =/* defaultConfiguration ?: */
configuration.resolveToSuspendTransformConfiguration()

SyntheticResolveExtension.registerExtension(suspendTransformSyntheticResolveExtension)
IrGenerationExtension.registerExtension(suspendTransformIrGenerationExtension)
}
register(storage, suspendTransformConfiguration)
}

fun register(storage: ExtensionStorage, configuration: SuspendTransformConfiguration) {
val suspendTransformSyntheticResolveExtension =
SuspendTransformSyntheticResolveExtension(configuration)
val suspendTransformFirExtensionRegistrar =
SuspendTransformFirExtensionRegistrar(configuration)

val suspendTransformIrGenerationExtension =
SuspendTransformIrGenerationExtension(configuration)

// override fun registerProjectComponents(
// project: MockProject,
// configuration: CompilerConfiguration,
// ) {
//
// val suspendTransformConfiguration =/* defaultConfiguration ?: */configuration.resolveToSuspendTransformConfiguration()
//
// if (suspendTransformConfiguration.enabled) {
// SyntheticResolveExtension.registerExtension(project, SuspendTransformSyntheticResolveExtension(suspendTransformConfiguration))
// IrGenerationExtension.registerExtension(project, SuspendTransformIrGenerationExtension(suspendTransformConfiguration))
// }
// }
with(storage) {
SyntheticResolveExtension.registerExtension(suspendTransformSyntheticResolveExtension)
FirExtensionRegistrarAdapter.registerExtension(suspendTransformFirExtensionRegistrar)
IrGenerationExtension.registerExtension(suspendTransformIrGenerationExtension)
}
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class FunctionInfo(
data class ClassInfo @JvmOverloads constructor(
var packageName: String,
var className: String,
var local: Boolean = false
var local: Boolean = false,
var nullable: Boolean = false,
)

@Serializable
Expand Down
Loading

0 comments on commit ec75285

Please sign in to comment.