r/gleamlang • u/xSpiralNightsx • 6h ago
Gekko: A Gleam to WASM Compiler Using MoonBit
github.comHi everyone. I have been working on a side project, gekko, that I wanted to share.
Notice:
This project is not affiliated with the official Gleam team or project.
This is an experimental, vibe-coded project. It is not yet suitable for production.
I came across Gleam language some time ago and think it's a really pleasant language to use. I wanted to find a way to run it as WebAssembly. While researching, I came across the MoonBit language, which supports WebAssembly but is less ergonomic than Gleam. However, it seems to have many of the same features of Gleam, so I tried to make a path from Gleam -> MoonBit -> WASM. Admittedly, I know nothing about language or compiler design, so this may indeed be a terrible idea, but I tried it anyway.
Gekko compiles Gleam to WASM using MoonBit as an intermediary. Some features & callouts are:
- Via MoonBit, can compile to WASM, WASM-GC, Native, and (MoonBit optimized) JS
- Supports FFI for MoonBit functions; Externals are referenced via pragma comments, so the official Gleam LSP doesn't show them as errors when reading them
- Helper commands to auto-generate Gleam stubs for MoonBit native functions
- Supports WIT & WebAssembly modules
- Supports pure Gleam packages; the gleam_stdlib and gleam_json packages were also forked to provide support for basic apps
- Follows MoonBit semantics rather Erlang (e.g. large integer addition)
- AI optimized performance (i.e. unoptimized)
I would love to get your thoughts on the project. Here's a link to some examples to show the features: https://github.com/spiral-nights/gekko_examples