diff --git a/build.gradle.kts b/build.gradle.kts index b4f2d0a0..b327b5c9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,6 +4,10 @@ import io.gitlab.arturbosch.detekt.DetektPlugin import io.gitlab.arturbosch.detekt.extensions.DetektExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent +import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin +import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask @Suppress("DSL_SCOPE_VIOLATION") plugins { @@ -107,3 +111,32 @@ allprojects { parent?.subprojects?.forEach { dependsOn(it.tasks.withType(taskClass)) } } } + +/** + * [Reference](https://github.com/square/okio/blob/55b7210fb3d52de07f4bc1122c5062e38df576d9/build.gradle.kts#L227-L248). + * + * Select a NodeJS version with WASI and WASM GC. + * https://github.com/Kotlin/kotlin-wasm-examples/blob/main/wasi-example/build.gradle.kts + */ +plugins.withType { + extensions.getByType().apply { + if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows) { + // We're waiting for a Windows build of NodeJS that can do WASM GC + WASI. + nodeVersion = "21.4.0" + } else { + // Reference: + // https://github.com/drewhamilton/Poko/blob/72ec8d24cf48a74b3d1125c94f0e625ab956b93f/build.gradle.kts#L17-L19 + // WASM requires a canary Node.js version. This is the last v21 canary, and has both + // darwin-arm64 and darwin-x64 artifacts: + nodeVersion = "21.0.0-v8-canary20231024d0ddc81258" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" + } + } + // Suppress an error because yarn doesn't like our Node version string. + // warning You are using Node "21.0.0-v8-canary20231024d0ddc81258" which is not supported and + // may encounter bugs or unexpected behavior. + // error karma@6.4.2: The engine "node" is incompatible with this module. + tasks.withType().all { + args += "--ignore-engines" + } +} diff --git a/channel-event-bus/build.gradle.kts b/channel-event-bus/build.gradle.kts index 16efe186..ecbce85e 100644 --- a/channel-event-bus/build.gradle.kts +++ b/channel-event-bus/build.gradle.kts @@ -27,16 +27,26 @@ kotlin { } } } + js(IR) { - compilations.all { - kotlinOptions { - sourceMap = true - moduleKind = "commonjs" + moduleName = property("POM_ARTIFACT_ID")!!.toString() + compilations.configureEach { + compilerOptions.configure { + sourceMap.set(true) + moduleKind.set(org.jetbrains.kotlin.gradle.dsl.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 = property("POM_ARTIFACT_ID")!!.toString() + "Wasm" + browser() + nodejs() + } // According to https://kotlinlang.org/docs/native-target-support.html // Tier 1: macosX64, macosArm64, iosSimulatorArm64, iosX64 @@ -95,6 +105,12 @@ kotlin { } } + val wasmJsTest by getting { + dependencies { + implementation(kotlin("test-wasm-js")) + } + } + jvmTest { dependencies { implementation(kotlin("test-junit"))