From d6e361e6f8b2f6bd1bef9a98b23affe54260d6e9 Mon Sep 17 00:00:00 2001 From: Tadeas Kriz Date: Mon, 30 Oct 2023 21:20:25 -0400 Subject: [PATCH] Add support for using Kotlin Native Compiler Embeddable artifact from Konan home. --- .../skie/buildsetup/plugins/DevAcceptanceTests.kt | 14 +++++++------- .../plugins/DevAcceptanceTestsFramework.kt | 3 ++- .../skie/buildsetup/plugins/SkieCompiler.kt | 3 ++- .../skie/gradle/util/KotlinNativeCompilerHome.kt | 15 +++++++++++++++ common-gradle/gradle.properties | 5 ++++- 5 files changed, 30 insertions(+), 10 deletions(-) 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 185a3c7c7..39d6f58eb 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 @@ -1,8 +1,11 @@ package co.touchlab.skie.buildsetup.plugins import co.touchlab.skie.gradle.KotlinCompilerVersion +import co.touchlab.skie.gradle.KotlinToolingVersion import co.touchlab.skie.gradle.architecture.MacOsCpuArchitecture import co.touchlab.skie.gradle.util.enquoted +import co.touchlab.skie.gradle.util.kotlinNativeCompilerEmbeddableDependency +import co.touchlab.skie.gradle.util.kotlinNativeCompilerHome import co.touchlab.skie.gradle.version.AcceptanceTestsComponent import co.touchlab.skie.gradle.version.KotlinToolingVersionComponent import co.touchlab.skie.gradle.version.acceptanceTest @@ -18,16 +21,12 @@ import com.github.gmazzo.gradle.plugins.BuildConfigExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.Dependency import org.gradle.api.attributes.Attribute import org.gradle.api.attributes.Usage import org.gradle.api.file.Directory import org.gradle.api.provider.Provider -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.exclude -import org.gradle.kotlin.dsl.named -import org.gradle.kotlin.dsl.project +import org.gradle.kotlin.dsl.* import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.language.jvm.tasks.ProcessResources import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType @@ -132,7 +131,8 @@ abstract class DevAcceptanceTests : Plugin { dependencies { weak("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") - weak("org.jetbrains.kotlin:kotlin-native-compiler-embeddable:$kotlinVersion") + + weak(kotlinNativeCompilerEmbeddableDependency(kotlinVersion)) testOnly("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTestsFramework.kt b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTestsFramework.kt index 1f821fad2..84293bd86 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTestsFramework.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/DevAcceptanceTestsFramework.kt @@ -1,6 +1,7 @@ package co.touchlab.skie.buildsetup.plugins import co.touchlab.skie.gradle.KotlinCompilerVersion +import co.touchlab.skie.gradle.util.kotlinNativeCompilerEmbeddableDependency import co.touchlab.skie.gradle.util.kotlinNativeCompilerHome import co.touchlab.skie.gradle.util.libs import co.touchlab.skie.gradle.version.ToolingVersions @@ -96,7 +97,7 @@ abstract class DevAcceptanceTestsFramework : Plugin { dependencies { weak("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}") - weak("org.jetbrains.kotlin:kotlin-native-compiler-embeddable:${kotlinVersion}") + weak(kotlinNativeCompilerEmbeddableDependency(kotlinVersion)) testOnly(libs.bundles.testing.jvm) } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieCompiler.kt b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieCompiler.kt index cabf4cef7..918a37705 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieCompiler.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/plugins/SkieCompiler.kt @@ -1,6 +1,7 @@ package co.touchlab.skie.buildsetup.plugins import co.touchlab.skie.gradle.KotlinCompilerVersion +import co.touchlab.skie.gradle.util.kotlinNativeCompilerEmbeddableDependency import co.touchlab.skie.gradle.version.kotlinToolingVersion import co.touchlab.skie.gradle.version.kotlinToolingVersionDimension import co.touchlab.skie.gradle.version.target.MultiDimensionTargetExtension @@ -32,7 +33,7 @@ abstract class SkieCompiler : Plugin { dependencies { weak("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") - weak("org.jetbrains.kotlin:kotlin-native-compiler-embeddable:$kotlinVersion") + weak(kotlinNativeCompilerEmbeddableDependency(kotlinVersion)) } } } diff --git a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/util/KotlinNativeCompilerHome.kt b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/util/KotlinNativeCompilerHome.kt index a4ff2cdd9..00a255b26 100644 --- a/build-setup/src/main/kotlin/co/touchlab/skie/gradle/util/KotlinNativeCompilerHome.kt +++ b/build-setup/src/main/kotlin/co/touchlab/skie/gradle/util/KotlinNativeCompilerHome.kt @@ -2,7 +2,9 @@ package co.touchlab.skie.gradle.util import co.touchlab.skie.gradle.KotlinToolingVersion import org.gradle.api.Project +import org.gradle.api.artifacts.Dependency import org.gradle.kotlin.dsl.extra +import org.gradle.kotlin.dsl.provideDelegate import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader import org.jetbrains.kotlin.konan.CompilerVersion import java.io.File @@ -30,6 +32,19 @@ fun Project.kotlinNativeCompilerHome(kotlinVersion: KotlinToolingVersion): File .compilerDirectory } +internal fun Project.kotlinNativeCompilerEmbeddableDependency(kotlinVersion: KotlinToolingVersion): Dependency { + val kotlinNativeCompilerEmbeddableFromHome: String? by project + return if (kotlinNativeCompilerEmbeddableFromHome.toBoolean()) { + project.dependencies.create( + files( + kotlinNativeCompilerHome(kotlinVersion).resolve("konan/lib/kotlin-native-compiler-embeddable.jar") + ) + ) + } else { + project.dependencies.create("org.jetbrains.kotlin:kotlin-native-compiler-embeddable:$kotlinVersion") + } +} + private fun Project.backupProperty(name: String): BackupProperty? { return if (properties.containsKey(name)) { BackupProperty(name, properties[name] as T) diff --git a/common-gradle/gradle.properties b/common-gradle/gradle.properties index d2b60c849..f0c874494 100644 --- a/common-gradle/gradle.properties +++ b/common-gradle/gradle.properties @@ -9,7 +9,10 @@ kotlin.mpp.import.enableKgpDependencyResolution=true pluginId=co.touchlab.skie # WIP remove RC -versionSupport.kotlinTooling=1.8.0(1.8.10), 1.8.20(1.8.21, 1.8.22), 1.9.0(1.9.10), 1.9.20[1.9.20-RC2] +versionSupport.kotlinTooling=1.8.0(1.8.10), 1.8.20(1.8.21, 1.8.22), 1.9.0(1.9.10), 1.9.20[1.9.20] versionSupport.gradleApi=7.3, 8.0, 8.1 touchlab.key=ABCDEFGHIJKLMNOPQRSTUVWXYZ + + +kotlinNativeCompilerEmbeddableFromHome=true