Hi. Hope I can ask simple 101 questions here. I'm ...
# webassembly
e
Hi. Hope I can ask simple 101 questions here. I'm trying to run a simple "Hello, world!" that returns a string, but I'm facing some issues. I think I need to include
hello.wasm.js
, but I'd rather not, and I frankly don't know how
i
This is not Kotlin Wasm compiler you use (it's old deprecated experimental kotlin native mode). The better way to use Kotlin/Wasm compiler is to use example projects from here or/and follow the documentation
e
Ah thanks. I visited that page, but didn't see a quick way to build without Gradle. I simply didn't want to do that, but I'll give it a shot
Well, it runs Now I just need to try and understand what happened 😅
i
It is indeed difficult to run kotlin multiplatform project without gradle but gradle needed to tune many things up.
e
A bit of
--debug
to Gradle and grep gave me the actual node command
Here we go
Ok, now looking at that file, and comparing it to AssemblyScript's launcher, I suspect these do similar things. So I must ask, this is JetBrains implementation of a GC, right? And in the future, will all implementations of a GC be identical (given the proposal goes through) - meaning I could in theory compile a wasm from AssemblyScript, and run it with the command above (also replacing wasm file)
Ah and look at it go with a bit of hacking
e
what do you mean? Kotlin/WASM has been using the WASM-GC proposal from even before it was accepted as a standard (which it now is)
the old WASM native backend did ship its own GC but that is no longer used
e
I might be misunderstanding, but I would like to create a wasm file that is language agnostic. The JS file generated by Kotlin is Kotlin wasm specific. I compare it to AssemblyScript, because I know they also support GC. The launcher file from them, compared to that of Kotlin seems to do similar things, for interfacing the wasm module. But they are bound to their implementation. My main goal here is to run wasm files, in a sandbox. Users can provide the wasm file, but not the JS, as it is definitely not sandboxed. AssemblyScript solves this with a generic launcher, as I understand. What I want is a generic launcher thing that would be identical no matter where the wasm came from
e
it's not the GC that makes them incompatible. the launchers are a bit different because they require different setup, but mostly it's the lack of using the WASM component model that prevents you from using them in an interchangeable. that is under construction
https://github.com/WebAssembly/component-model was only stabilized as of this year and is still getting necessary additions
e
Aha thanks
I guess there is no way to compile with Kotlin using this, yet?
e
well it depends on what you mean. wasmJs I don't think so? but wasmWasi is using WASI which is already a component
e
I thought WASI was for other things, not controlling GC?
e
I'm not sure why you're even bringing up GC
Kotlin has two different WASM targets, wasmJs and wasmWasi. wasmJs is set up to interact with a DOM through a JS bridge, and includes a JS starter module to set up some of the things it needs from the host environment. wasmWasi has different expectations of its environment (and thus different things available to Kotlin code compiled for that target)
e
Trying out the WASI examples now. I really don't need to interact with the host, I only need to pass a string in, and get a string out. Or rather complex objects, but since the host don't know the types I'm thinking JSON would do for now. In that regard, shouldn't I see
notMain
listed as an export here?
i
Functions are not exported from a Wasm module by default, to do that you need to mark them with
@WasmExport
in WASI
You already now interacting with the host in your program, you are using
println
There is no built-in implementation for
string
in Wasm standard (should be solved with component model proposal)
e
So what I really need is the component model, and not WASI or GC? I imagined GC would have to solve strings in a common manner, but perhaps not, especially between host and guest
i
GC is a garbage collector, it does not have any connection with strings
e
I know, I just thought it would define their structure