Skip to content

Commit

Permalink
Restrict Kotlin 1.8.0 to Coroutines 1.6.4 and remove support for watc…
Browse files Browse the repository at this point in the history
…hosDeviceArm64 due to version conflict.
  • Loading branch information
FilipDolnik committed Mar 11, 2024
1 parent 92918a7 commit 201a9af
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 34 deletions.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
17 changes: 14 additions & 3 deletions SKIE/runtime/kotlin/runtime-kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ abstract class DevAcceptanceTests : Plugin<Project> {
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Project> {

Expand All @@ -20,26 +25,8 @@ abstract class SkieRuntimeKotlin : Plugin<Project> {
apply<MultiDimensionTargetPlugin>()

extensions.configure<MultiDimensionTargetExtension> {
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 ->
Expand All @@ -51,4 +38,31 @@ abstract class SkieRuntimeKotlin : Plugin<Project> {
}
}
}

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))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,)")"""
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,)")"""
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ class MultiDimensionTargetConfigurer(

fun configure(
dimensions: List<Target.Dimension<*>>,
filter: (Target) -> Boolean,
createTarget: KotlinMultiplatformExtension.(Target) -> KotlinTarget,
) {
dimensions
.fold(tupleSpaceOf<Target.ComponentInDimension<*>>(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<KotlinMultiplatformExtension>()
allTargets.forEach { target ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions common-gradle/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down

0 comments on commit 201a9af

Please sign in to comment.