Does anyone know the target triple of wasmJs? is i...
# webassembly
c
Does anyone know the target triple of wasmJs? is it wasm32-unknown-unknown?
s
Are you referring to LLVM triple?
wasmJs
doesn’t have it because it doesn’t use LLVM.
c
It doesn’t? surely its lowered using llvm? or its a custom compiler backend?
s
It is a custom compiler backend that generates wasm directly. Binaryen is then used as a wasm->wasm post-processing optimizer pass. We used to have experimental LLVM-based Kotlin/Native
wasm32
target, but it is removed now.
c
interesting, do you happen to know why they opted for that route? I’d hazard a guess that it would allow them to experiment with certain proposals but llvm moves very fast itself?
s
(I’m one of those who started making the new backend) There were a few reasons: 1. Wasm GC proposal allows us to interact with JS and DOM GC. It is a built-in advanced GC, that allows us to make binary size smaller. 2. Wasm with a GC proposal is a higher level of abstraction compared to LLVM IR. It was unclear at the time if LLVM project would be OK with added complexity and support it (it still hasn’t). Even with LLVM support, we would likely need to generate a different version of LLVM IR for wasm. 3. We can acheive faster build times when targeting a single platform.
c
That makes a lot of sense thank you!
I was originally asking this because I had guessed we we’re using lllvm and the web target was empscripten. Is there any plans to bring c interop support to wasm? It would mean I could share more of my KMP project without having to write bespoke impls
s
No short-term plans due to priority in other areas. We see quite a bit of interest in reusing C libraries in Kotlin. Current solutions like JNI and Kotlin/Native C interop allow this, but are platform-specific. I, personally, would love to see some multi-platform solution (KT-39144) in the future. In the meantime, we want to have some form of C interop in Wasm. Some use cases will be covered when we support Component Model. It is unclear to me how good this approach will be in practice. If it works well in Wasm, I could imagine it becoming a multi-platform solution for foreign code sharing. If it doesn’t work, we’ll likely want some dedicated C interop solution (at least Wasm platform specific).