Skip to content

Commit 22cbd62

Browse files
authored
WASM support (#289)
* Kotlin WASM support * update compose and kodein * Revert kodein build gradle change * Fix detekt * fix build * chore: update compose
1 parent a28fd4d commit 22cbd62

File tree

23 files changed

+71
-8
lines changed

23 files changed

+71
-8
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ buildscript {
1111
classpath(libs.plugin.ktlint)
1212
classpath(libs.plugin.maven)
1313
classpath(libs.plugin.multiplatform.compose)
14+
classpath(libs.plugin.atomicfu)
1415
}
1516
}
1617

buildSrc/src/main/kotlin/Setup.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.gradle.kotlin.dsl.withType
1515
import org.gradle.kotlin.dsl.getByType
1616
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
1717
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
18+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
1819
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1920

2021
private fun BaseExtension.setupAndroid() {
@@ -69,6 +70,7 @@ fun Project.setupModuleForAndroidxCompose(
6970
fun Project.setupModuleForComposeMultiplatform(
7071
withKotlinExplicitMode: Boolean = true,
7172
fullyMultiplatform: Boolean = false,
73+
enableWasm: Boolean = true,
7274
iosPrefixName: String = "ios" // only used in ios sample
7375
) {
7476
plugins.withType<org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper> {
@@ -92,6 +94,10 @@ fun Project.setupModuleForComposeMultiplatform(
9294
js(IR) {
9395
browser()
9496
}
97+
if (enableWasm) {
98+
@OptIn(ExperimentalWasmDsl::class)
99+
wasmJs { browser() }
100+
}
95101
macosX64()
96102
macosArm64()
97103
ios(iosPrefixName)
@@ -126,6 +132,13 @@ fun Project.setupModuleForComposeMultiplatform(
126132
}
127133

128134
if (fullyMultiplatform) {
135+
val commonWebMain by creating {
136+
dependsOn(commonMain)
137+
}
138+
139+
val jsMain by getting
140+
jsMain.dependsOn(commonWebMain)
141+
129142
val nativeMain by creating {
130143
dependsOn(commonMain)
131144
}
@@ -145,6 +158,11 @@ fun Project.setupModuleForComposeMultiplatform(
145158
val iosSimulatorArm64Main = getByName(iosPrefixName + "SimulatorArm64Main").apply {
146159
dependsOn(iosMain)
147160
}
161+
162+
if (enableWasm) {
163+
val wasmJsMain by getting
164+
wasmJsMain.dependsOn(commonWebMain)
165+
}
148166
}
149167
}
150168
}

gradle.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ kotlin.native.ignoreIncorrectDependencies=true
2121
android.defaults.buildfeatures.buildconfig = false
2222

2323
org.jetbrains.compose.experimental.macos.enabled=true
24-
org.jetbrains.compose.experimental.uikit.enabled=true
2524
org.jetbrains.compose.experimental.jscanvas.enabled=true
25+
org.jetbrains.compose.experimental.wasm.enabled=true
26+
27+
kotlinx.atomicfu.enableJvmIrTransformation=true
28+
kotlinx.atomicfu.enableNativeIrTransformation=true
29+
kotlinx.atomicfu.enableJsIrTransformation=true
2630

2731
kotlin.mpp.androidSourceSetLayoutVersion=2
2832

gradle/libs.versions.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
plugin-android = "8.1.1"
33
plugin-ktlint = "11.5.1"
44
plugin-maven = "0.25.3"
5-
plugin-multiplatform-compose = "1.5.11"
5+
plugin-multiplatform-compose = "1.6.0-rc02"
66
plugin-binaryCompatibilityValidator = "0.13.2"
7+
plugin-atomicfu = "0.23.1"
78

8-
coroutines = "1.7.3"
9+
coroutines = "1.8.0-RC2"
910
kotlin = "1.9.21"
10-
kodein = "7.20.2"
11+
kodein = "7.21.2"
1112
koin = "3.4.3"
1213
koin-compose = "1.0.4"
1314
hilt = "2.49"
@@ -24,7 +25,7 @@ rxjava = "3.1.5"
2425

2526
junit = "5.10.0"
2627

27-
multiplatformUuid = "0.8.1"
28+
multiplatformUuid = "0.8.2"
2829

2930
[libraries]
3031
plugin-android = { module = "com.android.tools.build:gradle", version.ref = "plugin-android" }
@@ -33,6 +34,7 @@ plugin-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref =
3334
plugin-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "plugin-maven" }
3435
plugin-hilt = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "hilt" }
3536
plugin-multiplatform-compose = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "plugin-multiplatform-compose" }
37+
plugin-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "plugin-atomicfu" }
3638

3739
leakCanary = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakCanary" }
3840
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }

samples/multiplatform/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Dmg
33
import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Msi
44
import org.jetbrains.compose.desktop.application.tasks.AbstractNativeMacApplicationPackageTask
55
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
6+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
67

78
plugins {
89
kotlin("multiplatform")
910
id("com.android.application")
1011
id("org.jetbrains.compose")
1112
}
1213

14+
kotlin {
15+
@OptIn(ExperimentalWasmDsl::class)
16+
wasmJs {
17+
moduleName = "composeApp"
18+
browser {
19+
commonWebpackConfig {
20+
outputFileName = "composeApp.js"
21+
}
22+
}
23+
binaries.executable()
24+
}
25+
}
26+
1327
setupModuleForComposeMultiplatform(
1428
fullyMultiplatform = true,
1529
withKotlinExplicitMode = false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import androidx.compose.ui.ExperimentalComposeUiApi
2+
import androidx.compose.ui.window.CanvasBasedWindow
3+
import cafe.adriel.voyager.sample.multiplatform.SampleApplication
4+
5+
@OptIn(ExperimentalComposeUiApi::class)
6+
fun main() {
7+
CanvasBasedWindow(canvasElementId = "ComposeTarget") { SampleApplication() }
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Compose App</title>
6+
<script type="application/javascript" src="skiko.js"></script>
7+
<script type="application/javascript" src="composeApp.js"></script>
8+
</head>
9+
<body>
10+
<canvas id="ComposeTarget"></canvas>
11+
</body>
12+
</html>

voyager-bottom-sheet-navigator/src/jsMain/kotlin/cafe/adriel/voyager/navigator/bottomSheet/internal/Actuals.js.kt renamed to voyager-bottom-sheet-navigator/src/commonWebMain/kotlin/cafe/adriel/voyager/navigator/bottomSheet/internal/Actuals.web.kt

File renamed without changes.

voyager-core/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("com.android.library")
44
id("org.jetbrains.compose")
55
id("com.vanniktech.maven.publish")
6+
id("kotlinx-atomicfu")
67
}
78

89
setupModuleForComposeMultiplatform(fullyMultiplatform = true)
@@ -36,7 +37,7 @@ kotlin {
3637
implementation(libs.lifecycle.viewModelCompose)
3738
}
3839
}
39-
val jsMain by getting {
40+
val commonWebMain by getting {
4041
dependencies {
4142
implementation(libs.multiplatformUuid)
4243
}

voyager-core/src/jsMain/kotlin/cafe.adriel.voyager.core/concurrent/AtomicInt32.js.kt renamed to voyager-core/src/commonWebMain/kotlin/cafe.adriel.voyager.core/concurrent/AtomicInt32.js.kt

File renamed without changes.

0 commit comments

Comments
 (0)