Skip to content

Commit 5d9b365

Browse files
JakeWhartoncolinrtwhite
authored andcommitted
Unify multiplatform targets into named groups (#2070)
This gives us more control over what targets are built for which parts of the codebase based on their type. The big change is the drop of MacOS targets which were wholly unused. They will likely return at some point, along with new targets for common modules as well as for Compose UI, and this new grouping will make that easy to do. Before: $ gw build --dry-run | grep -c SKIPPED 7469 After: $ gw build --dry-run | grep -c SKIPPED 6405
1 parent 27219e8 commit 5d9b365

File tree

52 files changed

+300
-337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+300
-337
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Breaking:
2424
non-null if it's detached due to exception.
2525
-`Content.awaitContent()` now accepts an optional `Int` parameter for the number of updates to
2626
observe before the function returns.
27+
- MacOS targets have been (temporarily) removed from all modules.
28+
2729

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

build-support/src/main/kotlin/app/cash/redwood/buildsupport/KmpTargets.kt

-53
This file was deleted.

build-support/src/main/kotlin/app/cash/redwood/buildsupport/RedwoodBuildExtension.kt

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package app.cash.redwood.buildsupport
1717

1818
interface RedwoodBuildExtension {
19+
fun targets(group: TargetGroup)
20+
1921
/** Add the Compose compiler plugin. */
2022
fun composeCompiler()
2123

@@ -39,3 +41,27 @@ interface RedwoodBuildExtension {
3941
/** Consume a Zipline application in an Android application and embed it within assets. */
4042
fun embedZiplineApplication(dependencyNotation: Any)
4143
}
44+
45+
enum class TargetGroup {
46+
/** Common targets supported by core modules which are not specific to any platform. */
47+
Common,
48+
49+
/** Same as [Common], but with an additional Android target rather than relying on JVM. */
50+
CommonWithAndroid,
51+
52+
/** Tooling only runs on the JVM. */
53+
Tooling,
54+
55+
/** All toolkit targets for common modules. Includes JVM but not Android. */
56+
ToolkitAllWithoutAndroid,
57+
ToolkitAndroid,
58+
ToolkitIos,
59+
ToolkitHtml,
60+
ToolkitComposeUi,
61+
62+
/** Guest code which runs inside Treehouse. This also includes the JVM for easier testing. */
63+
TreehouseGuest,
64+
65+
/** Host code which supports loading Treehouse guest code. */
66+
TreehouseHost,
67+
}

build-support/src/main/kotlin/app/cash/redwood/buildsupport/RedwoodBuildPlugin.kt

+90
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
*/
1616
package app.cash.redwood.buildsupport
1717

18+
import app.cash.redwood.buildsupport.TargetGroup.Common
19+
import app.cash.redwood.buildsupport.TargetGroup.CommonWithAndroid
20+
import app.cash.redwood.buildsupport.TargetGroup.Tooling
21+
import app.cash.redwood.buildsupport.TargetGroup.ToolkitAllWithoutAndroid
22+
import app.cash.redwood.buildsupport.TargetGroup.ToolkitAndroid
23+
import app.cash.redwood.buildsupport.TargetGroup.ToolkitComposeUi
24+
import app.cash.redwood.buildsupport.TargetGroup.ToolkitHtml
25+
import app.cash.redwood.buildsupport.TargetGroup.ToolkitIos
26+
import app.cash.redwood.buildsupport.TargetGroup.TreehouseGuest
27+
import app.cash.redwood.buildsupport.TargetGroup.TreehouseHost
1828
import com.android.build.api.variant.AndroidComponentsExtension
1929
import com.android.build.gradle.BaseExtension
2030
import com.diffplug.gradle.spotless.SpotlessExtension
@@ -276,6 +286,73 @@ class RedwoodBuildPlugin : Plugin<Project> {
276286
}
277287

278288
private class RedwoodBuildExtensionImpl(private val project: Project) : RedwoodBuildExtension {
289+
override fun targets(group: TargetGroup) {
290+
when (group) {
291+
Common -> {
292+
project.applyKotlinMultiplatform {
293+
iosTargets()
294+
js().browser()
295+
jvm()
296+
}
297+
}
298+
CommonWithAndroid -> {
299+
project.plugins.apply("com.android.library")
300+
project.applyKotlinMultiplatform {
301+
androidTarget().publishLibraryVariants("release")
302+
iosTargets()
303+
js().browser()
304+
jvm()
305+
}
306+
}
307+
Tooling -> {
308+
project.plugins.apply("org.jetbrains.kotlin.jvm")
309+
}
310+
ToolkitAllWithoutAndroid -> {
311+
project.applyKotlinMultiplatform {
312+
iosTargets()
313+
js().browser()
314+
jvm()
315+
}
316+
}
317+
ToolkitAndroid -> {
318+
project.plugins.apply("com.android.library")
319+
project.plugins.apply("org.jetbrains.kotlin.android")
320+
}
321+
ToolkitIos -> {
322+
project.applyKotlinMultiplatform {
323+
iosTargets()
324+
}
325+
}
326+
ToolkitHtml -> {
327+
project.applyKotlinMultiplatform {
328+
js().browser()
329+
}
330+
}
331+
ToolkitComposeUi -> {
332+
project.plugins.apply("com.android.library")
333+
project.applyKotlinMultiplatform {
334+
androidTarget().publishLibraryVariants("release")
335+
iosTargets()
336+
jvm()
337+
}
338+
}
339+
TreehouseGuest -> {
340+
project.applyKotlinMultiplatform {
341+
js().nodejs()
342+
jvm() // For easier testing.
343+
}
344+
}
345+
TreehouseHost -> {
346+
project.plugins.apply("com.android.library")
347+
project.applyKotlinMultiplatform {
348+
androidTarget().publishLibraryVariants("release")
349+
iosTargets()
350+
jvm()
351+
}
352+
}
353+
}
354+
}
355+
279356
override fun composeCompiler() {
280357
project.plugins.apply(ComposePlugin::class.java)
281358
}
@@ -506,3 +583,16 @@ private fun Project.withKotlinPlugins(block: KotlinProjectExtension.() -> Unit)
506583
pluginManager.withPlugin("org.jetbrains.kotlin.jvm", handler)
507584
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform", handler)
508585
}
586+
587+
private fun Project.applyKotlinMultiplatform(block: KotlinMultiplatformExtension.() -> Unit) {
588+
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
589+
val kotlin = extensions.getByType(KotlinMultiplatformExtension::class.java)
590+
kotlin.block()
591+
kotlin.applyDefaultHierarchyTemplate()
592+
}
593+
594+
private fun KotlinMultiplatformExtension.iosTargets() {
595+
iosArm64()
596+
iosSimulatorArm64()
597+
iosX64()
598+
}

kotlin-js-store/yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ source-map-loader@4.0.1:
23002300
iconv-lite "^0.6.3"
23012301
source-map-js "^1.0.2"
23022302

2303-
source-map-support@~0.5.20:
2303+
source-map-support@0.5.21, source-map-support@~0.5.20:
23042304
version "0.5.21"
23052305
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
23062306
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==

redwood-compose/build.gradle

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import app.cash.redwood.buildsupport.ComposeHelpers
2-
import app.cash.redwood.buildsupport.KmpTargets
32

4-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
5-
apply plugin: 'com.android.library'
3+
import static app.cash.redwood.buildsupport.TargetGroup.CommonWithAndroid
64

75
redwoodBuild {
6+
targets(CommonWithAndroid)
87
composeCompiler()
98
publishing()
109
}
1110

1211
kotlin {
13-
KmpTargets.addAllTargets(project)
14-
1512
sourceSets {
1613
commonMain {
1714
kotlin.srcDir(ComposeHelpers.get(tasks, 'app.cash.redwood.compose'))

redwood-composeui/build.gradle

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import app.cash.redwood.buildsupport.KmpTargets
2-
3-
apply plugin: 'com.android.library'
4-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
1+
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitComposeUi
52

63
redwoodBuild {
4+
targets(ToolkitComposeUi)
75
composeCompiler()
86
publishing()
97
}
108

119
kotlin {
12-
KmpTargets.addAllTargets(project, true /* skipJs */)
13-
1410
sourceSets {
1511
commonMain {
1612
dependencies {

redwood-layout-api/build.gradle

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import app.cash.redwood.buildsupport.KmpTargets
2-
3-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
4-
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
1+
import static app.cash.redwood.buildsupport.TargetGroup.Common
52

63
redwoodBuild {
4+
targets(Common)
75
composeCompiler()
86
publishing()
97
}
108

11-
kotlin {
12-
KmpTargets.addAllTargets(project)
9+
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
1310

11+
kotlin {
1412
sourceSets {
1513
commonMain {
1614
dependencies {

redwood-layout-compose/build.gradle

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import app.cash.redwood.buildsupport.KmpTargets
2-
3-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
4-
apply plugin: 'app.cash.redwood.generator.compose'
1+
import static app.cash.redwood.buildsupport.TargetGroup.Common
52

63
redwoodBuild {
4+
targets(Common)
75
publishing()
86
}
97

10-
kotlin {
11-
KmpTargets.addAllTargets(project)
8+
apply plugin: 'app.cash.redwood.generator.compose'
129

10+
kotlin {
1311
sourceSets {
1412
commonMain {
1513
dependencies {

redwood-layout-composeui/build.gradle

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import app.cash.redwood.buildsupport.FlexboxHelpers
2-
import app.cash.redwood.buildsupport.KmpTargets
32

4-
apply plugin: 'com.android.library'
5-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
6-
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
7-
apply plugin: 'app.cash.paparazzi'
3+
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitComposeUi
84

95
redwoodBuild {
6+
targets(ToolkitComposeUi)
107
composeCompiler()
118
publishing()
129
}
1310

14-
kotlin {
15-
KmpTargets.addAllTargets(project, true /* skipJs */)
11+
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
12+
apply plugin: 'app.cash.paparazzi'
1613

14+
kotlin {
1715
sourceSets {
1816
commonMain {
1917
kotlin.srcDir(FlexboxHelpers.get(tasks, 'app.cash.redwood.layout.composeui').get())

redwood-layout-dom/build.gradle

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
1+
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitHtml
22

33
redwoodBuild {
4+
targets(ToolkitHtml)
45
publishing()
56
}
67

78
kotlin {
8-
js {
9-
browser()
10-
}
11-
129
sourceSets {
1310
commonMain {
1411
dependencies {

redwood-layout-modifiers/build.gradle

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import app.cash.redwood.buildsupport.KmpTargets
2-
3-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
4-
apply plugin: 'app.cash.redwood.generator.modifiers'
1+
import static app.cash.redwood.buildsupport.TargetGroup.Common
52

63
redwoodBuild {
4+
targets(Common)
75
publishing()
86
}
97

10-
kotlin {
11-
KmpTargets.addAllTargets(project)
8+
apply plugin: 'app.cash.redwood.generator.modifiers'
129

10+
kotlin {
1311
sourceSets {
1412
commonMain {
1513
dependencies {

redwood-layout-schema/build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
apply plugin: 'org.jetbrains.kotlin.jvm'
2-
apply plugin: 'app.cash.redwood.schema'
1+
import static app.cash.redwood.buildsupport.TargetGroup.Tooling
32

43
redwoodBuild {
4+
targets(Tooling)
55
publishing()
66
}
77

8+
apply plugin: 'app.cash.redwood.schema'
9+
810
dependencies {
911
api projects.redwoodLayoutApi
1012
}

redwood-layout-shared-test/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import app.cash.redwood.buildsupport.KmpTargets
1+
import static app.cash.redwood.buildsupport.TargetGroup.ToolkitAllWithoutAndroid
22

3-
apply plugin: 'org.jetbrains.kotlin.multiplatform'
3+
redwoodBuild {
4+
targets(ToolkitAllWithoutAndroid)
5+
}
46

57
kotlin {
6-
KmpTargets.addAllTargets(project, true /* skipJs */)
7-
88
sourceSets {
99
commonMain {
1010
dependencies {

0 commit comments

Comments
 (0)