From 62def45f27c5e0aa454547c44d40675b2f86e68f Mon Sep 17 00:00:00 2001 From: Rick Clephas Date: Fri, 19 Nov 2021 17:43:04 +0100 Subject: [PATCH 1/4] Add support for the embeddable Kotlin compiler --- buildSrc/src/main/kotlin/Dependencies.kt | 1 + .../.gitignore | 1 + .../build.gradle.kts | 51 +++++++++++++++++++ .../gradle/KmpNativeCoroutinesPlugin.kt | 2 +- sample/settings.gradle.kts | 2 +- settings.gradle.kts | 1 + 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 kmp-nativecoroutines-compiler-embeddable/.gitignore create mode 100644 kmp-nativecoroutines-compiler-embeddable/build.gradle.kts diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index b80b59fa..25d9f730 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -4,6 +4,7 @@ object Dependencies { private const val version = "1.6.0" const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version" const val compiler = "org.jetbrains.kotlin:kotlin-compiler:$version" + const val embeddableCompiler = "org.jetbrains.kotlin:kotlin-compiler-embeddable:$version" } object Kotlinx { diff --git a/kmp-nativecoroutines-compiler-embeddable/.gitignore b/kmp-nativecoroutines-compiler-embeddable/.gitignore new file mode 100644 index 00000000..aa8e45f1 --- /dev/null +++ b/kmp-nativecoroutines-compiler-embeddable/.gitignore @@ -0,0 +1 @@ +src/ \ No newline at end of file diff --git a/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts b/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts new file mode 100644 index 00000000..8adfc58b --- /dev/null +++ b/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + kotlin("jvm") + kotlin("kapt") + `kmp-nativecoroutines-publish` +} + +dependencies { + compileOnly(Dependencies.Kotlin.embeddableCompiler) + compileOnly(Dependencies.AutoService.annotations) + kapt(Dependencies.AutoService.processor) +} + +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all { + kotlinOptions { + jvmTarget = "11" + freeCompilerArgs = listOf("-Xjvm-default=all") + } +} + +val syncSources by tasks.registering(Sync::class) { + from(project(":kmp-nativecoroutines-compiler").sourceSets.main.get().allSource) + into("src/main/kotlin") + filter { + when (it) { + "import com.intellij.mock.MockProject" -> "import org.jetbrains.kotlin.com.intellij.mock.MockProject" + else -> it + } + } +} + +tasks.compileKotlin.configure { + dependsOn(syncSources) +} + +tasks.clean.configure { + delete("src") +} + +val sourcesJar by tasks.registering(Jar::class) { + archiveClassifier.set("sources") + from(sourceSets.main.get().allSource) +} + +publishing { + publications { + create("maven") { + from(components["kotlin"]) + artifact(sourcesJar) + } + } +} \ No newline at end of file diff --git a/kmp-nativecoroutines-gradle-plugin/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/gradle/KmpNativeCoroutinesPlugin.kt b/kmp-nativecoroutines-gradle-plugin/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/gradle/KmpNativeCoroutinesPlugin.kt index e5dc297e..d2444414 100644 --- a/kmp-nativecoroutines-gradle-plugin/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/gradle/KmpNativeCoroutinesPlugin.kt +++ b/kmp-nativecoroutines-gradle-plugin/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/gradle/KmpNativeCoroutinesPlugin.kt @@ -39,5 +39,5 @@ class KmpNativeCoroutinesPlugin: KotlinCompilerPluginSupportPlugin { SubpluginArtifact("com.rickclephas.kmp", "kmp-nativecoroutines-compiler", VERSION) override fun getPluginArtifact(): SubpluginArtifact = - throw UnsupportedOperationException("KMP-NativeCoroutines only supports Kotlin\\Native!") + SubpluginArtifact("com.rickclephas.kmp", "kmp-nativecoroutines-compiler-embeddable", VERSION) } \ No newline at end of file diff --git a/sample/settings.gradle.kts b/sample/settings.gradle.kts index 26dad161..3bc1adbb 100644 --- a/sample/settings.gradle.kts +++ b/sample/settings.gradle.kts @@ -11,7 +11,7 @@ include(":shared") includeBuild("..") { dependencySubstitution { - listOf("annotations", "compiler", "core", "gradle-plugin").forEach { + listOf("annotations", "compiler", "compiler-embeddable", "core", "gradle-plugin").forEach { substitute(module("com.rickclephas.kmp:kmp-nativecoroutines-$it")) .using(project(":kmp-nativecoroutines-$it")) } diff --git a/settings.gradle.kts b/settings.gradle.kts index deebfa25..bd7149a8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,4 +10,5 @@ rootProject.name = "kmp-nativecoroutines" include(":kmp-nativecoroutines-core") include(":kmp-nativecoroutines-annotations") include(":kmp-nativecoroutines-compiler") +include(":kmp-nativecoroutines-compiler-embeddable") include(":kmp-nativecoroutines-gradle-plugin") From 6745fa365b6c279c7c4b388032bd508433328c5d Mon Sep 17 00:00:00 2001 From: Rick Clephas Date: Fri, 19 Nov 2021 18:48:24 +0100 Subject: [PATCH 2/4] Update workflow to test embeddable compiler --- .github/workflows/run-integration-tests.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-integration-tests.yaml b/.github/workflows/run-integration-tests.yaml index efb0e895..b08730d1 100644 --- a/.github/workflows/run-integration-tests.yaml +++ b/.github/workflows/run-integration-tests.yaml @@ -23,7 +23,8 @@ jobs: xcode: [ 13.1 ] java: [ 11 ] platform: [ iOS, macOS, tvOS, watchOS ] - name: ${{ format('{0} ({1}, Xcode {2}, JDK {3})', matrix.platform, matrix.os, matrix.xcode, matrix.java) }} + embeddable-compiler: [ true, false ] + name: ${{ format('{0} (embeddable {1}) ({2}, Xcode {3}, JDK {4})', matrix.embeddable-compiler, matrix.platform, matrix.os, matrix.xcode, matrix.java) }} runs-on: ${{ matrix.os }} defaults: run: @@ -46,6 +47,10 @@ jobs: uses: ./.github/actions/cache-gradle - name: Cache Konan uses: ./.github/actions/cache-konan + - name: Set kotlin.native.useEmbeddableCompilerJar + env: + KOTLIN_NATIVE_EMBEDDABLE_COMPILER: ${{ matrix.embeddable-compiler }} + run: echo "kotlin.native.useEmbeddableCompilerJar=KOTLIN_NATIVE_EMBEDDABLE_COMPILER" >> gradle.properties - name: Install CocoaPods dependencies run: | ./gradlew :shared:generateDummyFramework From d6a2db829c308b821b9c8270634a97cc938fadf7 Mon Sep 17 00:00:00 2001 From: Rick Clephas Date: Fri, 19 Nov 2021 19:23:37 +0100 Subject: [PATCH 3/4] Fix job name --- .github/workflows/run-integration-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-integration-tests.yaml b/.github/workflows/run-integration-tests.yaml index b08730d1..37f2d87e 100644 --- a/.github/workflows/run-integration-tests.yaml +++ b/.github/workflows/run-integration-tests.yaml @@ -24,7 +24,7 @@ jobs: java: [ 11 ] platform: [ iOS, macOS, tvOS, watchOS ] embeddable-compiler: [ true, false ] - name: ${{ format('{0} (embeddable {1}) ({2}, Xcode {3}, JDK {4})', matrix.embeddable-compiler, matrix.platform, matrix.os, matrix.xcode, matrix.java) }} + name: ${{ format('{0} (embeddable {1}) ({2}, Xcode {3}, JDK {4})', matrix.platform, matrix.embeddable-compiler, matrix.os, matrix.xcode, matrix.java) }} runs-on: ${{ matrix.os }} defaults: run: From 6a4781a78bf6ea332c6b420262e460c94768656c Mon Sep 17 00:00:00 2001 From: Rick Clephas Date: Fri, 19 Nov 2021 19:59:38 +0100 Subject: [PATCH 4/4] Remove AutoService and kapt #12 --- .../build.gradle.kts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts b/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts index 8adfc58b..172f7924 100644 --- a/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts +++ b/kmp-nativecoroutines-compiler-embeddable/build.gradle.kts @@ -1,20 +1,10 @@ plugins { kotlin("jvm") - kotlin("kapt") `kmp-nativecoroutines-publish` } dependencies { compileOnly(Dependencies.Kotlin.embeddableCompiler) - compileOnly(Dependencies.AutoService.annotations) - kapt(Dependencies.AutoService.processor) -} - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all { - kotlinOptions { - jvmTarget = "11" - freeCompilerArgs = listOf("-Xjvm-default=all") - } } val syncSources by tasks.registering(Sync::class) { @@ -30,6 +20,10 @@ val syncSources by tasks.registering(Sync::class) { tasks.compileKotlin.configure { dependsOn(syncSources) + kotlinOptions { + jvmTarget = "11" + freeCompilerArgs = listOf("-Xjvm-default=all") + } } tasks.clean.configure {