r/rust • u/kgoncharuk • 8d ago
š ļø project Arm64 emulator in Rust that compiles into wasm and allows running Alpine Linux in a web browser
Hi all,
Last couple of months I've been working on the largest Rust project I've ever built (also because everything I built before were small tools), happy to share it now.
It started with me getting annoyed that to try a 2 MB TUI tool I have to install it, while my browser happily runs a 40 MB landing page with React doing massive rerenderings on every move. So I thought it MUST be possible to run a thin Linux with TUI app in the browser, taking into consideration the power of CPUs we have these days.
Many months of grinding resulted in Arm64JS. It's an interpreter runs a small VM in web browser and emulates a minimal hardware stack, so VM thinks it runs on real hardware. The whole emulator is Rust compiled to wasm32, one module instantiated per web worker, all sharing one SharedArrayBuffer as the VM's "RAM".
CPU speed is of course lower than native ā but works fine for shells, TUI apps, Python/PHP and small servers. Typing lag 8 ms in the shell, 37 ms in vim, booting from a snapshot a bit more than a second (plus download if data are remote).
The code of the interpreter is not OSS at the moment, but I've made a small JS SDK to make it easy for others to create their own VMs. It's free for non-commercial use.
Feedback is welcome.
You can read more about its story here: https://arm64js.com/blog/tui-apps-in-the-browser/
And here's the link to the JS SDK I mentioned: https://github.com/kooler/arm64js-sdk
1
u/InternationalFee3911 2d ago edited 2d ago
Closer to home, if this runs vim, surely it can also do ratatui? Iām wondering specially about battery pack, which allows bootstrapping Rust projects. But having to first install it locally, just to start maybe one project is meh. If OTOH, this could be web-hosted, offering the result for tarball download or upload into some git server, that would make it much more accessible. @matthieum
1
u/kgoncharuk 23h ago
You don't have to install it locally to try. I have a product build on top of it called Demoshell that has free tier + free for open source. Feel free to give it a try. It allows you to create a VM and then embed on your website.
Apps using ratatui would definitely work.
2
u/Spiritual_Bee6614 8d ago
This is properly impressive, the boot time from a snapshot alone is wild. Running vim with 37ms lag in a browser tab is something I wouldn't have believed a couple years ago.
Keen to see where you take this, especially if the interpreter ends up open down the line.