Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KRPC-18 Add K2 and IR code generation plugins, preserve KSP for K1 #105

Merged
merged 17 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Ignore Gradle build output directory
build
.kotlin

# idea files
.idea/*
Expand All @@ -17,6 +18,7 @@ build
!.idea/codeStyles/*
!.idea/icon.svg
!.idea/detekt.xml
!.idea/kotlinTestDataPluginTestDataPaths.xml

.DS_Store

Expand Down
19 changes: 19 additions & 0 deletions .idea/kotlinTestDataPluginTestDataPaths.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
*/

import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import util.kotlinVersionParsed

plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kotlinx.rpc) apply false
alias(libs.plugins.atomicfu) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.kover.root.project) apply false
alias(libs.plugins.conventions.kover)
alias(libs.plugins.binary.compatibility.validator)
}

// useful for dependencies introspection
// run ./gradlew htmlDependencyReport
// Report can normally be found in build/reports/project/dependencies/index.html
allprojects {
plugins.apply("project-report")
}

object Const {
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.InternalRPCApi"
}
Expand All @@ -24,8 +30,7 @@ apiValidation {

ignoredProjects.addAll(
listOf(
"codegen-tests-jvm",
"codegen-tests-mpp",
"compiler-plugin-tests",
"krpc-test",
"utils",
)
Expand All @@ -34,11 +39,7 @@ apiValidation {
nonPublicMarkers.add(Const.INTERNAL_RPC_API_ANNOTATION)
}

val kotlinVersion: String by extra

if (kotlinVersion >= "1.8.0") {
apply(plugin = libs.plugins.kover.root.project.get().pluginId)
}
val kotlinVersion: KotlinVersion by extra

allprojects {
group = "org.jetbrains.kotlinx"
Expand All @@ -47,11 +48,11 @@ allprojects {

println("kotlinx.rpc project version: $version, Kotlin version: $kotlinVersion")

// If the prefix of the kPRC version is not Kotlin gradle plugin version - you have a problem :)
// Probably some dependency brings kotlin with higher version.
// To mitigate so, please refer to `gradle/kotlin-version-lookup.json`
// and it's usage in `gradle-settings-conventions/src/main/kotlin/settings-conventions.settings.gradle.kts`
val kotlinGPVersion = getKotlinPluginVersion()
// If the prefix of the kPRC version is not Kotlin gradle plugin version you have a problem :)
// Probably some dependency brings kotlin with the later version.
// To mitigate so, refer to `versions-root/kotlin-version-lookup.json`
// and its usage in `gradle-conventions-settings/src/main/kotlin/settings-conventions.settings.gradle.kts`
val kotlinGPVersion = getKotlinPluginVersion().kotlinVersionParsed()
if (kotlinVersion != kotlinGPVersion) {
error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion")
}
Expand Down
22 changes: 1 addition & 21 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,10 @@
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import util.configureMetaTasks

val kotlinVersion: String by extra
val kotlinVersion: KotlinVersion by extra
val rpcVersion: String = libs.versions.kotlinx.rpc.get()

allprojects {
group = "org.jetbrains.kotlinx"
version = "$kotlinVersion-$rpcVersion"
}

plugins {
alias(libs.plugins.conventions.jvm)
alias(libs.plugins.compiler.specific.module)
}

subprojects {
afterEvaluate {
configure<KotlinProjectExtension> {
explicitApi = ExplicitApiMode.Disabled
}
}
}

configureMetaTasks("cleanTest", "test")
configureMetaTasks(tasks.matching { it.name.startsWith("publish") }.map { it.name })

This file was deleted.

11 changes: 0 additions & 11 deletions compiler-plugin/compiler-plugin-1_7_2/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions compiler-plugin/compiler-plugin-1_8/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions compiler-plugin/compiler-plugin-1_9/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

23 changes: 23 additions & 0 deletions compiler-plugin/compiler-plugin-backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode

plugins {
alias(libs.plugins.conventions.jvm)
alias(libs.plugins.compiler.specific.module)
}

kotlin {
explicitApi = ExplicitApiMode.Disabled

sourceSets.all {
languageSettings.optIn("org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI")
}
}

dependencies {
compileOnly(libs.kotlin.compiler.embeddable)
implementation(projects.compilerPluginCommon)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen

import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.builders.declarations.IrFieldBuilder
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.platform.TargetPlatform

interface VersionSpecificApi {
fun isJs(platform: TargetPlatform?): Boolean

fun referenceClass(context: IrPluginContext, packageName: String, name: String): IrClassSymbol?

fun referenceFunctions(
context: IrPluginContext,
packageName: String,
name: String,
): Collection<IrSimpleFunctionSymbol>

fun IrValueParameter.copyToVS(
irFunction: IrFunction,
origin: IrDeclarationOrigin = this.origin,
): IrValueParameter

fun IrSimpleFunction.addExtensionReceiverVS(
type: IrType,
origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED,
): IrValueParameter

var IrFieldBuilder.isFinalVS: Boolean

var IrCall.originVS: IrStatementOrigin?

var IrConstructor.isPrimaryVS: Boolean

companion object {
lateinit var INSTANCE: VersionSpecificApi
}
}

@Suppress("unused")
fun undefinedAPI(): Nothing = error("This API is not defined in current Kotlin version")
Loading