Rust Simulations in Sphinx Docs#

Introduction#

In this post I’ll cover how I managed to get this blog post to display the simulation below.

The key points about this bit work are:

  1. The simulation is written in Rust (https://github.com/lukasturcani/rust-boids) and compiled to WASM.

  2. This blog is written in rST and compiled into HTML using Sphinx.

  3. Embedding the simulation in the blog post looks something like this:

This is my blog post, written in reStructuredText!

.. bevy-sim:: https://github.com/lukasturcani/rust-boids/releases/download/v0.0.6/rust-boids-wasm.tar.gz

This is the rest of the blog post!

So the key bit of work is writing a Sphinx extension which adds the bevy-sim directive. This directive will:

  1. Take a single argument, which is a a URL to a Bevy simulation compiled to WASM.

  2. Download and extract the WASM.

  3. Place a canvas element into the HTML document in which the WASM will be run.