From 201a9af0cb5f84767bc32b60adc60a68acbc6f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Doln=C3=ADk?= Date: Mon, 11 Mar 2024 12:36:30 +0100 Subject: [PATCH] Restrict Kotlin 1.8.0 to Coroutines 1.6.4 and remove support for watchosDeviceArm64 due to version conflict. --- SKIE/acceptance-tests | 2 +- SKIE/runtime/kotlin/runtime-kotlin.gradle.kts | 17 ++++-- .../buildsetup/plugins/DevAcceptanceTests.kt | 2 + .../buildsetup/plugins/SkieRuntimeKotlin.kt | 54 ++++++++++++------- .../skie/gradle/test/ExternalLibrariesTask.kt | 8 ++- .../gradle/test/PrepareTestClasspathsTask.kt | 8 ++- .../target/MultiDimensionTargetConfigurer.kt | 15 +++--- .../target/MultiDimensionTargetExtension.kt | 4 +- common-gradle/gradle/libs.versions.toml | 2 + 9 files changed, 78 insertions(+), 34 deletions(-) diff --git a/SKIE/acceptance-tests b/SKIE/acceptance-tests index a07b85e8f..79d538005 160000 --- a/SKIE/acceptance-tests +++ b/SKIE/acceptance-tests @@ -1 +1 @@ -Subproject commit a07b85e8fa3c9b549df4abe62726afca911fed1c +Subproject commit 79d5380054ad9a1ea597c7a1b1caf5bbff33a411 diff --git a/SKIE/runtime/kotlin/runtime-kotlin.gradle.kts b/SKIE/runtime/kotlin/runtime-kotlin.gradle.kts index 665b8e0d4..264698a21 100644 --- a/SKIE/runtime/kotlin/runtime-kotlin.gradle.kts +++ b/SKIE/runtime/kotlin/runtime-kotlin.gradle.kts @@ -10,9 +10,20 @@ skiePublishing { } kotlin { - sourceSets.commonMain { - dependencies { - implementation(libs.kotlinx.coroutines.core) + // Runtime requires Coroutines but watchosDeviceArm64 is only supported since Coroutines 1.7.0 which require Kotlin 1.8.20 + // For this reason we must use an older version of Coroutines for Kotlin 1.8.0 + // This solution is far from ideal due to current project setup limitations - refactor this code as part of the build logic rewrite + sourceSets.configureEach { + val nameSegments = name.split("kgp_") + if (nameSegments.size == 2) { + val kgpVersionSegment = nameSegments[1] + dependencies { + if (kgpVersionSegment.startsWith("1.8.0")) { + implementation(libs.kotlinx.coroutines.core.legacy) + } else { + implementation(libs.kotlinx.coroutines.core) + } + } } } } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTests.kt b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTests.kt index f98494fe3..1ff3ebecc 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTests.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTests.kt @@ -232,6 +232,8 @@ abstract class DevAcceptanceTests : Plugin { isCanBeResolved = true exclude("org.jetbrains.kotlin", "kotlin-stdlib") + exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7") + exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8") exclude("org.jetbrains.kotlin", "kotlin-stdlib-common") attributes { diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieRuntimeKotlin.kt b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieRuntimeKotlin.kt index 64e05de04..4ffcb4c4c 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieRuntimeKotlin.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieRuntimeKotlin.kt @@ -1,17 +1,22 @@ package co.touchlab.skie.buildsetup.plugins import co.touchlab.skie.gradle.KotlinCompilerVersion +import co.touchlab.skie.gradle.KotlinToolingVersion +import co.touchlab.skie.gradle.version.DarwinPlatformComponent import co.touchlab.skie.gradle.version.darwinPlatform import co.touchlab.skie.gradle.version.darwinPlatformDimension import co.touchlab.skie.gradle.version.kotlinToolingVersion import co.touchlab.skie.gradle.version.kotlinToolingVersionDimension import co.touchlab.skie.gradle.version.target.MultiDimensionTargetExtension import co.touchlab.skie.gradle.version.target.MultiDimensionTargetPlugin +import co.touchlab.skie.gradle.version.target.Target import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.named +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget abstract class SkieRuntimeKotlin : Plugin { @@ -20,26 +25,8 @@ abstract class SkieRuntimeKotlin : Plugin { apply() extensions.configure { - dimensions(darwinPlatformDimension(), kotlinToolingVersionDimension()) { target -> - val preset = presets.getByName(target.darwinPlatform.name) - targetFromPreset(preset, target.name) { - this.attributes { - attribute(KotlinCompilerVersion.attribute, objects.named(target.kotlinToolingVersion.value)) - } - - // These two configurations are created by Kotlin, but don't copy our attributes, so we need to do it manually - configurations.named(target.name + "CInteropApiElements").configure { - this.attributes { - attribute(KotlinCompilerVersion.attribute, objects.named(target.kotlinToolingVersion.value)) - } - } - - configurations.named(target.name + "MetadataElements").configure { - this.attributes { - attribute(KotlinCompilerVersion.attribute, objects.named(target.kotlinToolingVersion.value)) - } - } - } + dimensions(darwinPlatformDimension(), kotlinToolingVersionDimension(), filter = { it.isSupported }) { target -> + configureTarget(target) } configureSourceSet { sourceSet -> @@ -51,4 +38,31 @@ abstract class SkieRuntimeKotlin : Plugin { } } } + + private val Target.isSupported: Boolean + // Runtime requires Coroutines but watchosDeviceArm64 is only supported since Coroutines 1.7.0 which require Kotlin 1.8.20 + get() = !(darwinPlatform == DarwinPlatformComponent.watchosDeviceArm64 && kotlinToolingVersion.primaryVersion == KotlinToolingVersion("1.8.0")) + + private fun KotlinMultiplatformExtension.configureTarget(target: Target): KotlinTarget { + val preset = presets.getByName(target.darwinPlatform.name) + + return targetFromPreset(preset, target.name) { + this.attributes { + attribute(KotlinCompilerVersion.attribute, project.objects.named(target.kotlinToolingVersion.value)) + } + + // These two configurations are created by Kotlin, but don't copy our attributes, so we need to do it manually + project.configurations.named(target.name + "CInteropApiElements").configure { + this.attributes { + attribute(KotlinCompilerVersion.attribute, project.objects.named(target.kotlinToolingVersion.value)) + } + } + + project.configurations.named(target.name + "MetadataElements").configure { + this.attributes { + attribute(KotlinCompilerVersion.attribute, project.objects.named(target.kotlinToolingVersion.value)) + } + } + } + } } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/ExternalLibrariesTask.kt b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/ExternalLibrariesTask.kt index 2ccf40ec1..c2808aa5e 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/ExternalLibrariesTask.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/ExternalLibrariesTask.kt @@ -199,7 +199,13 @@ abstract class ExternalLibrariesTask : DefaultTask() { api(library) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") { version { - strictly("[1.6.4,)") + ${ + if (kotlinVersion.get() == "1.8.0") { + """"strictly("[1.6.4,)")""" + } else { + """"strictly("[1.7.0,)")""" + } + } } } } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/PrepareTestClasspathsTask.kt b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/PrepareTestClasspathsTask.kt index 48f9b5ca8..f88a0e86e 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/PrepareTestClasspathsTask.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/test/PrepareTestClasspathsTask.kt @@ -100,7 +100,13 @@ abstract class PrepareTestClasspathsTask : DefaultTask() { } implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") { version { - strictly("[1.6.4,)") + ${ + if (kotlinVersion.get() == "1.8.0") { + """"strictly("[1.6.4,)")""" + } else { + """"strictly("[1.7.0,)")""" + } + } } } } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetConfigurer.kt b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetConfigurer.kt index 4c300a5d8..f2b986ad0 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetConfigurer.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetConfigurer.kt @@ -14,20 +14,23 @@ class MultiDimensionTargetConfigurer( fun configure( dimensions: List>, + filter: (Target) -> Boolean, createTarget: KotlinMultiplatformExtension.(Target) -> KotlinTarget, ) { dimensions .fold(tupleSpaceOf>(tupleOf())) { acc, dimension -> acc * dimension.componentsWithDimension } - .forEach { tuple -> - allTargets.add( - Target( - tuple.joinToString("__") { it.componentName }, - tuple.map { it.component }, - ), + .map { tuple -> + Target( + tuple.joinToString("__") { it.componentName }, + tuple.map { it.component }, ) } + .filter { filter(it) } + .forEach { + allTargets.add(it) + } val kotlin = project.extensions.getByType() allTargets.forEach { target -> diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetExtension.kt b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetExtension.kt index 048554d4d..c6373cc64 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetExtension.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/version/target/MultiDimensionTargetExtension.kt @@ -20,11 +20,11 @@ abstract class MultiDimensionTargetExtension @Inject constructor( sourceSetConfigureActions.convention(emptyList()) } - fun dimensions(vararg dimensions: Target.Dimension<*>, createTarget: KotlinMultiplatformExtension.(Target) -> KotlinTarget) { + fun dimensions(vararg dimensions: Target.Dimension<*>, filter: (Target) -> Boolean = { true }, createTarget: KotlinMultiplatformExtension.(Target) -> KotlinTarget) { val dimensionList = dimensions.toList() this.dimensions.set(dimensionList) this.dimensions.disallowChanges() - targetConfigurer.configure(dimensionList, createTarget) + targetConfigurer.configure(dimensionList, filter, createTarget) } fun configureSourceSet(block: ConfigureSourceSetScope.(SourceSet) -> Unit) { diff --git a/common-gradle/gradle/libs.versions.toml b/common-gradle/gradle/libs.versions.toml index cf2abbd20..a756a75c0 100644 --- a/common-gradle/gradle/libs.versions.toml +++ b/common-gradle/gradle/libs.versions.toml @@ -8,6 +8,7 @@ ktor = "2.2.3" nexusPublish = "2.0.0-rc-1" gradleDoctor = "0.8.1" coroutines = "1.7.0" +coroutines-legacy = "1.6.4" [plugins] kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } @@ -31,6 +32,7 @@ kotlin-native-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-nati kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.4.0" } kotlinx-serialization-yaml = { module = "com.charleskorn.kaml:kaml", version = "0.53.0" } kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } +kotlinx-coroutines-core-legacy = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines-legacy" } kotlinx-coroutines-jvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "coroutines" } jackson-databind = { module = " com.fasterxml.jackson.core:jackson-databind", version = "2.14.2" } kotlinPoet = { module = "com.squareup:kotlinpoet", version = "1.12.0" }