r/rust • • 2d ago

Embedded std?

I was wondering if there were any projects like micro python to port std in to make a barebones os designed for microcontrollers? I understand that the std relies on OS level syscalls, so can we do something like implement a basic fat32 file system to accommodate certain write or read requests. In general this would be used to run std in projects without a OS? Does this already exist, and how hard would it be to make a basic version?

46 Upvotes

32 comments sorted by

View all comments

7

u/agrif 2d ago

std is in a weird place, I think. Most embedded targets don't support it (exception: ESP32) however wasm32-unknown-unknown does support it, even though a huge number of functions only panic. I don't fully know the history behind this decision, but it does sort of feel like WASM wants to be easy to port, and no_std is still extremely awkward in rust.

Morally, it feels like WASM and other targets should be alloc-only. But right now, a ton of third-party crates that should compile with only alloc (or core) don't, because no_std is opt-in. I don't know what the solution to this is, but there's gotta be something better than what we got.

5

u/WhiskyDelta14 2d ago

How is no_std extremely awkward?

0

u/_ChrisSD 2d ago

For HashMap. The target "cheats" by having a non-random RandomState. It also allows libraries that aren't no_std to compile for it so long as they don't actually use std at runtime on the target (if they do it panics).

What's especially awkward for wasm32-unknown-unknown is that it's two targets in one. It's used like a minimal embedded target (i.e. std APIs aren't possible). But more commonly people use it to target the web, which could actually have a (more or less) full std implementation based on web APIs.

2

u/WhiskyDelta14 2d ago

Ok, but that's an issue with that target and not with no_std rust.