Skip to content

Commit ce89665

Browse files
committed
CfW: Prevent UnpackSkikoWasmRuntime task execution when it's not needed (#4824)
Fixes: #4823 In #4796 we intentionally started to configure the web app for all k/js and k/wasm targets. The configuration involves adding a dependency on skiko-wasm runtime and unpacking it. Some projects don't need skiko-wasm-runtime (like those based on compose.html or just compose.runtime). **Solution:** We check if there is a dependency on org.jetbrains.compose.ui libraries (including transitive dependencies). If we find it, then we enable skikoUnpack task. Otherwise it's disabled. ## Testing - Build the gradle plugin locally (with this change) - Used it in our html landing example: https://github.com/JetBrains/compose-multiplatform/blob/master/examples/html/landing - Run `./gradlew jsBrowserDistribution`, check `.../compose-multiplatform/examples/html/landing/build/dist/js/productionExecutable` and see NO skiko.* files added there - Then add `implementation(compose.foundation)` dependency in build.gradle.jts and run `./gradlew clean jsBrowserDistribution` again - the build/dist contains skiko.* now (cherry picked from commit 30164c5)
1 parent b5daa4d commit ce89665

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,34 @@ internal fun Project.configureWeb(
2323
composeExt: ComposeExtension,
2424
) {
2525
val webExt = composeExt.extensions.getByType(WebExtension::class.java)
26+
27+
// here we check all dependencies (including transitive)
28+
// If there is compose.ui, then skiko is required!
29+
val shouldRunUnpackSkiko = project.provider {
30+
var dependsOnComposeUi = false
31+
project.configurations.matching { configuration ->
32+
val isWasmOrJs = configuration.name.contains("js", true) ||
33+
configuration.name.contains("wasm", true)
34+
35+
configuration.isCanBeResolved && isWasmOrJs
36+
}.all { configuration ->
37+
val match = configuration.incoming.artifacts.resolvedArtifacts.get().any { artifact ->
38+
artifact.id.componentIdentifier.toString().contains("org.jetbrains.compose.ui:ui:")
39+
}
40+
41+
dependsOnComposeUi = dependsOnComposeUi || match
42+
}
43+
dependsOnComposeUi
44+
}
45+
2646
// configure only if there is k/wasm or k/js target:
2747
webExt.targetsToConfigure(project)
28-
.configureWebApplication(project)
48+
.configureWebApplication(project, shouldRunUnpackSkiko)
2949
}
3050

3151
internal fun Collection<KotlinJsIrTarget>.configureWebApplication(
32-
project: Project
52+
project: Project,
53+
shouldRunUnpackSkiko: Provider<Boolean>
3354
) {
3455
val skikoJsWasmRuntimeConfiguration = project.configurations.create("COMPOSE_SKIKO_JS_WASM_RUNTIME")
3556
val skikoJsWasmRuntimeDependency = skikoVersionProvider(project).map { skikoVersion ->
@@ -47,6 +68,10 @@ internal fun Collection<KotlinJsIrTarget>.configureWebApplication(
4768
testCompilation.defaultSourceSet.resources.srcDir(unpackedRuntimeDir)
4869

4970
val unpackRuntime = project.registerTask<UnpackSkikoWasmRuntimeTask>(taskName) {
71+
onlyIf {
72+
shouldRunUnpackSkiko.get()
73+
}
74+
5075
skikoRuntimeFiles = skikoJsWasmRuntimeConfiguration
5176
outputDir.set(unpackedRuntimeDir)
5277
}

0 commit comments

Comments
 (0)