Skip to content

Commit

Permalink
Support wasm targets for core, tests and local transport
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Nov 30, 2024
1 parent 4f066f5 commit 3e32d60
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ kotlin {
optIn.addAll(OptIns.ExperimentalSubclassOptIn)
}

applyDefaultHierarchyTemplate {
common {
group("nonJvm") {
withJs()
withWasmJs()
withWasmWasi()
group("native")
}
}
}

sourceSets.configureEach {
languageSettings {
if (name.contains("test", ignoreCase = true)) {
Expand Down
27 changes: 27 additions & 0 deletions build-logic/src/main/kotlin/rsocketbuild/targets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ package rsocketbuild

import org.gradle.jvm.toolchain.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.dsl.*

fun KotlinMultiplatformExtension.allTargets() {
jvmTarget()
jsTarget()
wasmJsTarget()
wasmWasiTarget()
nativeTargets()
}

fun KotlinMultiplatformExtension.appleTargets() {
macosX64()
macosArm64()
Expand Down Expand Up @@ -63,6 +72,24 @@ fun KotlinMultiplatformExtension.jsTarget(
}
}

@OptIn(ExperimentalWasmDsl::class)
fun KotlinMultiplatformExtension.wasmJsTarget(
supportsNode: Boolean = true,
supportsBrowser: Boolean = true,
) {
wasmJs {
if (supportsNode) nodejs()
if (supportsBrowser) browser()
}
}

@OptIn(ExperimentalWasmDsl::class)
fun KotlinMultiplatformExtension.wasmWasiTarget() {
wasmWasi {
nodejs()
}
}

fun KotlinMultiplatformExtension.jvmTarget(
jdkVersion: Int = 8,
jdkAdditionalTestVersions: Set<Int> = setOf(11, 17, 21),
Expand Down
4 changes: 1 addition & 3 deletions rsocket-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ plugins {
description = "rsocket-kotlin core functionality"

kotlin {
jvmTarget()
jsTarget()
nativeTargets()
allTargets()

sourceSets {
commonMain.dependencies {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,5 +19,5 @@ package io.rsocket.kotlin.logging
import io.rsocket.kotlin.*

@RSocketLoggingApi
public actual val DefaultLoggerFactory: LoggerFactory
internal actual val DefaultLoggerFactory: LoggerFactory
get() = PrintLogger
4 changes: 1 addition & 3 deletions rsocket-internal-io/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ plugins {
description = "rsocket-kotlin internal IO support"

kotlin {
jvmTarget()
jsTarget()
nativeTargets()
allTargets()

sourceSets {
commonMain.dependencies {
Expand Down
4 changes: 1 addition & 3 deletions rsocket-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ plugins {

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
jvmTarget()
jsTarget()
nativeTargets()
allTargets()

compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
Expand Down
27 changes: 27 additions & 0 deletions rsocket-test/src/wasmJsMain/kotlin/io/rsocket/kotlin/test/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.rsocket.kotlin.test

import kotlinx.coroutines.*

actual annotation class IgnoreJs
actual annotation class IgnoreJvm
actual annotation class IgnoreNative

actual val anotherDispatcher: CoroutineDispatcher get() = Dispatchers.Default

actual fun identityHashCode(instance: Any): Int = instance.hashCode()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.rsocket.kotlin.test

import kotlinx.coroutines.*

actual annotation class IgnoreJs
actual annotation class IgnoreJvm
actual annotation class IgnoreNative

actual val anotherDispatcher: CoroutineDispatcher get() = Dispatchers.Default

actual fun identityHashCode(instance: Any): Int = instance.hashCode()
4 changes: 1 addition & 3 deletions rsocket-transport-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ plugins {

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
jvmTarget()
jsTarget()
nativeTargets()
allTargets()

compilerOptions {
optIn.addAll(
Expand Down
4 changes: 1 addition & 3 deletions rsocket-transports/local/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ plugins {
description = "rsocket-kotlin Local transport implementation"

kotlin {
jvmTarget()
jsTarget()
nativeTargets()
allTargets()

sourceSets {
commonMain.dependencies {
Expand Down

0 comments on commit 3e32d60

Please sign in to comment.