Skip to content

Commit 67cbbea

Browse files
XilinJiaLouisCAD
authored andcommitted
preliminary Kotlin 2.2.0 build
(cherry picked from commit 0b1d4f2d6c55d9a848cce4488c414088e36aa538)
1 parent d71aa1a commit 67cbbea

File tree

13 files changed

+226
-175
lines changed

13 files changed

+226
-175
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.2.8
2+
3+
* updated Kotlin to 2.2.0
4+
* fixed build errors due to deprecations in Kotlin 2.2.0
5+
* gradle upped to 8.13
6+
* fixed syntax errors in build.gradle.kts in cinterop related to kotlinOptions for Mac ans iOS
7+
* fixed syntax errors in build.gradle.kts in cinterop related to KotlinCompile
8+
19
## 3.2.7
210

311
* avoided NullPointerException in SuspendableWriter

buildSrc/src/main/kotlin/Config.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ val HOST_OS: OperatingSystem = findHostOs()
6262

6363
object Realm {
6464
val ciBuild = (System.getenv("CI") != null)
65-
// const val version = "3.2.4-SNAPSHOT"
66-
const val version = "3.2.7"
65+
const val version = "3.2.8"
6766
const val group = "io.github.xilinjia.krdb"
6867
const val projectUrl = "https://realm.io"
6968
const val pluginPortalId = "io.github.xilinjia.krdb"
@@ -126,9 +125,9 @@ object Versions {
126125
const val junit = "4.13.2" // https://mvnrepository.com/artifact/junit/junit
127126
const val kbson = "0.4.0" // https://github.com/mongodb/kbson
128127
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
129-
const val kotlin = "2.1.20" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
128+
const val kotlin = "2.2.0" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
129+
const val latestKotlin = "2.2.0" // https://kotlinlang.org/docs/eap.html#build-details
130130
const val kotlinJvmTarget = "17" // Which JVM bytecode version is kotlin compiled to.
131-
const val latestKotlin = "2.1.20" // https://kotlinlang.org/docs/eap.html#build-details
132131
const val kotlinCompileTesting = "0.7.0" // https://github.com/zacsweers/kotlin-compile-testing
133132
const val ktlint = "1.5.0" // https://github.com/pinterest/ktlint
134133
const val ktor = "2.3.12" // https://github.com/ktorio/ktor

examples/min-android-sample/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ buildscript {
1616
}
1717
dependencies {
1818
classpath("com.android.tools.build:gradle:8.7.3")
19-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0")
19+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.0")
2020
classpath("io.github.xilinjia.krdb:gradle-plugin:${rootProject.extra["realmVersion"]}")
2121
}
2222
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

packages/cinterop/build.gradle.kts

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,17 @@ kotlin {
140140
// ... and def file does not support using environment variables
141141
// https://github.com/JetBrains/kotlin-native/issues/3631
142142
// so resolving paths through gradle
143-
kotlinOptions.freeCompilerArgs += when (buildType) {
144-
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorX86Debug
145-
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorX86Release
143+
// kotlinOptions.freeCompilerArgs += when (buildType) {
144+
// BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorX86Debug
145+
// BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorX86Release
146+
// }
147+
compilerOptions.configure {
148+
freeCompilerArgs.addAll(
149+
when (buildType) {
150+
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorX86Debug
151+
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorX86Release
152+
}
153+
)
146154
}
147155
}
148156
}
@@ -153,9 +161,17 @@ kotlin {
153161
packageName = "realm_wrapper"
154162
includeDirs("$absoluteCorePath/src/")
155163
}
156-
kotlinOptions.freeCompilerArgs += when (buildType) {
157-
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorArm64Debug
158-
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorArm64Release
164+
// kotlinOptions.freeCompilerArgs += when (buildType) {
165+
// BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorArm64Debug
166+
// BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorArm64Release
167+
// }
168+
compilerOptions.configure {
169+
freeCompilerArgs.addAll(
170+
when (buildType) {
171+
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorArm64Debug
172+
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorArm64Release
173+
}
174+
)
159175
}
160176
}
161177
}
@@ -173,9 +189,17 @@ kotlin {
173189
// ... and def file does not support using environment variables
174190
// https://github.com/JetBrains/kotlin-native/issues/3631
175191
// so resolving paths through gradle
176-
kotlinOptions.freeCompilerArgs += when (buildType) {
177-
BuildType.DEBUG -> nativeLibraryIncludesIosArm64Debug
178-
BuildType.RELEASE -> nativeLibraryIncludesIosArm64Release
192+
// kotlinOptions.freeCompilerArgs += when (buildType) {
193+
// BuildType.DEBUG -> nativeLibraryIncludesIosArm64Debug
194+
// BuildType.RELEASE -> nativeLibraryIncludesIosArm64Release
195+
// }
196+
compilerOptions.configure {
197+
freeCompilerArgs.addAll(
198+
when (buildType) {
199+
BuildType.DEBUG -> nativeLibraryIncludesIosArm64Debug
200+
BuildType.RELEASE -> nativeLibraryIncludesIosArm64Release
201+
}
202+
)
179203
}
180204
}
181205
}
@@ -193,9 +217,17 @@ kotlin {
193217
// ... and def file does not support using environment variables
194218
// https://github.com/JetBrains/kotlin-native/issues/3631
195219
// so resolving paths through gradle
196-
kotlinOptions.freeCompilerArgs += when(buildType) {
197-
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
198-
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
220+
// kotlinOptions.freeCompilerArgs += when(buildType) {
221+
// BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
222+
// BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
223+
// }
224+
compilerOptions.configure {
225+
freeCompilerArgs.addAll(
226+
when (buildType) {
227+
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
228+
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
229+
}
230+
)
199231
}
200232
}
201233
}
@@ -206,9 +238,17 @@ kotlin {
206238
packageName = "realm_wrapper"
207239
includeDirs("$absoluteCorePath/src/")
208240
}
209-
kotlinOptions.freeCompilerArgs += when(buildType) {
210-
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
211-
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
241+
// kotlinOptions.freeCompilerArgs += when(buildType) {
242+
// BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
243+
// BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
244+
// }
245+
compilerOptions.configure {
246+
freeCompilerArgs.addAll(
247+
when (buildType) {
248+
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
249+
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
250+
}
251+
)
212252
}
213253
}
214254
}
@@ -830,7 +870,10 @@ val generateSdkVersionConstant: Task = tasks.create("generateSdkVersionConstant"
830870
)
831871
}
832872
}
833-
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
873+
//tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
874+
// dependsOn(generateSdkVersionConstant)
875+
//}
876+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<*>>().configureEach {
834877
dependsOn(generateSdkVersionConstant)
835878
}
836879

