-
Notifications
You must be signed in to change notification settings - Fork 5
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
Help with kotlin-js #28
Comments
IIRC you also need to provide the compiler the stdlib, e.g.:
|
@lppedd is right, |
This is the command that will work:
It's not mentioned anywhere and it's what made me rethink my life in the last hour (joking, almost), but |
I can't seem to find that kotlin-stdlib-wasm-js-2.0.0-Beta3.klib file anywhere... |
@ericvergnaud Maven Central is the quickest solution, or locally under Gradle's cached files. |
Aaahhh... I had to import it using:
|
That resolves the cmd line errors, that said, despite using full paths, it doesn't seem to be generating anything... |
@ericvergnaud try to use the same option positioning as mine. And you don't need -kotlin-home. |
I've also tried a first attempt but got the following exception: exception: kotlin.UninitializedPropertyAccessException: lateinit property jsFrontEndResult has not been initialized
at org.jetbrains.kotlin.ir.backend.js.ModulesStructure.getJsFrontEndResult(klib.kt:503)
at org.jetbrains.kotlin.ir.backend.js.KlibKt.preparePsi2Ir(klib.kt:380)
at org.jetbrains.kotlin.ir.backend.js.KlibKt.loadIr(klib.kt:199)
at org.jetbrains.kotlin.ir.backend.js.KlibKt.loadIr$default(klib.kt:178)
at org.jetbrains.kotlin.backend.wasm.CompilerKt.compileToLoweredIr(compiler.kt:61)
at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:356)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:181)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:72)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:104)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:48)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:79)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:43)
at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:180)
at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:173)
at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:167)
at org.jetbrains.kotlin.cli.common.CLITool.doMain(CLITool.kt)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.main(K2JSCompiler.java:101)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:87)
at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:44) I'm trying to figure out what the problem is. |
🫣 Sorry for that. It's really wasn't intended/designed to be used from CLI, so no shortcuts and no user documentation. |
It looks like a one-step compilation for K/Wasm is broken in K2. You can for compiler work as K1 like below and it should work: kotlinc-js -language-version 1.9 -Xir-produce-js -Xwasm -Xwasm-target=wasm-js -no-stdlib -libraries kotlin-stdlib-wasm-js-2.0.0-Beta3.klib -ir-output-dir out -ir-output-name=mymodule Simple.kt |
For K2 you need to do two steps: 1: Produce a klib for sourceskotlinc-js -Xwasm -Xwasm-target=wasm-js -Xir-produce-klib-dir -no-stdlib -libraries kotlin-stdlib-wasm-js-2.0.0-Beta3.klib -ir-output-name mymodule -ir-output-dir mymodule-klib -Xir-per-module-output-name=mymodule Simple.kt 2: Generate an executablekotlinc-js -Xwasm -Xwasm-target=wasm-js -Xir-produce-js -no-stdlib -libraries kotlin-stdlib-wasm-js-2.0.0-Beta3.klib -Xinclude=mymodule-klib -ir-output-dir out -ir-output-name=mymodule |
Thanks, it really works with
It also works on my side. |
Thanks @bashor ! Works here too ! The intermediate output is somewhat puzzling...: Notice there is no Also note that I had to specify full paths for After changing suffixes to .ts and a few tweaks, I was able to run the generated wasm in Deno (attaching the file that works for me): test-module.uninstantiated.ts.zip Leads me to a few questions:
|
What is
Might be OS specific bug, please file an issue.
What kind of tweaks?
No specific plan so far about CLI in general. Could you please provide more about your case.
Do you ask about Kotlin Multiplatform or Kotlin/Wasm specifically? Anyway, feel free to file an issue.
No plan for generating TS, but recently we added d.ts generation for exported declarations. It will be available in the upcoming
No specific plans for Deno support in Gradle plugin as we have for Node.js now, but if there is any issue with running generated code inside Deno we would happy to look into it. Please file an issue. BTW, we have adhoc Deno setup in https://github.com/Kotlin/kotlin-wasm-examples/tree/main/wasi-example |
Sorry I should have mentioned these are the names used for
Issue filed https://youtrack.jetbrains.com/issue/KT-65711/kotlinc-js-requires-absolute-paths-on-MacOS-X
Deno is able to run .js, but the generated files have an .mjs suffix. Deno related tools such as he WebStorm Deno plugin do not recognize .mjs as Deno files. Re weaks, they were required because the xxx.uninstantiated.mjs file detects Node, and in its absence falls back to browser, using
Seems I am not allowed to access this issue...
I'm asking about Kotlin/Wasm specifically.
The benefit is static typing. Noted re
This is not about the Gradle plugin, but about kotlinc-js. The generated code does not work with Deno.
Thanks. To your knowledge, does it work with 2.0.0-Beta4 ? |
For tracking purpose, working cmd lines are:
followed by:
|
Hi @KvanTTT @bashor
I'm experimenting with Kotlin/Wasm and facing an issue you might be able to help with...
I've downloaded kotlinc 2.0.0-Beta3, and
kotlinc-js -version
shows the correct version.When I run:
kotlinc-js src/main/kotlin/Test.kt -Xwasm -Xwasm-target=wasm -ir-output-name test.js -ir-output-dir out/wasm -kotlin-home /Users/ericvergnaud/Development/kotlinc
I get:
exception: java.lang.IllegalStateException: Class not found: kotlin/Float
How do I tell kotlin-js where to find builtins (I thought -kotlin-home was about that) ?
Btw where are they actually located ?
The text was updated successfully, but these errors were encountered: