hello! i followed the getting started guide to use...
# webassembly
s
hello! i followed the getting started guide to use kotlin/wasm in intellij and it worked great, but i want to figure out how to compile kotlin to wasm directly on the command line, similar to `kotlinc`; i installed kotlin via homebrew on my mac and tried looking for a kotlin/wasm cli tool in
/opt/homebrew/bin/kotlin*
but these were the only ones i saw: •
kotlin
kotlin-dce-js
kotlinc
kotlinc-js
kotlinc-jvm
and when i run
kotlinc-js -help
i don't see anything about wasm, so i'm guessing that isn't the right tool; anyways, is there a way i can do this?
s
Hello! We don’t have a proper CLI for Wasm target yet. We have a human-unfriendly way to do this through
kotlinc-js
. I have found a script I made for a simple case. It runs CLI two times: compiling
.klib
and
.wasm
. Additionally you will need a stdlib library of the same version with path written to STDLIB variable.
Copy code
SRC=$1
OUT_DIR=$2
MODULE_NAME=$3
STDLIB=/path/to/kotlin-stdlib-wasm-js.klib

kotlinc-js -Xwasm -libraries $STDLIB -ir-output-dir=$OUT_DIR/klib -ir-output-name $MODULE_NAME -Xir-produce-klib-file $SRC
kotlinc-js -Xwasm -libraries $STDLIB -ir-output-dir=$OUT_DIR/wasm -ir-output-name $MODULE_NAME -Xir-produce-js -Xinclude=$OUT_DIR/klib/$MODULE_NAME.klib
kotlinc-js -X
would show help for all
-X…
flags that are missing from
-help
If you have a gradle build, you can run it with
--debug
and fish out the
kotlinc-js
arguments from the debug log to replicate it manually.
s
amazing, thank you! i'll try those both out