From 54313f65e90dbf2545b0bf6997c4eb1c9c216b3f Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 23 Jun 2023 11:30:26 -0400 Subject: [PATCH] Fix API checks for Android builds --- .github/workflows/build.yaml | 9 +++++-- build.gradle.kts | 2 +- gradle/libs.versions.toml | 4 +-- samples/build.gradle.kts | 22 ++++++++++++++++ .../trivia/trivia-shared/api/zipline-api.toml | 12 +++++++++ samples/world-clock/android/build.gradle.kts | 7 +++--- .../presenters/api/zipline-api.toml | 19 ++++++++++++++ .../world-clock/presenters/build.gradle.kts | 7 ++++++ .../app/cash/zipline/gradle/ZiplinePlugin.kt | 25 +++++++++++-------- 9 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 samples/trivia/trivia-shared/api/zipline-api.toml create mode 100644 samples/world-clock/presenters/api/zipline-api.toml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8a69c7dc52..3318698b3e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -57,10 +57,15 @@ jobs: if: matrix.os == 'ubuntu-latest' run: sudo apt-get install -y libtinfo5 - # Build unless this is a cross-compile. - - run: ./gradlew build --stacktrace + # Build unless this is a cross-compile (we can't test cross-compiled code) + - name: Build Zipline + run: ./gradlew build --stacktrace if: matrix.arch == 'amd64' || matrix.arch == 'x86_64' + - name: Build samples + run: ../gradlew check --stacktrace + working-directory: ./samples + - uses: actions/upload-artifact@v3 with: name: jvm-native-libraries diff --git a/build.gradle.kts b/build.gradle.kts index 1a914bf085..1d84cca778 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -112,7 +112,7 @@ allprojects { Visibility.PROTECTED )) reportUndocumented.set(false) - jdkVersion.set(8) + jdkVersion.set(11) perPackageOption { matchingRegex.set("app\\.cash\\.zipline\\.internal\\..*") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cde3c052f2..8a07c93cfa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] androidx-compose = "1.4.3" -androidx-compose-compiler = "1.4.7" +androidx-compose-compiler = "1.4.5" auto-service="1.1.1" compileSdk = "33" http4k = "4.48.0.0" @@ -22,7 +22,7 @@ androidx-annotation = { module = "androidx.annotation:annotation", version = "1. androidx-appCompat = { module = "androidx.appcompat:appcompat", version = "1.6.1" } # This isn't strictly used, but allows Renovate to see us using the Compose Compiler artifact androidx-compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "androidx-compose-compiler" } -androidx-compose-material = { module = "androidx.compose.material:material", version = "androidx-compose" } +androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose" } androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose" } androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" } androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose" } diff --git a/samples/build.gradle.kts b/samples/build.gradle.kts index bf57828083..0c00a8f10b 100644 --- a/samples/build.gradle.kts +++ b/samples/build.gradle.kts @@ -1,3 +1,7 @@ +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + buildscript { dependencies { classpath(libs.android.gradle.plugin) @@ -20,3 +24,21 @@ allprojects { google() } } + +allprojects { + plugins.withId("org.jetbrains.kotlin.multiplatform") { + configure { + jvmToolchain(11) + } + } + plugins.withId("org.jetbrains.kotlin.jvm") { + configure { + jvmToolchain(11) + } + } + plugins.withId("org.jetbrains.kotlin.android") { + configure { + jvmToolchain(11) + } + } +} diff --git a/samples/trivia/trivia-shared/api/zipline-api.toml b/samples/trivia/trivia-shared/api/zipline-api.toml new file mode 100644 index 0000000000..30a8bb5e9c --- /dev/null +++ b/samples/trivia/trivia-shared/api/zipline-api.toml @@ -0,0 +1,12 @@ +[app.cash.zipline.samples.trivia.TriviaService] + +functions = [ + # fun answer(kotlin.Int, kotlin.Int, kotlin.String): app.cash.zipline.samples.trivia.AnswerResult + "zqfiWcT7", + + # fun close(): kotlin.Unit + "moYx+T3e", + + # fun games(): kotlin.collections.List + "CpVBWiWi", +] diff --git a/samples/world-clock/android/build.gradle.kts b/samples/world-clock/android/build.gradle.kts index 962116692f..413029bddc 100644 --- a/samples/world-clock/android/build.gradle.kts +++ b/samples/world-clock/android/build.gradle.kts @@ -11,14 +11,13 @@ android { defaultConfig { applicationId = "com.example.zipline.worldclock" - minSdk = 21 - targetSdk = 33 + minSdk = libs.versions.compileSdk.get().toInt() } compileOptions { isCoreLibraryDesugaringEnabled = true - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } buildFeatures { diff --git a/samples/world-clock/presenters/api/zipline-api.toml b/samples/world-clock/presenters/api/zipline-api.toml new file mode 100644 index 0000000000..a442fa16d2 --- /dev/null +++ b/samples/world-clock/presenters/api/zipline-api.toml @@ -0,0 +1,19 @@ +[app.cash.zipline.samples.worldclock.WorldClockHost] + +functions = [ + # fun close(): kotlin.Unit + "moYx+T3e", + + # fun timeZones(): kotlin.collections.List + "GaZNl/pB", +] + +[app.cash.zipline.samples.worldclock.WorldClockPresenter] + +functions = [ + # fun close(): kotlin.Unit + "moYx+T3e", + + # fun models(kotlinx.coroutines.flow.Flow): kotlinx.coroutines.flow.Flow + "GXtzhRC8", +] diff --git a/samples/world-clock/presenters/build.gradle.kts b/samples/world-clock/presenters/build.gradle.kts index 0129c24957..5a69cad75b 100644 --- a/samples/world-clock/presenters/build.gradle.kts +++ b/samples/world-clock/presenters/build.gradle.kts @@ -52,6 +52,13 @@ kotlin { android { compileSdk = libs.versions.compileSdk.get().toInt() namespace = "app.cash.zipline.samples.worldclock.presenters" + defaultConfig { + minSdk = libs.versions.minSdk.get().toInt() + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } } zipline { diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt index 98952b8406..1e86671fb2 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt @@ -15,8 +15,10 @@ */ package app.cash.zipline.gradle +import app.cash.zipline.gradle.ZiplineApiValidationTask.Mode import app.cash.zipline.loader.SignatureAlgorithmId import org.gradle.api.Project +import org.gradle.api.Task import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -77,11 +79,15 @@ class ZiplinePlugin : KotlinCompilerPluginSupportPlugin { } } + val ziplineApiCheck = target.tasks.register("ziplineApiCheck") + target.tasks.named("check").configure { checkTask -> + checkTask.dependsOn(ziplineApiCheck) + } + val ziplineApiDump = target.tasks.register("ziplineApiDump") target.tasks.withType(KotlinCompile::class.java) { kotlinCompile -> - if (kotlinCompile.name == "compileKotlinJvm") { - registerZiplineApiTask(target, kotlinCompile, ZiplineApiValidationTask.Mode.Check) - registerZiplineApiTask(target, kotlinCompile, ZiplineApiValidationTask.Mode.Dump) - } + if ("Test" in kotlinCompile.name) return@withType + registerZiplineApiTask(target, kotlinCompile, Mode.Check, ziplineApiCheck) + registerZiplineApiTask(target, kotlinCompile, Mode.Dump, ziplineApiDump) } } @@ -117,18 +123,17 @@ class ZiplinePlugin : KotlinCompilerPluginSupportPlugin { private fun registerZiplineApiTask( project: Project, compileTask: KotlinCompileTool, - mode: ZiplineApiValidationTask.Mode, + mode: Mode, + rollupTask: TaskProvider, ) { val task = project.tasks.register( - "ziplineApi$mode", + "${compileTask.name}ZiplineApi$mode", // Like 'compileKotlinJvmZiplineApiCheck' ZiplineApiValidationTask::class.java, mode, ) - if (mode == ZiplineApiValidationTask.Mode.Check) { - project.tasks.named("check").configure { checkTask -> - checkTask.dependsOn(task) - } + rollupTask.configure { + it.dependsOn(task) } task.configure { task ->