https://kotlinlang.org logo
#webassembly
Title
# webassembly
j

John O'Reilly

09/30/2023, 10:36 AM
Is there any plans in near future to update various experimental Kotlin/Wasm and Compose for Web artefacts to work with likes of Kotlin 1.9.20.x ?
8
b

bashor

10/02/2023, 6:03 PM
Hi! Sorry for the delay. Here are some libraries compatible with
1.9.20*
and available at https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental
Copy code
kotlinx-coroutines	1.7.2-wasm1
compose-multiplatform	1.5.1-dev-wasm01
kotlinx-serialization	1.6.0-wasm0
kotlinx-atomicfu	0.22.0-wasm1
kotlinx-datetime	0.4.0-wasm2
👍🏼 1
👍🏻 1
👍 5
👍🏾 1
j

John O'Reilly

10/02/2023, 6:05 PM
very cool, thanks!
I had come across and tried to use that version of compose but getting following for some reason....could be some other issue in my setup
Copy code
An exception occurred applying plugin request [id: 'org.jetbrains.compose', version: '1.5.1-dev-wasm01']
> Failed to apply plugin 'org.jetbrains.compose'.
   > Shared build service 'org.jetbrains.compose.internal.service.ConfigurationProblemReporterService' parameters have unexpected type: org.gradle.api.services.BuildServiceParameters
is
1.4.0-dev-wasm09
the right version of compose compiler to use?
also getting
Copy code
> Could not resolve all dependencies for configuration ':compose-web:wasmJsNpmAggregated'.
   > Could not find org.jetbrains.kotlin:kotlin-stdlib:1.9.30-dev-460.
b

bashor

10/02/2023, 6:16 PM
I just update versions there
j

John O'Reilly

