Skip to content

LyonSyonII/rubri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rubri - The Rust Browser Interpreter

See it in action.

Rubri is a proof-of-concept wrapper for Miri that runs in the browser.

This allows for extremely fast iterative development, as it avoids compiling the code, which is known to be slow even when done natively.

Execution speed is pretty slow though, probably worse than the 1000x Miri claims.
Output is especially demanding, a simple loop of 2000 prints takes between 2 and 3 seconds.

The project has been made possible thanks to the work of bjorn3 on Cranelift, compiling Miri to WASM and the Browser WASI shim.
All credits are for them, this is just a wrapper I wanted to make to see if Rust could really run in the browser.

Usage

See the index.astro file for an example on how Miri can be used from javascript.
This example has been made with Vite or Astro in mind, if you don't use any of them you can still run the code by removing the import.meta.env directives and adapting the fetch paths.

The public/wasm-rustc folder is needed, as it contains the compiled Miri and the necessary .rlib libraries.
You can build your own wasm-rustc files by following the instructions in this issue comment.

Limitations

All of them!

Seriously though, this is extremely experimental at the moment.
It doesn't support multiple files, using crates, input/output operations, etc.

Everything not supported by Miri or WASM is not supported by Rubri.

If you have any knowledge on how to improve this, feel free to open a PR!

How it works

rustc is tricky to compile to WASM because linkers are not supported.
Miri though does not need linking, so it can be used to interpret the mid-level intermediate representation Rust uses in its compiling process.

This wrapper loads Miri and the necessary libraries via a Web Worker and invokes it with the provided code.
To improve execution speed, Miri's code has been modified slightly and all checks are disabled (does not check for UB, only runs the code).

All the libraries are cached the first time they are downloaded, ensuring fast load times.

License

Licensed under MIT license (LICENSE or http:https://opensource.org/licenses/MIT).