Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API checks for Android builds #1058

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
swankjesse marked this conversation as resolved.
Show resolved Hide resolved

- uses: actions/upload-artifact@v3
with:
name: jvm-native-libraries
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ allprojects {
Visibility.PROTECTED
))
reportUndocumented.set(false)
jdkVersion.set(8)
jdkVersion.set(11)

perPackageOption {
matchingRegex.set("app\\.cash\\.zipline\\.internal\\..*")
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Expand Down
22 changes: 22 additions & 0 deletions samples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -20,3 +24,21 @@ allprojects {
google()
}
}

allprojects {
plugins.withId("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
jvmToolchain(11)
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
configure<KotlinJvmProjectExtension> {
jvmToolchain(11)
}
}
plugins.withId("org.jetbrains.kotlin.android") {
configure<KotlinAndroidProjectExtension> {
jvmToolchain(11)
}
}
}
12 changes: 12 additions & 0 deletions samples/trivia/trivia-shared/api/zipline-api.toml
Original file line number Diff line number Diff line change
@@ -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<app.cash.zipline.samples.trivia.TriviaGame>
"CpVBWiWi",
]
7 changes: 3 additions & 4 deletions samples/world-clock/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions samples/world-clock/presenters/api/zipline-api.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[app.cash.zipline.samples.worldclock.WorldClockHost]

functions = [
# fun close(): kotlin.Unit
"moYx+T3e",

# fun timeZones(): kotlin.collections.List<kotlin.String>
"GaZNl/pB",
]

[app.cash.zipline.samples.worldclock.WorldClockPresenter]

functions = [
# fun close(): kotlin.Unit
"moYx+T3e",

# fun models(kotlinx.coroutines.flow.Flow<app.cash.zipline.samples.worldclock.WorldClockEvent>): kotlinx.coroutines.flow.Flow<app.cash.zipline.samples.worldclock.WorldClockModel>
"GXtzhRC8",
]
7 changes: 7 additions & 0 deletions samples/world-clock/presenters/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions zipline-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ gradlePlugin {

tasks {
test {
// The test in 'src/test/projects/android' needs Java 17+.
javaLauncher.set(
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
)
systemProperty("ziplineVersion", project.version)
dependsOn(":zipline-bytecode:publishAllPublicationsToTestMavenRepository")
dependsOn(":zipline-gradle-plugin:publishAllPublicationsToTestMavenRepository")
dependsOn(":zipline-kotlin-plugin:publishAllPublicationsToTestMavenRepository")
dependsOn(":zipline-loader:publishJvmPublicationToTestMavenRepository")
dependsOn(":zipline-loader:publishKotlinMultiplatformPublicationToTestMavenRepository")
dependsOn(":zipline:publishAndroidReleasePublicationToTestMavenRepository")
dependsOn(":zipline:publishJsPublicationToTestMavenRepository")
dependsOn(":zipline:publishJvmPublicationToTestMavenRepository")
dependsOn(":zipline:publishKotlinMultiplatformPublicationToTestMavenRepository")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get at the main compilation task through

kotlinExtension.targets.all { target -> .. }

but that can be a follow-up. At the very least it reduces the risk of name-based task logic. Someone could, in theory, have "Test" in their target name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lemme do

registerZiplineApiTask(target, kotlinCompile, Mode.Check, ziplineApiCheck)
registerZiplineApiTask(target, kotlinCompile, Mode.Dump, ziplineApiDump)
}
}

Expand Down Expand Up @@ -117,18 +123,17 @@ class ZiplinePlugin : KotlinCompilerPluginSupportPlugin {
private fun registerZiplineApiTask(
project: Project,
compileTask: KotlinCompileTool,
mode: ZiplineApiValidationTask.Mode,
mode: Mode,
rollupTask: TaskProvider<Task>,
) {
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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ class ZiplinePluginTest {
}
}

/** Confirm ziplineApiDump tasks are available on non-JVM projects. */
@Test
fun ziplineApiDumpOnAndroidProject() {
val projectDir = File("src/test/projects/android")
val ziplineApiToml = projectDir.resolve("lib/api/zipline-api.toml")
ziplineApiToml.delete() // In case a previous execution crashed.

try {
val taskName = ":lib:ziplineApiDump"
createRunner(projectDir, "clean", taskName).build()
assertThat(ziplineApiToml.exists()).isTrue()
} finally {
ziplineApiToml.delete()
}
}

private fun createRunner(projectDir: File, vararg taskNames: String): GradleRunner {
val gradleRoot = projectDir.resolve("gradle").also { it.mkdir() }
File("../gradle/wrapper").copyRecursively(gradleRoot.resolve("wrapper"), true)
Expand Down
24 changes: 24 additions & 0 deletions zipline-gradle-plugin/src/test/projects/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
buildscript {
repositories {
maven {
url = file("$rootDir/../../../../../build/testMaven").toURI()
}
mavenCentral()
google()
}
dependencies {
classpath("app.cash.zipline:zipline-gradle-plugin:${project.property("ziplineVersion")}")
classpath(libs.android.gradle.plugin)
classpath(libs.kotlin.gradle.plugin)
}
}

allprojects {
repositories {
maven {
url = file("$rootDir/../../../../../build/testMaven").toURI()
}
mavenCentral()
google()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kotlin.js.compiler=ir
android.useAndroidX=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
kotlin("multiplatform")
id("com.android.library")
id("app.cash.zipline")
}

kotlin {
android()
js {
browser()
binaries.executable()
}

sourceSets {
commonMain {
dependencies {
implementation("app.cash.zipline:zipline:${project.property("ziplineVersion")}")
}
}
}
}

android {
namespace = "app.cash.zipline.tests.android"
compileSdk = libs.versions.compileSdk.get().toInt()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2023 Cash App
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package app.cash.zipline.tests

import app.cash.zipline.ZiplineService

interface GreetService : ZiplineService {
fun greet(name: String): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../../../../gradle/libs.versions.toml"))
}
}
}

include(":lib")
Loading