@ -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} "
@ -93,20 +77,3 @@ private fun KotlinNativeTarget.disableKotlinNativeCache() {
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 ' " ) ,
)
}