# Rust's std porting, how much work would that represent?

**URL:** <https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809>\
**Category:** Uncategorized\
**Created:** [January 16, 2024, 12:47pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809 "2024-01-16T12:47:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![raskyld](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/raskyld/32/279_2.png) [@raskyld](https://sel4.discourse.group/u/raskyld)\
**Post date:** [January 16, 2024, 12:47pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/1 "2024-01-16T12:47:06Z")

</div>

> **How I ended up there**
>
> I’ve recently started learning about OSDev and seL4 is really appealing as a foundation on-top of which I could build things to learn about OSDev, seL4 and Rust ecosystem in general.
> 
> My long-term goals are to:
> 
> - contribute to seL4’s Rust landscape,
> - become a decent “OS Developer”,
> - PoC to see if seL4 could be used as the foundation of a next-gen OS specially-made for Servers and Infrastructure (disclaimer: I am working for an European CSP but my employer does not support my seL4 initiative, I do it out of business hours),
> - Porting [Wasmtime](https://wasmtime.dev) to this eventual OS based on seL4,
> - Eventually make a living of this work 🤞.

I am starting this thread just to have feedback from actually experienced (unlike me) Rust developers and seL4 professionals to see which approach could one take to port Rust’s std crate to their system based on seL4.

I think, it is premature to think about a one-size-fits-all approach as it’ll largely depends on the specific userland of one. But this thread is more about general ideas and approaches produced by the community to serve as reference for future works.

---

<div class="post-metadata">

**Author:** ![raskyld](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/raskyld/32/279_2.png) [@raskyld](https://sel4.discourse.group/u/raskyld)\
**Post date:** [January 16, 2024, 12:51pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/2 "2024-01-16T12:51:15Z")

</div>

I post this for reference:

> **[Refactoring std for ultimate portability](https://internals.rust-lang.org/t/refactoring-std-for-ultimate-portability/4301)**
>
> Rust is really super portable. It supports a lot of platforms. But not enough ... not nearly enough. Rust wants to be everywhere, in wild places that only future generations will be able to imagine. We've got some work yet to enable that future...

---

<div class="post-metadata">

**Author:** ![gerwin.klein](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/gerwin.klein/32/46_2.png) [@gerwin.klein](https://sel4.discourse.group/u/gerwin.klein)\
**Post date:** [January 18, 2024, 12:25am UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/3 "2024-01-18T00:25:04Z")

</div>

Porting std directly to seL4 makes only limited sense, because seL4 alone doesn’t provide a lot of the services that std assumes. That is, std assumes a roughly POSIX-ish OS underneath with file system and network etc, and seL4 is just a microkernel that you might build such an OS on top of, but it does not provide these services itself.

That said, I think there is direct std support for other microkernels, which is achieved by just returning “unsupported” for most of the std features (esp file system and network). One could always do that, but the question is how much one would gain compared to direct no\_std development on top of seL4 with the current no\_std crates that [seL4 provides](https://github.com/seL4/rust-sel4/).

Or, one could of course start building a dynamic OS personality on seL4 that supports what std assumes, but that is a bigger project.

---

<div class="post-metadata">

**Author:** ![raskyld](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/raskyld/32/279_2.png) [@raskyld](https://sel4.discourse.group/u/raskyld)\
**Post date:** [January 18, 2024, 8:59pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/4 "2024-01-18T20:59:57Z")

</div>

Yes, it’s what I assumed, it would probably be the responsibility of some higher-level layer to provide POSIX-ish like behaviour to ease porting efforts.

---

<div class="post-metadata">

**Author:** ![raskyld](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/raskyld/32/279_2.png) [@raskyld](https://sel4.discourse.group/u/raskyld)\
**Post date:** [January 18, 2024, 9:01pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/5 "2024-01-18T21:01:57Z")

</div>

Another project that could ease porting efforts would be [GitHub - bytecodealliance/cap-std: Capability-oriented version of the Rust standard library](https://github.com/bytecodealliance/cap-std) but I think it would still requires some higher-level abstraction.

---

<div class="post-metadata">

**Author:** ![nspin](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/nspin/32/77_2.png) [@nspin](https://sel4.discourse.group/u/nspin)\
**Post date:** [January 29, 2024, 9:00am UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/6 "2024-01-29T09:00:36Z")

</div>

First echoing @gerwin.klein’s comment, any `libstd` port with any features at all (as opposed to one consisting only of empty stubs) would be specific to a higher-level framework of OS personality sitting on top of the kernel, rather than the kernel itself.

However, while `#![no_std]` support in the Rust ecosystem is growing stronger every month, some crates like `wasmtime` are a long way from being `#![no_std]` compatible. For the [Veracruz project](https://github.com/veracruz-project/veracruz), we drafted an ad-hoc operating system personality, along with and accompanying `libstd` port, specifically to support `wasmtime`. The OS personality basically just provided `mmap()` and fault-based lazy page mapping.

For a bit of context, Veracruz is a framework for privacy-preserving collaborative compute using various backends for confidential compute primitives. The [IceCap hypervisor](https://gitlab.com/coliasgroup/icecap), which is based on seL4, was one such backend. I believe Veracruz has dropped support for IceCap, and this code I’m talking about never actually landed in Veracruz, but here are some links to old branches of various repositories to give you a sense of what was going on:

- [The PR that added support for `wasmtime` on IceCap (i.e. seL4)](https://github.com/veracruz-project/veracruz/pull/311)
- [A branch of `libstd` with IceCap (i.e. seL4) support](https://github.com/veracruz-project/icecap-rust) (mostly stubs)
- [A branch of `wasmtime` with IceCap (i.e. seL4) support](https://github.com/veracruz-project/wasmtime/tree/icecap)

Let me know if there are any aspects of all of this that you’d like to expand on.

---

<div class="post-metadata">

**Author:** ![raskyld](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/raskyld/32/279_2.png) [@raskyld](https://sel4.discourse.group/u/raskyld)\
**Post date:** [January 29, 2024, 12:36pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/7 "2024-01-29T12:36:30Z")

</div>

Thanks a lot for these references !

It will surely help me. For now, I am focusing on getting low-level concepts right as I have mostly been involved in high-level projects.

I also read a lot of references to get inspiration and good ideas, then I would like to try producing a prototype OS personality (btw, I am not sure what is the exact meaning of OS Personality, is it an academic concept or is it strictly related to seL4 eco-system? My understanding is that it’s a specific userland running on seL4).

Also, since we speak about Wasmtime specifically I just wanted to share this link in the thread:

> **[Porting Wasmtime to no\_std atop Theseus | Theseus OS Blog](https://www.theseus-os.com/2022/06/21/wasmtime-complete-no_std-port.html)**
>
> Theseus OS Blog

---

<div class="post-metadata">

**Author:** ![nspin](https://yyz2.discourse-cdn.com/free1/user_avatar/sel4.discourse.group/nspin/32/77_2.png) [@nspin](https://sel4.discourse.group/u/nspin)\
**Post date:** [January 29, 2024, 1:01pm UTC](https://sel4.discourse.group/t/rusts-std-porting-how-much-work-would-that-represent/809/8 "2024-01-29T13:01:09Z")

</div>

> (btw, I am not sure what is the exact meaning of OS Personality, is it an academic concept or is it strictly related to seL4 eco-system? My understanding is that it’s a specific userland running on seL4)

By OS personality, I mean a subsystem that provides a userspace environment with elements of some familiar OS API. For example, in the case at hand, Veracruz is not a Unix-like system, but the component running Wasmtime is supervised by (i.e. managed by) a more privileged component which provides it with an OS API which includes `mmap()`. One could say that the more privileged component is, exposes, or provides an OS personality for the Wasmtime component.

(This phrase is not specific to the seL4 ecosystem)
