Skip to content

Commit

Permalink
Support web assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedre committed May 12, 2024
1 parent 174b598 commit de0966c
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 3 deletions.
33 changes: 32 additions & 1 deletion catalog/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
Expand Down Expand Up @@ -27,6 +36,20 @@ kotlin {
binaries.executable()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
commonWebpackConfig {
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
static = (static ?: mutableListOf()).apply {
add(project.projectDir.path)
}
}
}
}
binaries.executable()
}

androidTarget {
compilations.all {
kotlinOptions {
Expand Down Expand Up @@ -74,14 +97,22 @@ kotlin {
}
}

val jsMain by getting {
val webMain by creating {
resources.srcDirs("src/commonRes", "../sdui/src/commonRes")
dependencies {
implementation(projects.design)
implementation(compose.ui)
implementation(libs.ktor.client.js)
}
}

val jsMain by getting {
dependsOn(webMain)
}

val wasmJsMain by getting {
dependsOn(webMain)
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions catalog/src/wasmJsMain/kotlin/dev/helw/playground/sdui/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package dev.helw.playground.sdui

import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.CanvasBasedWindow
import dev.helw.playground.sdui.design.theme.AppTheme

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
CanvasBasedWindow {
AppTheme { FullScreenDemo() }
}
}
12 changes: 12 additions & 0 deletions catalog/src/wasmJsMain/resources/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SDUi Demo</title>
<script src="skiko.js"> </script>
<script src="catalog.js"> </script>
</head>
<body>
<canvas id="ComposeTarget"></canvas>
</body>
</html>
20 changes: 19 additions & 1 deletion design/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
Expand All @@ -21,6 +29,8 @@ kotlin {
jvm("desktop")

js(IR) { browser() }
@OptIn(ExperimentalWasmDsl::class)
wasmJs() { browser() }

androidTarget {
compilations.all {
Expand Down Expand Up @@ -57,7 +67,7 @@ kotlin {
}
}

val jsMain by getting {
val webMain by creating {
dependencies {
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
Expand All @@ -66,6 +76,14 @@ kotlin {
implementation(libs.ktor.client.js)
}
}

val jsMain by getting {
dependsOn(webMain)
}

val wasmJsMain by getting {
dependsOn(webMain)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
# Compose KMP
org.jetbrains.compose.experimental.jscanvas.enabled=true

# WebAssembly
org.jetbrains.compose.experimental.wasm.enabled=true

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ coroutines = "1.8.1"
foundation = "1.6.7"
kotlin = "1.9.23"
kotlinx-serialization = "1.6.3"
ktor = "2.3.8"
ktor = "3.0.0-wasm1"
compose-compiler = "1.5.13"
compose-jb = "1.6.1"
spotless = "6.14.0"
Expand Down
11 changes: 11 additions & 0 deletions sdui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

/**
* Copyright (c) 2023 Ahmed El-Helw and Abdulahi Osoble
*
Expand All @@ -23,6 +31,9 @@ kotlin {

js(IR) { browser() }

@OptIn(ExperimentalWasmDsl::class)
wasmJs { browser() }

androidTarget {
compilations.all {
kotlinOptions {
Expand Down

0 comments on commit de0966c

Please sign in to comment.