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

Support KMP for the landscapist module #390

Merged
merged 10 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
lint:
name: Spotless check
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v4.1.1
Expand All @@ -23,7 +23,7 @@ jobs:

api_check:
name: API check
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v4.1.1
Expand All @@ -37,7 +37,7 @@ jobs:

build:
name: Build and Tests
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v4.1.1

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:

jobs:
deploy:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
publish:
name: Snapshot build and publish
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v4.1.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
publish:
name: Release build and publish
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v4.1.1
Expand Down
42 changes: 23 additions & 19 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
plugins {
`kotlin-dsl`
`kotlin-dsl`
}

group = "com.skydoves.landscapist.buildlogic"

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.spotless.gradlePlugin)
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.spotless.gradlePlugin)
}

gradlePlugin {
plugins {
register("androidApplicationCompose") {
id = "landscapist.application.compose"
implementationClass = "AndroidApplicationComposeConventionPlugin"
}
register("androidLibraryCompose") {
id = "landscapist.library.compose"
implementationClass = "AndroidLibraryComposeConventionPlugin"
}
register("spotless") {
id = "landscapist.spotless"
implementationClass = "SpotlessConventionPlugin"
}
plugins {
register("androidApplicationCompose") {
id = "landscapist.application.compose"
implementationClass = "AndroidApplicationComposeConventionPlugin"
}
register("androidLibraryCompose") {
id = "landscapist.library.compose"
implementationClass = "AndroidLibraryComposeConventionPlugin"
}
register("composeMultiplatformLibrary") {
id = "landscapist.library.compose.multiplatform"
implementationClass = "ComposeMultiplatformLibraryConventionPlugin"
}
register("spotless") {
id = "landscapist.spotless"
implementationClass = "SpotlessConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Designed and developed by 2020-2022 skydoves (Jaewoong Eum)
*
* 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.
*/

import com.android.build.gradle.LibraryExtension
import com.skydoves.landscapist.configureAndroidCompose
import com.skydoves.landscapist.configureComposeMultiplatform
import com.skydoves.landscapist.configureKotlinAndroid
import com.skydoves.landscapist.kotlinOptions
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class ComposeMultiplatformLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("com.android.library")
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
pluginManager.apply("org.jetbrains.compose")
pluginManager.apply("com.vanniktech.maven.publish")
pluginManager.apply("binary-compatibility-validator")
pluginManager.apply("androidx.baselineprofile")

extensions.configure<LibraryExtension> libraryExtension@{
extensions.configure<KotlinMultiplatformExtension> kmpExtension@{
configureComposeMultiplatform(this@libraryExtension, this@kmpExtension)
}
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
tasks.withType(JavaCompile::class.java).configureEach {
this.targetCompatibility = libs.findVersion("jvmTarget").get().toString()
this.sourceCompatibility = libs.findVersion("jvmTarget").get().toString()
}

dependencies {
add("baselineProfile", project(":benchmark-landscapist"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Designed and developed by 2020-2022 skydoves (Jaewoong Eum)
*
* 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.
*/

@file:Suppress("UnstableApiUsage")

package com.skydoves.landscapist

import com.android.build.api.dsl.CommonExtension
import java.io.File
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

/**
* Configure Compose-Multiplatform-specific options
*/
internal fun Project.configureComposeMultiplatform(
commonExtension: CommonExtension<*, *, *, *, *>,
kotlinMultiplatformExtension: KotlinMultiplatformExtension,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

kotlinMultiplatformExtension.apply {
androidTarget { publishLibraryVariants("release") }
jvm("desktop")
iosX64()
iosArm64()
iosSimulatorArm64()
macosX64()
macosArm64()

@Suppress("OPT_IN_USAGE")
applyHierarchyTemplate {
common {
group("jvm") {
withAndroidTarget()
withJvm()
}
group("skia") {
withJvm()
group("darwin") {
group("apple") {
group("ios") {
withIosX64()
withIosArm64()
withIosSimulatorArm64()
}
group("macos") {
withMacosX64()
withMacosArm64()
}
}
withJs()
}
}
}
}

explicitApi()
}

commonExtension.apply {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion =
libs.findVersion("androidxComposeCompiler").get().toString()
}

packaging {
resources {
excludes.add("/META-INF/{AL2.0,LGPL2.1}")
}
}
}
}

private fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val enableMetrics = (enableMetricsProvider.orNull == "true")
if (enableMetrics) {
val metricsFolder = File(project.buildDir, "compose-metrics")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=${metricsFolder.absolutePath}/compose_metrics"
)
}

val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
val enableReports = (enableReportsProvider.orNull == "true")
if (enableReports) {
val reportsFolder = File(project.buildDir, "compose-reports")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${reportsFolder.absolutePath}/compose_metrics"
)
}
return metricParameters.toList()
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.jetbrains.compose) apply false
alias(libs.plugins.kotlin.binary.compatibility) apply false
alias(libs.plugins.baseline.profile) apply false
alias(libs.plugins.hilt) apply false
Expand Down
13 changes: 13 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ android.nonTransitiveRClass=true
enableComposeCompilerMetrics=true
enableComposeCompilerReports=true

# MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.stability.nowarn=true
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.native.binary.memoryModel=experimental
kotlin.native.cacheKind=none

# Compose
org.jetbrains.compose.experimental.uikit.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
compose.kotlin.native.manageCacheKind=false

# Required to publish to Nexus (see https://github.com/gradle/gradle/issues/11308)
systemProp.org.gradle.internal.publish.checksums.insecure=true

Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ androidxJunit = "1.1.5"
androidxMacroBenchmark = "1.2.2"
androidxProfileinstaller = "1.3.1"
androidxUiAutomator = "2.3.0-beta01"
jetbrains-compose = "1.5.11"
glide = "4.16.0"
fresco = "3.1.3"
coil = "2.5.0"
Expand Down Expand Up @@ -73,7 +74,8 @@ android-application = { id = "com.android.application", version.ref = "androidGr
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
nexus-plugin = { id = "com.vanniktech.maven.publish", version.ref = "nexusPlugin" }
kotlin-binary-compatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinBinaryCompatibility" }
Expand Down
Loading