packages/plugin-compiler/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies {
4646

4747
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
4848
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
49+
// compilerOptions.freeCompilerArgs.add("-Xjvm-default=all")
4950
}
5051

5152
realmPublish {

packages/plugin-compiler/src/main/kotlin/io/github/xilinjia/krdb/compiler/AccessorModifierIrGeneration.kt

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ import org.jetbrains.kotlin.types.StarProjectionImpl
117117
import org.jetbrains.kotlin.types.isNullable
118118
import org.jetbrains.kotlin.types.typeUtil.supertypes
119119
import kotlin.collections.set
120+
//import org.jetbrains.kotlin.ir.util.isNullable
121+
//import org.jetbrains.kotlin.ir.util.isSubtypeOfClass
120122

121123
/**
122124
* Modifies the IR tree to transform getter/setter to call the C-Interop layer to retrieve read the managed values from the Realm
@@ -822,23 +824,23 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
822824
).also {
823825
it.dispatchReceiver = irGetObject(realmObjectHelper.symbol)
824826
}.apply {
825-
if (typeArgumentsCount > 0) {
826-
putTypeArgument(0, type)
827+
if (typeArguments.isNotEmpty()) {
828+
typeArguments[0] = type
827829
}
828-
putValueArgument(0, irGet(objectReferenceType, tmp.symbol))
829-
putValueArgument(1, irString(property.persistedName))
830+
arguments[0] = irGet(objectReferenceType, tmp.symbol)
831+
arguments[1] = irString(property.persistedName)
830832
}
831833
val storageValue = fromRealmValue?.let {
832834
irCall(callee = it).apply {
833-
if (typeArgumentsCount > 0) {
834-
putTypeArgument(0, type)
835+
if (typeArguments.isNotEmpty()) {
836+
typeArguments[0] = type
835837
}
836-
putValueArgument(0, managedObjectGetValueCall)
838+
arguments[0] = managedObjectGetValueCall
837839
}
838840
} ?: managedObjectGetValueCall
839841
val publicValue = toPublic?.let {
840842
irCall(callee = toPublic).apply {
841-
putValueArgument(0, storageValue)
843+
arguments[0] = storageValue
842844
}
843845
} ?: storageValue
844846
+irIfNull(
@@ -892,28 +894,28 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
892894
)
893895
val storageValue: IrDeclarationReference = fromPublic?.let {
894896
irCall(callee = it).apply {
895-
putValueArgument(0, irGet(setter.valueParameters.first()))
897+
arguments[0] = irGet(parameters.first())
896898
}
897-
} ?: irGet(setter.valueParameters.first())
899+
} ?: irGet(parameters.first())
898900
val realmValue: IrDeclarationReference = toRealmValue?.let {
899901
irCall(callee = it).apply {
900-
if (typeArgumentsCount > 0) {
901-
putTypeArgument(0, type)
902+
if (typeArguments.isNotEmpty()) {
903+
typeArguments[0] = type
902904
}
903-
putValueArgument(0, storageValue)
905+
arguments[0] = storageValue
904906
}
905907
} ?: storageValue
906908
val cinteropCall = irCall(
907909
callee = setFunction,
908910
).also {
909911
it.dispatchReceiver = irGetObject(realmObjectHelper.symbol)
910912
}.apply {
911-
if (typeArgumentsCount > 0) {
912-
putTypeArgument(0, type)
913+
if (typeArguments.isNotEmpty()) {
914+
typeArguments[0] = type
913915
}
914-
putValueArgument(0, irGet(objectReferenceType, tmp.symbol))
915-
putValueArgument(1, irString(property.persistedName))
916-
putValueArgument(2, realmValue)
916+
arguments[0] = irGet(objectReferenceType, tmp.symbol)
917+
arguments[1] = irString(property.persistedName)
918+
arguments[2] = realmValue
917919
}
918920

919921
+irIfNull(
@@ -924,7 +926,7 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
924926
irSetField(
925927
irGet(receiver),
926928
backingField.symbol.owner,
927-
irGet(setter.valueParameters.first()),
929+
irGet(parameters.first()),
928930
),
929931
// Managed object, return realm value
930932
elsePart = cinteropCall
@@ -1071,24 +1073,28 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
10711073

10721074
// Otherwise just return the matching core type present in the declaration
10731075
val genericPropertyType: PropertyType? = getPropertyTypeFromKotlinType(collectionGenericType)
1074-
return if (genericPropertyType == null) {
1075-
logError(
1076-
"Unsupported type for ${collectionType.description}: '${collectionGenericType.getKotlinTypeFqNameCompat(true)
1077-
}'",
1078-
declaration.locationOf()
1079-
)
1080-
null
1081-
} else if (genericPropertyType == PropertyType.RLM_PROPERTY_TYPE_MIXED && !collectionGenericType.isNullable()) {
1082-
logError(
1083-
"Unsupported type for ${collectionType.description}: Only '${collectionType.description}<RealmAny?>' is supported.",
1084-
declaration.locationOf()
1085-
)
1086-
return null
1087-
} else {
1088-
CoreType(
1089-
propertyType = genericPropertyType,
1090-
nullable = collectionGenericType.isNullable()
1091-
)
1076+
return when (genericPropertyType) {
1077+
null -> {
1078+
logError(
1079+
"Unsupported type for ${collectionType.description}: '${collectionGenericType.getKotlinTypeFqNameCompat(true)
1080+
}'",
1081+
declaration.locationOf()
1082+
)
1083+
null
1084+
}
1085+
PropertyType.RLM_PROPERTY_TYPE_MIXED if !collectionGenericType.isNullable() -> {
1086+
logError(
1087+
"Unsupported type for ${collectionType.description}: Only '${collectionType.description}<RealmAny?>' is supported.",
1088+
declaration.locationOf()
1089+
)
1090+
return null
1091+
}
1092+
else -> {
1093+
CoreType(
1094+
propertyType = genericPropertyType,
1095+
nullable = collectionGenericType.isNullable()
1096+
)
1097+
}
10921098
}
10931099
}
10941100

0 commit comments

Comments
 (0)