Browse Source

Revert enabling caching for Kotlin 1.9.0 (#3511)

We tried to enable the compiler cache, when
Kotlin/Native 1.9.0 is used.
Prior to Kotlin 1.9.0, the caching could not
be used with Compose, because code generation would fail.
With Kotlin 1.9.0, code generation succeeds, but  generated debug symbols cause issues with dsymutil during xcode build.
For more details, see https://youtrack.jetbrains.com/issue/KT-61270

This change partially reverts https://github.com/JetBrains/compose-multiplatform/pull/3477 and https://github.com/JetBrains/compose-multiplatform/pull/3496

Now, we always set `kotlin.native.cacheKind=none` in
Compose Multiplatform Gradle plugin for all
versions of Kotlin until KT-61270 is fixed.
Also, explicit cache kind error becomes a warning again.
pull/3519/head
Alexey Tsvetkov 1 year ago committed by GitHub
parent
commit
8b6b4ae3e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt
  2. 13
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

51
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/internal/configureNativeCompilerCaching.kt

@ -11,7 +11,6 @@ import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.internal.mppExt import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.utils.KGPPropertyProvider import org.jetbrains.compose.internal.utils.KGPPropertyProvider
import org.jetbrains.compose.internal.utils.configureEachWithType import org.jetbrains.compose.internal.utils.configureEachWithType
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.konan.target.presetName import org.jetbrains.kotlin.konan.target.presetName
@ -23,10 +22,9 @@ internal fun Project.configureNativeCompilerCaching() {
if (findProperty(COMPOSE_NATIVE_MANAGE_CACHE_KIND) == "false") return if (findProperty(COMPOSE_NATIVE_MANAGE_CACHE_KIND) == "false") return
plugins.withId(KOTLIN_MPP_PLUGIN_ID) { plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
val kotlinVersion = kotlinVersionNumbers(this)
mppExt.targets.configureEachWithType<KotlinNativeTarget> { mppExt.targets.configureEachWithType<KotlinNativeTarget> {
checkCacheKindUserValueIsNotNone() checkCacheKindUserValueIsNotNone()
configureTargetCompilerCache(kotlinVersion) disableKotlinNativeCache()
} }
} }
} }
@ -46,7 +44,9 @@ private fun KotlinNativeTarget.checkCacheKindUserValueIsNotNone() {
val value = provider.valueOrNull(cacheKindProperty) val value = provider.valueOrNull(cacheKindProperty)
if (value != null) { if (value != null) {
if (value.equals(NONE_VALUE, ignoreCase = true)) { if (value.equals(NONE_VALUE, ignoreCase = true)) {
error(cacheKindPropertyWarningMessage(cacheKindProperty, provider)) ComposeMultiplatformBuildService
.getInstance(project)
.warnOnceAfterBuild(cacheKindPropertyWarningMessage(cacheKindProperty, provider))
} }
return return
} }
@ -58,30 +58,14 @@ private fun cacheKindPropertyWarningMessage(
cacheKindProperty: String, cacheKindProperty: String,
provider: KGPPropertyProvider provider: KGPPropertyProvider
) = """ ) = """
|'$cacheKindProperty' is explicitly set to `none`. |Warning: '$cacheKindProperty' is explicitly set to `none`.
|This option significantly slows the Kotlin/Native compiler. |Compose Multiplatform Gradle plugin can manage this property automatically
|Compose Multiplatform Gradle plugin can set this property automatically, |based on a Kotlin compiler version being used.
|when it is necessary. |In future versions of Compose Multiplatform this warning will become an error.
| * Recommended action: remove explicit '$cacheKindProperty=$NONE_VALUE' from ${provider.location}. | * Recommended action: remove explicit '$cacheKindProperty=$NONE_VALUE' from ${provider.location}.
| * Alternative action: if you are sure you need '$cacheKindProperty=$NONE_VALUE', disable | * Alternative action: disable cache kind management by adding '$COMPOSE_NATIVE_MANAGE_CACHE_KIND=false' to your 'gradle.properties'.
|this error by adding '$COMPOSE_NATIVE_MANAGE_CACHE_KIND=false' to your 'gradle.properties'.
""".trimMargin() """.trimMargin()
private fun KotlinNativeTarget.configureTargetCompilerCache(kotlinVersion: KotlinVersion) {
// See comments in https://youtrack.jetbrains.com/issue/KT-57329
when {
// Kotlin < 1.9.0 => disable cache
kotlinVersion < KotlinVersion(1, 9, 0) -> {
disableKotlinNativeCache()
}
// 1.9.0 <= Kotlin < 1.9.20 => add -Xlazy-ir-for-caches=disable
kotlinVersion < KotlinVersion(1, 9, 20) -> {
disableLazyIrForCaches()
}
// Kotlin >= 1.9.20 => do nothing
else -> {}
}
}
private val KotlinNativeTarget.targetCacheKindPropertyName: String private val KotlinNativeTarget.targetCacheKindPropertyName: String
get() = "$PROJECT_CACHE_KIND_PROPERTY_NAME.${konanTarget.presetName}" get() = "$PROJECT_CACHE_KIND_PROPERTY_NAME.${konanTarget.presetName}"
@ -92,21 +76,4 @@ private fun KotlinNativeTarget.disableKotlinNativeCache() {
} else { } else {
project.extensions.extraProperties.set(targetCacheKindPropertyName, NONE_VALUE) project.extensions.extraProperties.set(targetCacheKindPropertyName, NONE_VALUE)
} }
}
private fun KotlinNativeTarget.disableLazyIrForCaches() {
compilations.configureEach { compilation ->
compilation.kotlinOptions.freeCompilerArgs += listOf("-Xlazy-ir-for-caches=disable")
}
}
private fun kotlinVersionNumbers(project: Project): KotlinVersion {
val version = project.getKotlinPluginVersion()
val m = Regex("(\\d+)\\.(\\d+)\\.(\\d+)").find(version) ?: error("Kotlin version has unexpected format: '$version'")
val (_, majorPart, minorPart, patchPart) = m.groupValues
return KotlinVersion(
major = majorPart.toIntOrNull() ?: error("Could not parse major part '$majorPart' of Kotlin plugin version: '$version'"),
minor = minorPart.toIntOrNull() ?: error("Could not parse minor part '$minorPart' of Kotlin plugin version: '$version'"),
patch = patchPart.toIntOrNull() ?: error("Could not parse patch part '$patchPart' of Kotlin plugin version: '$version'"),
)
} }

