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

Unify multiplatform targets into named groups #2070

Merged
merged 1 commit into from
May 31, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Breaking:
non-null if it's detached due to exception.
-`Content.awaitContent()` now accepts an optional `Int` parameter for the number of updates to
observe before the function returns.
- MacOS targets have been (temporarily) removed from all modules.


## [0.11.0] - 2024-05-15
[0.11.0]: https://github.com/cashapp/redwood/releases/tag/0.11.0
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package app.cash.redwood.buildsupport

interface RedwoodBuildExtension {
fun targets(group: TargetGroup)

/** Add the Compose compiler plugin. */
fun composeCompiler()

Expand All @@ -39,3 +41,27 @@ interface RedwoodBuildExtension {
/** Consume a Zipline application in an Android application and embed it within assets. */
fun embedZiplineApplication(dependencyNotation: Any)
}

enum class TargetGroup {
/** Common targets supported by core modules which are not specific to any platform. */
Common,

/** Same as [Common], but with an additional Android target rather than relying on JVM. */
CommonWithAndroid,

/** Tooling only runs on the JVM. */
Tooling,

/** All toolkit targets for common modules. Includes JVM but not Android. */
ToolkitAllWithoutAndroid,
ToolkitAndroid,
ToolkitIos,
ToolkitHtml,
ToolkitComposeUi,

/** Guest code which runs inside Treehouse. This also includes the JVM for easier testing. */
TreehouseGuest,

/** Host code which supports loading Treehouse guest code. */
TreehouseHost,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*/
package app.cash.redwood.buildsupport

import app.cash.redwood.buildsupport.TargetGroup.Common
import app.cash.redwood.buildsupport.TargetGroup.CommonWithAndroid
import app.cash.redwood.buildsupport.TargetGroup.Tooling
import app.cash.redwood.buildsupport.TargetGroup.ToolkitAllWithoutAndroid
import app.cash.redwood.buildsupport.TargetGroup.ToolkitAndroid
import app.cash.redwood.buildsupport.TargetGroup.ToolkitComposeUi
import app.cash.redwood.buildsupport.TargetGroup.ToolkitHtml
import app.cash.redwood.buildsupport.TargetGroup.ToolkitIos
import app.cash.redwood.buildsupport.TargetGroup.TreehouseGuest
import app.cash.redwood.buildsupport.TargetGroup.TreehouseHost
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.gradle.BaseExtension
import com.diffplug.gradle.spotless.SpotlessExtension
Expand Down Expand Up @@ -276,6 +286,73 @@ class RedwoodBuildPlugin : Plugin<Project> {
}

private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodBuildExtension {
override fun targets(group: TargetGroup) {
when (group) {
Common -> {
project.applyKotlinMultiplatform {
iosTargets()
js().browser()
jvm()
}
}
CommonWithAndroid -> {
project.plugins.apply("com.android.library")
project.applyKotlinMultiplatform {
androidTarget().publishLibraryVariants("release")
iosTargets()
js().browser()
jvm()
}
}
Tooling -> {
project.plugins.apply("org.jetbrains.kotlin.jvm")
}
ToolkitAllWithoutAndroid -> {
project.applyKotlinMultiplatform {
iosTargets()
js().browser()
jvm()
}
}
ToolkitAndroid -> {
project.plugins.apply("com.android.library")
project.plugins.apply("org.jetbrains.kotlin.android")
}
ToolkitIos -> {
project.applyKotlinMultiplatform {
iosTargets()
}
}
ToolkitHtml -> {
project.applyKotlinMultiplatform {
js().browser()
}
}
ToolkitComposeUi -> {
project.plugins.apply("com.android.library")
project.applyKotlinMultiplatform {
androidTarget().publishLibraryVariants("release")
iosTargets()
jvm()
}
}
TreehouseGuest -> {
project.applyKotlinMultiplatform {
js().nodejs()
jvm() // For easier testing.
}
}
TreehouseHost -> {
project.plugins.apply("com.android.library")
project.applyKotlinMultiplatform {
androidTarget().publishLibraryVariants("release")
iosTargets()
jvm()
}
}
}
}

override fun composeCompiler() {
project.plugins.apply(ComposePlugin::class.java)
}
Expand Down Expand Up @@ -506,3 +583,16 @@ private fun Project.withKotlinPlugins(block: KotlinProjectExtension.() -> Unit)
pluginManager.withPlugin("org.jetbrains.kotlin.jvm", handler)
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform", handler)
}

private fun Project.applyKotlinMultiplatform(block: KotlinMultiplatformExtension.() -> Unit) {
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
val kotlin = extensions.getByType(KotlinMultiplatformExtension::class.java)
kotlin.block()
kotlin.applyDefaultHierarchyTemplate()
}

private fun KotlinMultiplatformExtension.iosTargets() {
iosArm64()
iosSimulatorArm64()
iosX64()
}
2 changes: 1 addition & 1 deletion kotlin-js-store/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ source-map-loader@4.0.1:
iconv-lite "^0.6.3"
source-map-js "^1.0.2"

source-map-support@~0.5.20:
source-map-support@0.5.21, source-map-support@~0.5.20:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
Expand Down
7 changes: 2 additions & 5 deletions redwood-compose/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import app.cash.redwood.buildsupport.ComposeHelpers
import app.cash.redwood.buildsupport.KmpTargets

apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'com.android.library'
import static app.cash.redwood.buildsupport.TargetGroup.CommonWithAndroid

redwoodBuild {
targets(CommonWithAndroid)
composeCompiler()
publishing()
}

kotlin {
KmpTargets.addAllTargets(project)

sourceSets {
commonMain {
kotlin.srcDir(ComposeHelpers.get(tasks, 'app.cash.redwood.compose'))
Expand Down
8 changes: 2 additions & 6 deletions redwood-composeui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import app.cash.redwood.buildsupport.KmpTargets

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.multiplatform'
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitComposeUi

redwoodBuild {
targets(ToolkitComposeUi)
composeCompiler()
publishing()
}

kotlin {
KmpTargets.addAllTargets(project, true /* skipJs */)

sourceSets {
commonMain {
dependencies {
Expand Down
10 changes: 4 additions & 6 deletions redwood-layout-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import app.cash.redwood.buildsupport.KmpTargets

apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
import static app.cash.redwood.buildsupport.TargetGroup.Common

redwoodBuild {
targets(Common)
composeCompiler()
publishing()
}

kotlin {
KmpTargets.addAllTargets(project)
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'

kotlin {
sourceSets {
commonMain {
dependencies {
Expand Down
10 changes: 4 additions & 6 deletions redwood-layout-compose/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import app.cash.redwood.buildsupport.KmpTargets

apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'app.cash.redwood.generator.compose'
import static app.cash.redwood.buildsupport.TargetGroup.Common

redwoodBuild {
targets(Common)
publishing()
}

kotlin {
KmpTargets.addAllTargets(project)
apply plugin: 'app.cash.redwood.generator.compose'

kotlin {
sourceSets {
commonMain {
dependencies {
Expand Down
12 changes: 5 additions & 7 deletions redwood-layout-composeui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import app.cash.redwood.buildsupport.FlexboxHelpers
import app.cash.redwood.buildsupport.KmpTargets

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'app.cash.paparazzi'
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitComposeUi

redwoodBuild {
targets(ToolkitComposeUi)
composeCompiler()
publishing()
}

kotlin {
KmpTargets.addAllTargets(project, true /* skipJs */)
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'app.cash.paparazzi'

kotlin {
sourceSets {
commonMain {
kotlin.srcDir(FlexboxHelpers.get(tasks, 'app.cash.redwood.layout.composeui').get())
Expand Down
7 changes: 2 additions & 5 deletions redwood-layout-dom/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
apply plugin: 'org.jetbrains.kotlin.multiplatform'
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitHtml

redwoodBuild {
targets(ToolkitHtml)
publishing()
}

kotlin {
js {
browser()
}

sourceSets {
commonMain {
dependencies {
Expand Down
10 changes: 4 additions & 6 deletions redwood-layout-modifiers/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import app.cash.redwood.buildsupport.KmpTargets

apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'app.cash.redwood.generator.modifiers'
import static app.cash.redwood.buildsupport.TargetGroup.Common

redwoodBuild {
targets(Common)
publishing()
}

kotlin {
KmpTargets.addAllTargets(project)
apply plugin: 'app.cash.redwood.generator.modifiers'

kotlin {
sourceSets {
commonMain {
dependencies {
Expand Down
6 changes: 4 additions & 2 deletions redwood-layout-schema/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'app.cash.redwood.schema'
import static app.cash.redwood.buildsupport.TargetGroup.Tooling

redwoodBuild {
targets(Tooling)
publishing()
}

apply plugin: 'app.cash.redwood.schema'

dependencies {
api projects.redwoodLayoutApi
}
Expand Down
8 changes: 4 additions & 4 deletions redwood-layout-shared-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import app.cash.redwood.buildsupport.KmpTargets
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitAllWithoutAndroid

apply plugin: 'org.jetbrains.kotlin.multiplatform'
redwoodBuild {
targets(ToolkitAllWithoutAndroid)
}

kotlin {
KmpTargets.addAllTargets(project, true /* skipJs */)

sourceSets {
commonMain {
dependencies {
Expand Down
Loading