Skip to content

Commit

Permalink
Merge pull request #26 from ahmedre/wasm
Browse files Browse the repository at this point in the history
Support web assembly
  • Loading branch information
ahmedre authored May 12, 2024
2 parents 174b598 + bae4f23 commit 5cb034e
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 3 deletions.
34 changes: 33 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,23 @@ kotlin {
}
}

val jsMain by getting {
val webMain by creating {
dependsOn(commonMain)
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() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 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.network

import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.js.JsClient

actual fun sduiClient(config: HttpClientConfig<*>.() -> Unit): HttpClient = HttpClient(JsClient()) {
config(this)
}
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>
23 changes: 22 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,15 +67,26 @@ kotlin {
}
}

val jsMain by getting {
val webMain by creating {
dependsOn(commonMain)
dependencies {
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(libs.coil.network.ktor)
implementation(libs.ktor.client.core)
}
}

val jsMain by getting {
dependsOn(webMain)
dependencies {
implementation(libs.ktor.client.js)
}
}

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 5cb034e

Please sign in to comment.