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

sdeleuze

08/14/2022, 9:07 AM
Let say I want to build a Wasm library with Kotlin/Wasm
1.7.20-Beta
that "exports"
fun add(a: Int, b: Int): Int = a + b
. I don't care about JavaScript here, I just want to specify that the generated Wasm should be shipped with this function and everything else removed (tree shaking). I have no
main()
in my project. How should I specify that in my code and/or how my build configuration
kotlin { wasm { binaries.library() } }
should be customized? Is
@JsExport
the way to go for now?
s

Svyatoslav Kuzmich [JB]

08/17/2022, 2:19 PM
binaries.executable()
and
@JsExport
would be the way to go for now.
Note that JsExport of some non-primitive types currently requires autogenerated JS glue to function.
s

sdeleuze

08/18/2022, 5:49 PM
Ok thanks, in term of design I would be curious if you may target a
binaries.library()
+
@WasmExport
for that use case or if you have something else in mind. Other languages usually uses keyword instead of
@JsExport
/
@WasmExport
but maybe there is not enough use cases on other platforms to justify such keyword in Kotlin ...
93 Views