#mruby #embedded-scripting #vm #edge #ruby #bytecode #yet-another #edge-computing #mrb

mrubyedge

mruby/edge is yet another mruby that is specialized for running on WASM

53 releases (29 stable)

Uses new Rust 2024

new 1.1.8 Feb 21, 2026
1.0.20 Jan 31, 2026
1.0.15 Dec 30, 2025
1.0.5 Feb 23, 2025
0.1.3 Mar 27, 2024

#68 in WebAssembly

Download history 24/week @ 2025-12-04 12/week @ 2025-12-11 3/week @ 2026-01-08 28/week @ 2026-01-29 2/week @ 2026-02-05 14/week @ 2026-02-12 31/week @ 2026-02-19

75 downloads per month
Used in 8 crates

BSD-3-Clause

390KB
10K SLoC

mrubyedge

crates.io docs.rs

A pure-Rust reimplementation of the mruby VM that keeps its core execution engine no_std-friendly while striving for behavioral compatibility with upstream mruby.

Overview

mruby/edge is an mruby-compatible virtual machine implementation written in Rust, specifically designed for WebAssembly environments and embedded systems. It aims to provide:

  • WebAssembly-first design: Optimized for running Ruby code in browsers and edge computing environments
  • Lightweight runtime: Minimal footprint and binary size suitable for constrained environments
  • no_std core: Can run in environments without standard library support
  • mruby compatibility: Executes mruby bytecode (.mrb files) and Ruby source code
  • Rust safety: Built with Rust for memory safety and reliability

Installation

Add this to your Cargo.toml:

[dependencies]
mrubyedge = "1.0"

Usage

Running Precompiled Bytecode

Load and execute a precompiled *.mrb file produced by mrbc:

use mrubyedge::rite;
use mrubyedge::yamrb::vm;

// Bundle the compiled script at build time
const SCRIPT: &[u8] = include_bytes!("./examples/simple.mrb");

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut rite = rite::load(SCRIPT)?;
    let mut vm = vm::VM::open(&mut rite);
    let value = vm.run()?;
    println!("{:?}", value);
    Ok(())
}

Creating VMs Programmatically

You can also construct IREP (internal representation) structures directly:

use mrubyedge::yamrb::{op, vm, value::RSym};
use mrubyedge::rite::insn::{Fetched, OpCode};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let irep = vm::IREP {
        __id: 0,
        nlocals: 0,
        nregs: 7,
        rlen: 0,
        code: vec![
            op::Op { code: OpCode::LOADI_1, operand: Fetched::B(1), pos: 0, len: 2 },
            op::Op { code: OpCode::LOADI_2, operand: Fetched::B(2), pos: 2, len: 2 },
            op::Op { code: OpCode::ADD, operand: Fetched::B(1), pos: 4, len: 2 },
            op::Op { code: OpCode::STOP, operand: Fetched::Z, pos: 6, len: 1 },
        ],
        syms: vec![],
        pool: Vec::new(),
        reps: Vec::new(),
        catch_target_pos: Vec::new(),
    };

    let mut vm = vm::VM::new_by_raw_irep(irep);
    let value = vm.run()?;
    println!("{:?}", value);
    Ok(())
}

Use Cases

  • Embedded Systems: Run Ruby in resource-constrained devices
  • WebAssembly Applications: Deploy Ruby code in browsers and serverless environments
  • Edge Computing: Lightweight Ruby runtime for edge nodes
  • Rust Integration: Embed Ruby scripting in Rust applications

CLI Tool

For a command-line interface to compile and run Ruby scripts, see mrubyedge-cli.

Documentation

License

See the LICENSE file in the repository root.

Dependencies

~0.3–0.9MB
~15K SLoC