News for hackers. Stuff that matters.
Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by hobo_mark on Monday April 11, 2022 @01:12PM (#30991853)
That is half of what I would need for a project, the other half being Clang itself running in the browser (to use for teaching). In theory there is [1] since many years, but in practice it never worked for me (even now I get "Runtime error: memory access out of bounds").

[1] https://tbfleming.github.io/cib/

Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by bialpio on Monday April 11, 2022 @06:26PM (#30995901)
This was a topic at CppCon'19 (seems like exactly the same use case as you are describing: teaching!). Take a look at https://www.youtube.com/watch?v=5N4b-rU-OAA. I think it relies on the LLVM fork, so not sure how well it'll work for you, quick web search points to: https://github.com/binji/llvm-project.
Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by jansommer on Tuesday April 12, 2022 @07:51AM (#31001326)
I'm investigating v86 [1] (x86-compatible CPU and hardware emulator in JS) to get a c compiler in the browser. There's an example with a 5.5 mb Build Root Linux example [2] where you can pass files and commands between the browser and vm. The vm boots within a few seconds in Firefox on my Pixel 2 XL. There's also an example where Lua code is passed from the host, but you have to download the GitHub repo to see it [3]

It likely isn't suited for compiling big c programs, but I think one can get far with preparing a few shared libraries and Tiny C Compiler or similar.

[1] https://github.com/copy/v86

[2] https://copy.sh/v86/?profile=buildroot

[3] https://github.com/copy/v86/blob/master/examples/lua.html

Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by mbrock on Monday April 11, 2022 @01:25PM (#30992029)
It’s not ready just yet but if you’re curious about Zig they’re going to have a nice self-hosted WebAssembly toolchain soon, with no LLVM dependency. I’m really looking forward to it and I’m happy to see the Zig compiler work making lots of progress these days. I hope I’ll be able to start playing with this in a couple of weeks or so.
Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by hobo_mark on Monday April 11, 2022 @01:41PM (#30992225)
I was quite excited about `zig cc (although I understand why they would want to throw LLVM away), but despite what the crab people shout all day I still need C++.
Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by randomsilence on Monday April 11, 2022 @01:42PM (#30992242)
Do you know https://webassembly-studio.kamenokosoft.com/ ?

I don't know if it compiles in the browser or on a server.

Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by hobo_mark on Monday April 11, 2022 @01:48PM (#30992311)
That's fast! But it looks like it still needs a server, and I'd rather avoid giving the internet arbitrary code execution rights to some server I pay for and risk having my bill explode or my account terminated for abuse.
Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by randomsilence on Monday April 11, 2022 @02:15PM (#30992592)
Choose a supplier with a 100Mbit limit and unlimited bandwidth.
Re:Show HN: How to compile C/C++ for WASM, pure Clang, no li... by hobo_mark on Monday April 11, 2022 @02:25PM (#30992692)
I'm way more worried about ending up hosting miners or other malicious crap, Godbolt himself said users have found all sorts of ways to escape the compiler explorer sandbox over the years. I'd rather serve the compiler as a static blob that runs in the browser.