Skip to content

Commit

Permalink
add wasmJs support
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Feb 16, 2024
1 parent 1f54638 commit cae673f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
strategy:
matrix:
os: [ macos-11 ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
if: ${{ github.repository == 'hoc081098/kmp-viewmodel' }}
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' && github.repository == 'hoc081098/kmp-viewmodel' }}
strategy:
matrix:
os: [ macos-11 ]
os: [ macos-14 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Liked some of my work? Buy me a coffee (or more likely a beer)
> Because the `ViewModel.viewModelScope` depends on `Dispatchers.Main` provided by that libraries on Desktop.
- `js` (`IR`).
- `wasmJs`.
- `Darwin` targets:
- `iosArm64`, `iosX64`, `iosSimulatorArm64`.
- `watchosArm32`, `watchosArm64`, `watchosX64`, `watchosSimulatorArm64`.
Expand Down
1 change: 1 addition & 0 deletions docs/multiplatform.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
> Because the `ViewModel.viewModelScope` depends on `Dispatchers.Main` provided by that libraries on Desktop.
- `js` (`IR`).
- `wasmJs`.
- `Darwin` targets:
- `iosArm64`, `iosX64`, `iosSimulatorArm64`.
- `watchosArm32`, `watchosArm64`, `watchosX64`, `watchosSimulatorArm64`.
Expand Down
39 changes: 33 additions & 6 deletions viewmodel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("ClassName")

import java.net.URL
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

@Suppress("DSL_SCOPE_VIOLATION")
Expand Down Expand Up @@ -45,15 +46,24 @@ kotlin {
}
}
js(IR) {
compilations.all {
kotlinOptions {
sourceMap = true
moduleKind = "commonjs"
moduleName = project.name
compilations.configureEach {
compilerOptions.configure {
sourceMap.set(true)
moduleKind.set(JsModuleKind.MODULE_COMMONJS)
}
}
browser()
nodejs()
}
@OptIn(org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl::class)
wasmJs {
// Module name should be different from the one from JS
// otherwise IC tasks that start clashing different modules with the same module name
moduleName = project.name + "Wasm"
browser()
nodejs()
}

iosArm64()
iosX64()
Expand Down Expand Up @@ -119,16 +129,33 @@ kotlin {
}
}

jsMain {
val jsAndWasmMain by creating {
dependsOn(nonAndroidMain)
}
jsTest {
val jsAndWasmTest by creating {
dependsOn(nonAndroidTest)
}

jsMain {
dependsOn(jsAndWasmMain)
}
jsTest {
dependsOn(jsAndWasmTest)
dependencies {
implementation(kotlin("test-js"))
}
}

val wasmJsMain by getting {
dependsOn(jsAndWasmMain)
}
val wasmJsTest by getting {
dependsOn(jsAndWasmTest)
dependencies {
implementation(kotlin("test-wasm-js"))
}
}

nativeMain {
dependsOn(nonAndroidMain)
dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.hoc081098.kmp.viewmodel.utils

actual suspend fun runBlockInNewThread(block: () -> Unit) = block()

0 comments on commit cae673f

Please sign in to comment.