10/02/2023, 6:17 PM
I had been using that as reference all right....let me compare again
ok, working now, thanks!
🎉 1
started with the most minimal kmp sample I had (https://github.com/joreilly/chip-8) ....will update other samples I have that use Wasm soon
(dependency stuff i there probably needs to be cleaned up a bit as well)
b

bashor

10/02/2023, 7:03 PM
🎉
j

John O'Reilly

10/02/2023, 7:03 PM
you can play space invaders (and other games) now in Wasm based Compose for Web client 😃
👍 1
performance is a bit slow but I imagine that will improve.over time
I'll update PeopleInSpace and BikeShare KMP samples next
re. performance, could be some bottlenecks as well in chip-8 emulator....I need to look more closely at that too......though speed is reasonable in for example Compose for Desktop client
also just came across following think it's Rust based 😉 https://code.benco.io/chip8/web/
@bashor do you think performance right now is somewhat expected given stage tech is at or is it worth seeing if as mentioned there are perhaps some bottlenecks in the implementation?
@bashor is
2.3.3-wasm0
still latest version of Ktor that supports wasm (from https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental/io/ktor/ktor/)?
if I try to use that (this is a different project to above....it's BikeShare) I get
Copy code
Could not find org.jetbrains.kotlin:kotlin-stdlib-wasm:1.9.20-Beta2.
this is due I guess to
Copy code
if (requested.module.name.startsWith("kotlin-stdlib")) {
                val kotlinVersion = project.property("kotlin.version") as String
                useVersion(kotlinVersion)
            }
b

bashor

10/03/2023, 4:52 PM
is
2.3.3-wasm0
still latest version of Ktor that supports wasm
I think so, we don’t have new ktor yet (cc @Igor Yakovlev)
> though speed is reasonable in for example Compose for Desktop client I think it’s more likely related to timers directly or indirectly. There is restriction in the browsers, like described here https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified
do you think performance right now is somewhat expected given stage tech is at
or is it worth seeing if as mentioned there are perhaps some bottlenecks in the implementation?
The performance mostly should be good — at least, comparable or better than JS. Definitely, there is room for improvement, there could be issues in specific libraries. Feel free to report perf issues as well.
j

John O'Reilly

10/03/2023, 5:13 PM
I think I saw something about that before (timers) but then was wondering about https://code.benco.io/chip8/web/ ...they seem to perform very well....but could likely of course be using different approach
re. above on using ktor etc.....should there be a
org.jetbrains.kotlin:kotlin-stdlib-wasm:1.9.20-Beta2
version right now?
b

bashor

10/03/2023, 6:21 PM
I think I saw something about that before (timers) but then was wondering about https://code.benco.io/chip8/web/ ...they seem to perform very well....but could likely of course be using different approach
IDK, from first sight, I don’t feel a difference 🤷‍♂️
j

John O'Reilly

10/03/2023, 6:25 PM
should there be a
org.jetbrains.kotlin:kotlin-stdlib-wasm:1.9.20-Beta2
version right now
I see there's
1.9.20-dev-6845
version of that and a
1.9.20-Beta2
version of
kotlin-stdilib-wasm-js
I can try and setup a
resolutionStrategy
to handle those
b

bashor

10/03/2023, 6:26 PM
speaking about ktor it might be tricky, due to • new toolchain needs new stdlib (runtime), • new stdlib-wasm has some ABI changes and you may get linking error for libraries compiled against old stdlib
right, there should be
kotlin-stdilib-wasm-js
and
kotlin-stdilib-wasm-wasi
since 1.9.20-Beta
no
kotlin-stdilib-wasm
j

John O'Reilly

10/03/2023, 6:29 PM
it's ktor that seems to be looking for
kotlin-stdlib-wasm
Copy code
+--- io.ktor:ktor-client-core:2.3.3-wasm0
|    \--- io.ktor:ktor-client-core-wasm:2.3.3-wasm0
|         +--- org.jetbrains.kotlin:kotlin-stdlib-wasm:1.9.0 -> 1.9.20-Beta2 FAILED
|         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2-wasm0 -> 1.7.2-wasm1 (*)
b

bashor

10/03/2023, 6:31 PM
https://kotlinlang.slack.com/archives/CDFP59223/p1696348807259419?thread_ts=1696070166.178509&cid=CDFP59223 You can try to comment this part, after that you probably will need to add
maven("<https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev>")
to repos
j

John O'Reilly

10/03/2023, 6:32 PM
I have that repo here already
b

bashor

10/03/2023, 6:33 PM
better to try replacing
org.jetbrains.kotlin:kotlin-stdlib-wasm:1.9.0
with
org.jetbrains.kotlin:kotlin-stdlib-wasm-js:1.9.20-Beta2
j

John O'Reilly

10/03/2023, 6:36 PM
I'll try that now
ok, I think following worked (though probably cleaner way of doing it)
Copy code
resolutionStrategy {
    dependencySubstitution {
        substitute(module("org.jetbrains.kotlin:kotlin-stdlib-wasm:1.9.0"))
            .using(module("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:1.9.20-Beta2"))
    }

    eachDependency {
        if (requested.module.name.startsWith("kotlin-stdlib")) {
            useVersion("1.9.20-Beta2")
        }
    }
}
got a bit further but ended up with
Copy code
e: There are still 2 unbound symbols at the end of IR linkage process:
Unbound public symbol IrSimpleFunctionPublicSymbolImpl: org.w3c.dom/WebSocket.addEventListener|-5832680268725389244[0]
Unbound public symbol IrSimpleFunctionPublicSymbolImpl: org.w3c.dom/WebSocket.removeEventListener|3589491163511314858[0]
@John O'Reilly thanks for trying, we’ll let you know as soon as we publish a new version of ktor
👍 1
j

Justin Salér

10/03/2023, 10:17 PM
Using the same versions mentioned here:
Copy code
compose = "1.5.1-dev-wasm01"
compose-compiler = "1.5.2.1-Beta"
kotlin = "1.9.20-Beta2"
ksp = "1.9.20-Beta2-1.0.13"
serialization = "1.6.0-wasm0"
When running the task compileProductionExecutableKotlinWasmJs I get the error:
Copy code
Module "org.jetbrains.compose.ui:ui" has a reference to symbol kotlin/AllowDifferentMembersInActual.<init>|<init>(){}[0]. Neither the module itself nor its dependencies contain such declaration.
Anyone has any idea whether I am doing something wrong 😐?
b

bashor

10/04/2023, 7:18 PM
@Justin Salér the error sounds like there are incompatible versions of compose and stdlib
j

Justin Salér

10/05/2023, 12:54 PM
Thank you! @bashor. Seems like the issue was fixed by adding this code
Copy code
configurations.all {
    resolutionStrategy.eachDependency {
        if (requested.module.name.startsWith("kotlin-stdlib")) {
            useVersion(libs.versions.kotlin.get())
        }
    }
}
👍 1
j

John O'Reilly

10/13/2023, 3:08 PM
@bashor just in case there were updated version of Ktor libraries (I'm looking at https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental/io/ktor/ktor/ ....is that correct place to look?)
b

bashor

10/13/2023, 3:17 PM
@John O'Reilly yeah, it’s right place and you
3.0.0-wasm0
I just waited updates for compose before sharing it. But, actually, this version of ktor should work with well with library versions mentioned above.
j

John O'Reilly

10/13/2023, 3:18 PM
ah, sorry, I somehow missed that there was
3.0.0-wasm0
version now.....will try that
👍 1
Looking good so far
b

bashor

10/13/2023, 6:16 PM
👍 thanks for trying
2 Views