using wasm islands as rich media
This is the glyph rain on my z-layer, a bare-metal Rust GPU shader under everything on my desktop. Here it’s not a recording or a port of the idea: it’s the same Rust shader, compiled to SPIR-V by rust-gpu, translated to WGSL, and running in your browser. If your browser can’t run WebGPU, or you asked it for less motion, you’re looking at a still frame the native renderer drew.
I wanted the blog to show pieces of projects where I’m writing about them, not link out to a demo.
the plain part stays
The site is static HTML, written in hypomnema. Every page ships with
script-src 'none'. It reads the same in any browser, it archives, and there’s nothing on it to inject into.
I’m not giving that up.
There was a halfway option: animate things with CSS and SVG, no scripts at all. It felt fake. If I’m showing a shader, I want the shader.
islands
So an island is the real thing, opted into one page at a time:
- The still is the page. The post’s folder holds a still frame, the module and the wasm. The still is what everyone gets first; the module upgrades it in place if the browser can run it.
- One page, one exception. That page gets its own
content security policy:
same-origin modules and WebAssembly, nothing else. Every other page stays at
script-src 'none'. - Scripts are refused everywhere else. The leak check that gates publishing fails on a
<script>in any page that hasn’t declared an island. - It fits the screen. A wide banner on desktop, a taller frame on a phone, and the canvas follows the frame.
proving it on every deploy
A policy that’s only right on my machine isn’t worth much. The site deploys with
edgepub, and every deploy is checked against the live site before it
counts: each page with its own header rule is fetched and must carry exactly its policy. This one must allow
the island; the rest must still say 'none'. If not, the previous version goes back up.
what it took
- The shader is one file, 237 lines of Rust. It gained a second entry point: on the desktop its parameters arrive as a Vulkan push constant, and WebGPU doesn’t have those, so in the browser the same 32 bytes are a uniform buffer.
- naga translated the SPIR-V to WGSL cleanly on the first try. 15 KB of SPIR-V became 22 KB of WGSL.
- The host is new: about 210 lines of Rust against WebGPU directly, no wgpu. The wasm is 218 KB (62 KB compressed), and that includes the glyph atlas, baked at 32 px instead of the desktop’s 128. The still is a 40 KB WebP.
- The leak check caught the first build. Rust release builds keep source paths for panic messages, and mine had my home directory in them. The build now remaps them and refuses to finish if any are left.
what’s next
The policy for each island page is still written by hand. Next, the publisher writes it from the island itself, and hypomnema’s preview enforces the same policy, so a mistake shows up while I’m writing instead of after a deploy.