Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

clang can compile into wasm pretty well via the

--target=wasm32

option. It creates small binaries. My 16-Bit x86 emulator with BIOS and DOS emulation is under 100kB [0].

[0] https://github.com/s-macke/FSHistory



And if you need parts of libc, you can use something like the below, for something more minimal than musl: https://github.com/Photosounder/MinQND-libc

Personally, although I do use wasi-sdk (clang) and the wasm32-unknown-wasi triple, the result can be basically free-standing, depending on what flags you use.

As a sibling post said, optimization matters, and using wasm-ctor-eval and wasm-opt also helps. But it's useful to keep full C semantics.


> Personally, although I do use wasi-sdk (clang) and the wasm32-unknown-wasi triple, the result can be basically free-standing, depending on what flags you use.

This is what I've been doing for my little non-WASI runtime. For my minimal programs I find only a few wasi exports are required, which don't appear to actually be used and I just stub them out. Would love to figure out how to get rid of the code depending on them entirely but it's lower priority.


If it's possible that it's stuff that's being used at initialization time, wasm-ctor-eval might help.

Also, you probably want to build a reactor (-mexec-model=reactor) if that's not what you're already doing. A command will use WASI to read command-line arguments and environment.

But it's hard to tell without knowing the specific imports you're trying to get rid of.


Thanks. This is awesome. For the emulator I wrote my own 200 line libc implementation with a five line malloc routine [0]. Nice to see another implementation, which does a little bit more.

[0] https://github.com/s-macke/FSHistory/tree/master/src/wasm_li...


That emulator is awesome. Especially cool about the easter egg.

I've seen a few of these WASM emulators and fantasy consoles, but they all seem to be focused on games. Are you aware of any that are designed to run normal GUI apps?


Maybe WebVM is something you are looking for [0].

[0] https://github.com/leaningtech/webvm


I tried for a few days to embed clang as a lib just to get it to compile to wasm and got so close and I might pick that project up again because I think it would be a really exciting and fun app.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: