Cheerp 3.0 has been up on HackerNews all day. It looks like it could be a good compiler target for Nim to web assembly without Emscripten.
Has anyone tried it with Nim?
the point is not which source language, but how to convert POSIX calls to WASM.
If I got it correctly here, there's no much difference between Emscripten and Cheers on this matter.
Well got the hello world working: https://github.com/elcritch/cheerp
@ElegantBeef -- I forgotten about that. Though oddly LLVM on macos doesn't support wasm outputs. Well at least last time I tried it. Does LLVM/Clang support the POSIX conversion too?
there is also a lack of multi-threading etc
That's preferred for my use case. I want to run user functions on an embedded device.. Though I think you can use web workers with WASM to provide multi-threading.
Ok, some last notes in case others are interested in it. Installing Cheerp was much quicker / easier than either brew install llvm or emscripten's setup.
It appears the Cheerp/clang++ works well with Nim output and strips any unneeded items. For a basic hello-world the .wasm output is only 88B, wow! The JS output is 1.3kb. IIRC, the default emscripten output was much larger.
The javascript integration is pretty nice, though Nim code doesn't work with the [[cheerp::genericjs]] style functions. On that side either use nim js or JS. The [[cheerp::exportjs]] annotations would probably work, but might be easier to manually wrap a C++ function over a Nim one.
Though you can do things like this too which:
{.emit: """
[[cheerp::genericjs]] void domOutput(const char* str)
{
client::console.log(str);
}
""".}
proc domOutput(msg: cstring) {.importc, header: "cheerp/clientlib.h".}
proc webMain() {.exportc.} =
domOutput("hello world!")
Here's an example config.nims that compiles a JS/WASM output.