13
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

@ -128,8 +128,7 @@ class GradlePluginTest : GradlePluginTestBase() {
with(nativeCacheKindProject(kotlinVersion = TestKotlinVersions.v1_9_0) ) { with(nativeCacheKindProject(kotlinVersion = TestKotlinVersions.v1_9_0) ) {
gradle(task, "--info").checks { gradle(task, "--info").checks {
check.taskSuccessful(task) check.taskSuccessful(task)
check.logContains("-Xauto-cache-from=") check.logDoesntContain("-Xauto-cache-from=")
check.logContains("-Xlazy-ir-for-caches=disable")
} }
} }
} }
@ -142,19 +141,19 @@ class GradlePluginTest : GradlePluginTestBase() {
defaultTestEnvironment.copy(kotlinVersion = kotlinVersion) defaultTestEnvironment.copy(kotlinVersion = kotlinVersion)
) )
val cacheKindError = "'kotlin.native.cacheKind' is explicitly set to `none`" val cacheKindWarning = "'kotlin.native.cacheKind' is explicitly set to `none`"
val args = arrayOf("build", "--dry-run", "-Pkotlin.native.cacheKind=none") val args = arrayOf("build", "--dry-run", "-Pkotlin.native.cacheKind=none")
with(nativeCacheKindWarningProject(kotlinVersion = TestKotlinVersions.v1_8_20)) { with(nativeCacheKindWarningProject(kotlinVersion = TestKotlinVersions.v1_8_20)) {
gradleFailure(*args).checks { gradle(*args).checks {
check.logContains(cacheKindError) check.logContains(cacheKindWarning)
} }
} }
testWorkDir.deleteRecursively() testWorkDir.deleteRecursively()
testWorkDir.mkdirs() testWorkDir.mkdirs()
with(nativeCacheKindWarningProject(kotlinVersion = TestKotlinVersions.v1_9_0) ) { with(nativeCacheKindWarningProject(kotlinVersion = TestKotlinVersions.v1_9_0) ) {
gradleFailure(*args).checks { gradle(*args).checks {
check.logContains(cacheKindError) check.logContains(cacheKindWarning)
} }
} }
} }

Loading…
Cancel
Save