Skip to content

Commit 29ab0e0

Browse files
XilinJiaLouisCAD
authored andcommitted
preliminary Kotlin 2.2.0 build
(cherry picked from commit 0b1d4f2d6c55d9a848cce4488c414088e36aa538)
1 parent de7e602 commit 29ab0e0

File tree

14 files changed

+235
-186
lines changed

14 files changed

+235
-186
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
@@ -144,9 +144,17 @@ kotlin {
144144
// ... and def file does not support using environment variables
145145
// https://github.com/JetBrains/kotlin-native/issues/3631
146146
// so resolving paths through gradle
147-
kotlinOptions.freeCompilerArgs += when (buildType) {
148-
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorX86Debug
149-
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorX86Release
147+
// kotlinOptions.freeCompilerArgs += when (buildType) {
148+
// BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorX86Debug
149+
// BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorX86Release
150+
// }
151+
compilerOptions.configure {
152+
freeCompilerArgs.addAll(
153+
when (buildType) {
154+
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorX86Debug
155+
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorX86Release
156+
}
157+
)
150158
}
151159
}
152160
}
@@ -157,9 +165,17 @@ kotlin {
157165
packageName = "realm_wrapper"
158166
includeDirs("$absoluteCorePath/src/")
159167
}
160-
kotlinOptions.freeCompilerArgs += when (buildType) {
161-
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorArm64Debug
162-
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorArm64Release
168+
// kotlinOptions.freeCompilerArgs += when (buildType) {
169+
// BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorArm64Debug
170+
// BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorArm64Release
171+
// }
172+
compilerOptions.configure {
173+
freeCompilerArgs.addAll(
174+
when (buildType) {
175+
BuildType.DEBUG -> nativeLibraryIncludesIosSimulatorArm64Debug
176+
BuildType.RELEASE -> nativeLibraryIncludesIosSimulatorArm64Release
177+
}
178+
)
163179
}
164180
}
165181
}
@@ -177,9 +193,17 @@ kotlin {
177193
// ... and def file does not support using environment variables
178194
// https://github.com/JetBrains/kotlin-native/issues/3631
179195
// so resolving paths through gradle
180-
kotlinOptions.freeCompilerArgs += when (buildType) {
181-
BuildType.DEBUG -> nativeLibraryIncludesIosArm64Debug
182-
BuildType.RELEASE -> nativeLibraryIncludesIosArm64Release
196+
// kotlinOptions.freeCompilerArgs += when (buildType) {
197+
// BuildType.DEBUG -> nativeLibraryIncludesIosArm64Debug
198+
// BuildType.RELEASE -> nativeLibraryIncludesIosArm64Release
199+
// }
200+
compilerOptions.configure {
201+
freeCompilerArgs.addAll(
202+
when (buildType) {
203+
BuildType.DEBUG -> nativeLibraryIncludesIosArm64Debug
204+
BuildType.RELEASE -> nativeLibraryIncludesIosArm64Release
205+
}
206+
)
183207
}
184208
}
185209
}
@@ -197,9 +221,17 @@ kotlin {
197221
// ... and def file does not support using environment variables
198222
// https://github.com/JetBrains/kotlin-native/issues/3631
199223
// so resolving paths through gradle
200-
kotlinOptions.freeCompilerArgs += when(buildType) {
201-
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
202-
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
224+
// kotlinOptions.freeCompilerArgs += when(buildType) {
225+
// BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
226+
// BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
227+
// }
228+
compilerOptions.configure {
229+
freeCompilerArgs.addAll(
230+
when (buildType) {
231+
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
232+
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
233+
}
234+
)
203235
}
204236
}
205237
}
@@ -210,9 +242,17 @@ kotlin {
210242
packageName = "realm_wrapper"
211243
includeDirs("$absoluteCorePath/src/")
212244
}
213-
kotlinOptions.freeCompilerArgs += when(buildType) {
214-
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
215-
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
245+
// kotlinOptions.freeCompilerArgs += when(buildType) {
246+
// BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
247+
// BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
248+
// }
249+
compilerOptions.configure {
250+
freeCompilerArgs.addAll(
251+
when (buildType) {
252+
BuildType.DEBUG -> nativeLibraryIncludesMacosUniversalDebug
253+
BuildType.RELEASE -> nativeLibraryIncludesMacosUniversalRelease
254+
}
255+
)
216256
}
217257
}
218258
}
@@ -838,7 +878,10 @@ val generateSdkVersionConstant: Task = tasks.create("generateSdkVersionConstant"
838878
)
839879
}
840880
}
841-
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
881+
//tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
882+
// dependsOn(generateSdkVersionConstant)
883+
//}
884+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<*>>().configureEach {
842885
dependsOn(generateSdkVersionConstant)
843886
}
844887

packages/plugin-compiler/build.gradle.kts

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

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

5253
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)