DEV Community

white kotan
white kotan

Posted on

I Tried to Build a Local-First LeetCode with Rust and Failed

I recently had an idea to build an educational platform something like LeetCode, but open-source and with a different twist. My specific goal was to design and test a system that could handle multiple programming languages within the platform.

Since I was aiming for a "local-first" approach, using Docker containers wasn't an option. Not everyone has Docker installed, and frankly, not everyone knows what it is.

So, my choice fell on WebAssembly. It’s fast, compact, and allows for a pure browser-based frontend without the hassle of desktop setups. However, my knowledge of WASM was superficial at best. After a few minutes of brainstorming, I decided to use Rust for the backend core.

The task seemed straightforward:

Take Rust.

Take an interpreter for a language (I chose Python and the RustPython crate).

Run it using wasm-bindgen.

Accept user code from the frontend, throw it into the interpreter, get the result, and show it to the user. Everyone’s happy, right?

I dug into the documentation and examples. I built the interpreter and tested it as a standalone script-it ran perfectly. Then, I compiled it as a library (yes, Rust WASM targets need to be compiled as libraries).

The code worked, but it was stripped down. The Standard Library (stdlib) was disabled, following the guide I found. It wasn't immediately critical-I really just needed the print function, and I could have written a simple hacky workaround for that. But I got curious. It became important to me to understand how to do it right.

And that’s when the HELL began.

Instead of documentation on the official site, I saw this:. I couldn't find any clear explanations in the examples either; everyone was using vm::Interpreter::without_stdlib-essentially running it naked, without the standard library.

It was 6 AM. My brain was fried. I decided to try and get at least a messy result using AI. ChatGPT - terrible. Gemini - terrible. Claude - also terrible.

The last two tried to guide me through the "freeze" method, but that wasn't exactly what I needed. The worst part was dealing with dependencies-they were either hopelessly outdated or incompatible with each other.

In the end, I gave up on that approach.

But as I was finally going to sleep, it hit me: If a programming language can be packaged into WebAssembly, that means I can treat each language as a separated, isolated box that is simply called from the frontend when the user selects it.

The Conclusion: I wrestled with Rust, I wrestled with WebAssembly, and while I didn't get the result I expected, I now have a solid architectural concept in hand. I plan to code this new approach in the next few days.

Top comments (1)

Collapse
 
aniruddhaadak profile image
ANIRUDDHA ADAK

Bold effort!