Live data from Hacker News

Show HN: Compiling C in the browser using WebAssembly

wasmer.io

21–30 of 74 posts

Re: Show HN: Compiling C in the browser using WebAssembly

#21

Now all this needs is a simple OS running in a browser, that can edit and compile itself, post the resulting binary onto a WebDAV somewhere, and reload itself from there. Then it becomes a fully self-sustaining OS that can live forever in a browser.

Very interesting idea but I have to say that those goals are not possible with a simple OS, at least by OS definitions of simple :P

Re: Show HN: Compiling C in the browser using WebAssembly

#22

Couldn’t a tcc or similarly simple C compiler be used instead of a 100MB Clang? Where’s the C to wasm compiler hiding?

One issue with Wasm is you essentially can't target it with a single-pass compiler, unlike just about any real machine. Wasm can only represent reducible control flow, so you have to pass your control-flow graph through some variation of the Relooper[1,2]. I don't know if upstream tcc can do that (there are apparently some forks?..).

[1] http://troubles.md/why-do-we-need-the-relooper-algorithm-aga...

[2] https://medium.com/leaningtech/solving-the-structured-contro...

Re: Show HN: Compiling C in the browser using WebAssembly

#23

It's pretty misleading not to mention the performance overhead. That's an obvious downside and quite easy to benchmark. Skipping any discussion of performance feels like sweeping it under the marketing rug :/

> Skipping any discussion of performance feels like sweeping it under the marketing rug

Expecting performance while compiling C in the browser feels redundant right now though.

Re: Show HN: Compiling C in the browser using WebAssembly

#25

Now all this needs is a simple OS running in a browser, that can edit and compile itself, post the resulting binary onto a WebDAV somewhere, and reload itself from there. Then it becomes a fully self-sustaining OS that can live forever in a browser.

Very interesting idea but I have to say that those goals are not possible with a simple OS, at least by OS definitions of simple :P

The old https://webassembly.sh/ and the new https://wasmer.sh/ came a long way already.

All you need is a virtual filesystem of some sort, a way to download, a way to upload, an editor, a compiler, and a VT100 JS library. We already have WASI for the rest.

If the JS is too undesired, then perhaps go the old framebuffer graphics mode (e.g. a region of the WASM memory that is interpreted as an ASCII screen, or maybe even as a full bitmap buffer). Then JavaScript side just needs to forward keyboard/mouse into memory and that screen region out of memory.

Re: Show HN: Compiling C in the browser using WebAssembly

#27
Very cool! I've been watching the "toolchains in Wasm" landscape for a while, and seeing a Clang/LLVM toolchain running in Wasm is awesome!

YoWASP has also had an LLVM toolchain working in Wasm for a while too[1], although it seems like this version solves the subprocess problem by providing an implementation of `posix_spawn` whereas the YoWASP one uses some patches to avoid subprocesses altogether

My biggest question marks around this version are about runtime/platform support. As I understand it, this toolchain uses WASIX, which (AFAICT) works with Wasmer's own runtime and with a browser shim, but with none of the other runtimes. Are there plans to get WASIX more widely adopted across more runtimes, or to get WASIX caught up to the latest WASI standard (preview2)? Or maybe even better, bring the missing features from WASIX to mainline WASI like `posix_spawn`[2]? I'd love to be able to adopt this toolchain, but it doesn't seem like WASIX support has really caught on across the other runtimes

[1]: https://discourse.llvm.org/t/rfc-building-llvm-for-webassemb... [2]: https://github.com/WebAssembly/WASI/issues/414

Re: Show HN: Compiling C in the browser using WebAssembly

#28
post #3

Is it possible/already existing to have interactive C++ lessons where the user's C++ code is compiled an run client-side in a web page?

Absolutely! You can even run clang in wasm targeting x86_64, and then emulate the resulting program using the blink x86_64 emulator.

I'm working on something similar, where students can compile intel assembly and run it client-side: https://github.com/robalb/x86-64-playground

Re: Show HN: Compiling C in the browser using WebAssembly

#29

Couldn’t a tcc or similarly simple C compiler be used instead of a 100MB Clang? Where’s the C to wasm compiler hiding?

One issue with Wasm is you essentially can't target it with a single-pass compiler, unlike just about any real machine. Wasm can only represent reducible control flow, so you have to pass your control-flow graph through some variation of the Relooper[1,2]. I don't know if upstream tcc can do that (there are apparently some forks?..). [1] http://troubles.md/why-do-we-need-the-relooper-algorithm-aga... [2] https://medi…

> you essentially can't target it with a single-pass compiler,

That might be true if your source language has goto, but for other languages that start with structured control flow, it's possible to just carry the structure through and emit Wasm directly from the AST.

Re: Show HN: Compiling C in the browser using WebAssembly

#30

If what I want is not an executable but a shared library, does this get me anything? I currently have a use case that uses a server running an emscripten build (using SMODULARIZE and some exports, I suppose it’s not a true dylib)

Importing a wasm module from a wasm module is (non)surprisingly impossible to do -- you have to have a linker, abi and all that.
Post reply on HN