Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan for WASM/JS? #211

Closed
Its-Kenta opened this issue Feb 15, 2023 · 5 comments · Fixed by #216
Closed

Plan for WASM/JS? #211

Its-Kenta opened this issue Feb 15, 2023 · 5 comments · Fixed by #216

Comments

@Its-Kenta
Copy link

1.8.20-Beta introduces the new WASM backend. I've been playing around with it lately and it provides some great compilation speeds and provides easier interoperability with JS, faster application startup compared to Kotlin/JS and JavaScript and Improved application runtime performance compared to Kotlin/JS and JavaScript

Of course it will possibly be released in Kotlin 2.0, but would there be any consideration to move towards using it?

@LeHaine
Copy link
Member

LeHaine commented Feb 15, 2023

Definitely. Would be great to get it added. I haven't looked much into it or how much heavy lifting it will be but it is definitely worth trying to get working.

@Its-Kenta
Copy link
Author

Its-Kenta commented Feb 15, 2023

Surprisingly there isn't much that needs to be changed. You would need to change jsMain to wasmMain:
https://kotlinlang.org/docs/whatsnew-eap.html#new-kotlin-wasm-target

It also supports webpack for test runs:

kotlin {
    @OptIn(org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl::class)
    wasm {
        compilations.all {
            kotlinOptions {
                freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
            }
        }
        binaries.executable()
        browser {
            commonWebpackConfig {
                devServer = (devServer ?: org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.DevServer()).copy(
                    open = mapOf(
                        "app" to mapOf(
                            "name" to "microsoft-edge", // "edge" 
                            "arguments" to listOf("--js-flags=--experimental-wasm-gc")
                        )
                    ),
                )
            }
        }
    }

    sourceSets {
        val wasmMain by getting
    }
}

"name" to "microsoft-edge", // "edge" <-- this requires to be changed by user to determine what browser they want to use, but it has to be one that supports WASM GC experimental. (so chrome/edge beta or firefox that allows it) But also
"arguments" to listOf("--js-flags=--experimental-wasm-gc") need to be modified based on the browser.

and you can call JS interop e.g. webgl just as you do with JS right now.

import org.khronos.webgl.ArrayBufferView
import org.khronos.webgl.WebGLObject
import org.khronos.webgl.WebGLRenderingContext

external class WebGLVertexArrayObject : WebGLObject
external class WebGLTransformFeedback : WebGLObject
external class WebGLActiveInfo

@LeHaine
Copy link
Member

LeHaine commented Feb 16, 2023

Awesome! Thanks for the example. I'll give it a whirl at some point hopefully in the coming days.

@Its-Kenta
Copy link
Author

Is there any update on moving from Kotlin/JS to Kotlin/WASM so far?

@LeHaine LeHaine linked a pull request Oct 2, 2023 that will close this issue
@LeHaine
Copy link
Member

LeHaine commented Oct 2, 2023

Is there any update on moving from Kotlin/JS to Kotlin/WASM so far?

Hello,

The changes are in progress and should hopefully have it done within the next few days when I get a bit more time. I've linked the in-progress pull request to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants