-
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];
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
-
I'm investigating v86 [1] 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 with a Lua compiler. 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]
[1] https://github.com/copy/v86
-
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/
-
Not trying to steal your thunder, but here is another nostdlib clang -> wasm example with malloc, a few math functions, rand, and writing to a canvas doing animation.
=> https://github.com/robrohan/wefx
-
These are also good resources on using wasm without dependencies:
https://depth-first.com/articles/2019/10/16/compiling-c-to-w...
https://github.com/diekmann/wasm-fizzbuzz
-
See also my example I put together some time ago: https://github.com/PetterS/clang-wasm
At the time, I could not find something like this online.
-
I made some emulators in Rust as a learning project during the start of the pandemic, and ran into the exact same issue when I wanted to make a wasm version to run in a browser. Eventually, I was able to figure out how to do it, although I do use the 'wasm-pack' Cargo package to assist with it (I think you can get away without it if you're really motivated, you just need to set up the targets and other elements yourself). Basically you define some Rust API to expose whatever you need from your project, then that and the project get compiled into one .wasm binary and some (surprisingly readable) JavaScript "glue" gets generated which allows for easy inclusion into a web page. It works well for code in the std, but I've had issues with 3rd party packages.
It's focused on emulation development, but I wrote a document that describes the process I followed: https://github.com/aquova/chip8-book/blob/master/src/wasm.md
-
-
llvm-project
This is the canonical git mirror of the LLVM subversion repository. The repository does not accept github pull requests at this moment. Please submit your patches at http://reviews.llvm.org. (by binji)
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.
-
Since I haven't seen it mentioned in the comments yet, here's another interesting project in the general area of "WASM without Emscripten":
https://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 the Emscripten SDK. It still needs some additional tools next to Clang, so it sits somewhere between "pure Clang" and "full Emscripten SDK".
-