How do I get wasm output from the CLI compiler? I'...
# webassembly
j
How do I get wasm output from the CLI compiler? I'm using the
kotlinc-js
binary with
-Xwasm
but still getting JS
k
Try "kotlinc-native hello.kt -target wasm32 -o hello"
j
Isn't that the old backend?
k
Yes, the old one. You want the new IR approach one?
j
yes. i'm poking around the Gradle plugin but it has so many abstractions i can't track down where it actually configures the JS IR compilation task
okay i got it
I added
-Xir-per-module
and
-Xir-produce-js
which I found via running a Gradle build with
--debug
. Very weird, but it produces what I expect now
Well, kinda. It's a start toward getting closer to what Gradle produces.
k
Can you paste the whole command with params to compile a kotlin file into wasm one? I also want to have a try.
j
kotlinc-js -output out/lib.js -Xir-produce-js -Xwasm -libraries kotlin-stdlib-wasm-1.7.20.klib input.kt
k
kylewong@KyleWongs-Work-MBP ir-wasm % kotlinc-js -output lib.js -Xir-produce-js -Xwasm -libraries kotlin-stdlib-wasm-1.7.20.klib input.kt exception: java.lang.IllegalArgumentException: Function getVirtualMethodId not found at org.jetbrains.kotlin.backend.wasm.WasmSymbols.getFunction(WasmSymbols.kt:294) at org.jetbrains.kotlin.backend.wasm.WasmSymbols.getInternalFunction(WasmSymbols.kt:305) at org.jetbrains.kotlin.backend.wasm.WasmSymbols.<init>(WasmSymbols.kt:173) at org.jetbrains.kotlin.backend.wasm.WasmBackendContext.<init>(WasmBackendContext.kt:105) at org.jetbrains.kotlin.backend.wasm.CompilerKt.compileToLoweredIr(compiler.kt:51) at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:345) at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:183) at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:72) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:94) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43) 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:179) at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit$default(CLITool.kt:177) at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:166) at org.jetbrains.kotlin.cli.common.CLITool.doMain(CLITool.kt) at org.jetbrains.kotlin.cli.js.K2JSCompiler.main(K2JSCompiler.java:100) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:87) at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:44)
@jw Did I miss something? I met error with the same command you used.
j
I'm not sure. If you build with Gradle and run with
--debug
you can see all the flags that it uses to invoke the JS compiler to produce WASM output. That's what I did.
s
@kang wang check that your path in
-libraries /path/to/kotlin-stdlib-wasm-1.7.20.klib
leads to an actual
kotlin-stdlib-wasm-1.7.20.klib
file
We should, obviously, include stdlib by default when we have a real CLI. Current CLI is not really meant to be used manually without Gradle.