Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
31–40 of 44 posts
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#32https://github.com/aquova/chip8-book/blob/master/src/wasm.md
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#33Is there a similar example for C?
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#34That 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 libs, no framework
#35(Obligatory:) Neat! Still, a lot of copying bits around, and more JS than one might hope for. Could you send a pointer to canvas into the C code and operate on it in a direct, zero-copy way there?
https://stackoverflow.com/questions/42806037/modify-canvas-f...
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#36directly when reading this code I cannot help myself but to get into review-mode. It is an awesome example, which i will probably use myself one day. However... inc.cpp:27 Gray is not the average of RGB, it is usally approximated with `Y = 0.299 R + 0.587 G + 0.114 B`.
Also, you must work in linear colour space. In OP's case you would have to apply the inverse sRGB transform, do the calculation, then apply the forward sRGB transform. Best if you just work with linear colour end to end, if you have the memory to spare.
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#37This is really cool! I never looked into WASM before, I'm really happy to see it's not that difficult to build a simple example like this. One thing that's bothering me about that code is the declaration of `memory` as an uint8_t when it's clearly being used for its address: extern uint8_t memory; And then in a lot of places: uint8_t* ptr = &memory; ptr[FOO] = BAR; Declaring `memory` as an array is much more idiomati…
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#38https://github.com/schellingb/wajic
This provides an alternative implementation of Emscripten's EM_JS() magic (embed Javascript snippets right in the C/C++ source code), but without requiring a full Emscripten SDK installation. It still needs some additional tools next to Clang though, so it sits somewhere between "pure Clang" and "full Emscripten SDK".
Re: Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework
#39That 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/
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 libs, no framework
#40directly when reading this code I cannot help myself but to get into review-mode. It is an awesome example, which i will probably use myself one day. However... inc.cpp:27 Gray is not the average of RGB, it is usally approximated with `Y = 0.299 R + 0.587 G + 0.114 B`.
For future readers, this is the code that is being referred: https://github.com/ern0/howto-wasm-minimal/blob/master/inc.c... It should be: uint32_t gray = 0.299 * ptr[i] + 0.587 * ptr[i+1] + 0.114 * ptr[i+2]; ptr[i] = gray; ptr[i+1] = gray; ptr[i+2] = gray;