The initial use case for this came from Shopify – a commerce platform built on Ruby and the company sponsoring this work. Shopify is heavily investi

Using Wasmtime from Ruby

submited by
Style Pass
2023-01-24 19:00:11

The initial use case for this came from Shopify – a commerce platform built on Ruby and the company sponsoring this work. Shopify is heavily investing in making commerce extensible. Among other things, it uses WebAssembly to run untrusted code on the server. All that Wasm code must run fast and securely.

The goal of the gem is to allow exposing all of Wasmtime’s power with minimal overhead. The gem’s API should have a nice Ruby feel to it – we think it does! – but it intentionally does not introduce new abstractions or DSLs. These can be added by the community through new gems.

Why pick Rust? you may ask, knowing Ruby native extensions are normally written in C? That is a fair question, let’s dive into it.

First, Wasmtime’s Rust API is the canonical one. It is more expressive — thanks to Rust — and tends to get the features first. Closing the gap between Rust’s and C’s API would have increased the scope of work greatly.

Second, Rust is gaining in popularity in the Ruby community, increasing the pool of potential contributors. YJIT (Ruby’s latest JIT compiler) uses Rust and is now considered stable as of Ruby 3.2. RubyGems also added support for scaffolding Rust-based native extensions using the Magnus crate, which makes writing Rust-based Ruby native extensions a breeze.

Leave a Comment