Skip to content

Commit 197146a

Browse files
authored
Wasm target support (#188)
* Enable Wasm target and updated Kotlin version to 1.9.10
1 parent f749dc0 commit 197146a

File tree

9 files changed

+119
-2
lines changed

9 files changed

+119
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![JetBrains incubator project](https://jb.gg/badges/incubator.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
55
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)
66
[![Download](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-io-core?versionSuffix=0.2.1)](https://central.sonatype.com/artifact/org.jetbrains.kotlinx/kotlinx-io-core/0.2.1)
7-
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
7+
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
88
[![TeamCity build](https://img.shields.io/teamcity/build/s/KotlinTools_KotlinxIo_BuildAggregated.svg?server=http%3A%2F%2Fteamcity.jetbrains.com)](https://teamcity.jetbrains.com/viewType.html?buildTypeId=KotlinTools_KotlinxIo_BuildAggregated&guest=1)
99
[![KDoc link](https://img.shields.io/badge/API_reference-KDoc-blue)](https://fzhinkin.github.io/kotlinx-io-dokka-docs-preview/)
1010

build-logic/src/main/kotlin/kotlinx/io/conventions/kotlinx-io-multiplatform.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
77
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
8+
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
89
import kotlin.jvm.optionals.getOrNull
910

1011
plugins {
@@ -36,6 +37,14 @@ kotlin {
3637
}
3738
}
3839

40+
@OptIn(org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl::class)
41+
wasm {
42+
nodejs()
43+
// Disabled because we can't exclude some tests: https://youtrack.jetbrains.com/issue/KT-58291
44+
// browser()
45+
binaries.executable()
46+
}
47+
3948
sourceSets {
4049
commonTest {
4150
dependencies {
@@ -163,3 +172,7 @@ fun androidTargets() = listOf(
163172
"androidNativeX64",
164173
"androidNativeX86"
165174
)
175+
176+
rootProject.the<NodeJsRootExtension>().apply {
177+
nodeVersion = "20.4.0"
178+
}

core/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ kotlin {
3131
}
3232
}
3333

34+
@OptIn(org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl::class)
35+
wasm {
36+
nodejs {
37+
testTask(Action {
38+
useMocha {
39+
timeout = "300s"
40+
}
41+
filter.setExcludePatterns("*SmokeFileTest*")
42+
})
43+
}
44+
}
45+
3446
sourceSets {
3547
commonMain {
3648
dependencies {

core/wasm/src/-PlatformWasm.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.io
7+
8+
import kotlinx.io.internal.commonAsUtf8ToByteArray
9+
10+
internal actual fun String.asUtf8ToByteArray(): ByteArray = commonAsUtf8ToByteArray()
11+
12+
public actual open class IOException actual constructor(
13+
message: String?,
14+
cause: Throwable?
15+
) : Exception(message, cause) {
16+
public actual constructor(message: String?) : this(message, null)
17+
}
18+
19+
public actual open class EOFException actual constructor(message: String?) : IOException(message)

core/wasm/src/RawSink.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.io
7+
8+
@OptIn(ExperimentalStdlibApi::class)
9+
public actual interface RawSink : AutoCloseableAlias {
10+
public actual fun write(source: Buffer, byteCount: Long)
11+
12+
public actual fun flush()
13+
14+
actual override fun close()
15+
}

core/wasm/src/SegmentPool.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.io
7+
8+
internal actual object SegmentPool {
9+
actual val MAX_SIZE: Int = 0
10+
11+
actual val byteCount: Int = 0
12+
13+
actual fun take(): Segment = Segment()
14+
15+
actual fun recycle(segment: Segment) {
16+
}
17+
}

core/wasm/src/files/PathsWasm.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.io.files
7+
8+
import kotlinx.io.Sink
9+
import kotlinx.io.Source
10+
11+
12+
public actual class Path internal constructor(private val path: String,
13+
@Suppress("UNUSED_PARAMETER") any: Any?) {
14+
override fun toString(): String = path
15+
}
16+
17+
public actual fun Path(path: String): Path {
18+
return Path(path, null)
19+
}
20+
21+
public actual fun Path.source(): Source {
22+
TODO("Paths are not supported for Wasm target")
23+
}
24+
25+
public actual fun Path.sink(): Sink {
26+
TODO("Paths are not supported for Wasm target")
27+
}

core/wasm/test/utils.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.io
7+
8+
actual fun createTempFile(): String {
9+
TODO("Paths are not supported for Wasm target")
10+
}
11+
12+
actual fun deleteFile(path: String) {
13+
TODO("Paths are not supported for Wasm target")
14+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
kotlin = "1.9.0"
2+
kotlin = "1.9.10"
33
java = "8"
44
dokka = "1.8.20"
55
kover = "0.7.3"

0 commit comments

Comments
 (0)