Skip to content

Commit

Permalink
Add wasm platform
Browse files Browse the repository at this point in the history
  • Loading branch information
vooft committed Jun 7, 2024
1 parent 7188a48 commit 579bbdb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Currently it is compiled for:
* mingwX64
* linuxX64
* js (browser/nodejs)
* wasm (browser/nodejs)

# Quick start
Library is published to Maven Central under name [io.github.vooft:kotlinx-serialization-smile-core](https://central.sonatype.com/search?namespace=io.github.vooft).
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serializa
kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }

# testing
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
Expand Down
8 changes: 8 additions & 0 deletions kotlinx-serialization-smile-benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kotlin.multiplatform)
Expand All @@ -21,6 +22,12 @@ kotlin {
nodejs()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
nodejs()
}

applyDefaultHierarchyTemplate()

sourceSets {
Expand Down Expand Up @@ -49,6 +56,7 @@ benchmark {
}

targets.register("js")
targets.register("wasmJs")

// not working for some reason
targets.register("macosArm64")
Expand Down
9 changes: 7 additions & 2 deletions kotlinx-serialization-smile-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
// core kotlin plugins
Expand Down Expand Up @@ -29,6 +30,12 @@ kotlin {
nodejs()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
nodejs()
}

applyDefaultHierarchyTemplate()

sourceSets {
Expand All @@ -42,9 +49,7 @@ kotlin {

commonTest.dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotest.framework.engine)
implementation(libs.kotest.assertions.core)
implementation(libs.kotest.framework.datatest)
implementation(libs.kotlin.reflect)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
package io.github.vooft.kotlinsmile.common

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import kotlin.test.Test

class ZigzagIntegerTest : FunSpec({

val data = listOf(
Zigzag(0, 0),
Zigzag(1, -1),
Zigzag(2, 1),
Zigzag(3, -2),
Zigzag(999, -500),
Zigzag(Int.MAX_VALUE - 1, Int.MAX_VALUE / 2),
Zigzag(Int.MAX_VALUE, Int.MIN_VALUE / 2),
)

// there is an issue with kotest js and withData https://github.com/kotest/kotest/pull/3913
for (datum in data) {
test("should encode ${datum.decoded} to ${datum.encoded}") {
class ZigzagIntegerTest {
@Test
fun should_encode_integer() {
for (datum in testData) {
ZigzagInteger.encode(datum.decoded) shouldBe datum.encoded
}
}

test("should decode ${datum.encoded} to ${datum.decoded}") {
@Test
fun should_decode_integer() {
for (datum in testData) {
ZigzagInteger.decode(datum.encoded) shouldBe datum.decoded
}
}
}

// context("should encode integer") {
// withData(data) {
// ZigzagInteger.encode(it.decoded) shouldBe it.encoded
// }
// }
//
// context("should decode integer") {
// withData(data) {
// ZigzagInteger.decode(it.encoded) shouldBe it.decoded
// }
// }
})
private val testData = listOf(
Zigzag(0, 0),
Zigzag(1, -1),
Zigzag(2, 1),
Zigzag(3, -2),
Zigzag(999, -500),
Zigzag(Int.MAX_VALUE - 1, Int.MAX_VALUE / 2),
Zigzag(Int.MAX_VALUE, Int.MIN_VALUE / 2),
)

private data class Zigzag(val encoded: Int, val decoded: Int)
8 changes: 8 additions & 0 deletions kotlinx-serialization-smile-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.serialization)
Expand All @@ -13,6 +15,12 @@ kotlin {
nodejs()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
nodejs()
}

applyDefaultHierarchyTemplate()

sourceSets {
Expand Down

0 comments on commit 579bbdb

Please sign in to comment.