Should I learn Rust for OSDev?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Timmy100
Posts: 13
Joined: Sun Apr 09, 2017 12:58 pm

Should I learn Rust for OSDev?

Post by Timmy100 »

Sup guys. Should I learn Rust for OSDev? Is it stable enough? Would it be good enough? Does it work on x86 architecture? Is it supported? Would it be good?

Cheers
Timmy
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Should I learn Rust for OSDev?

Post by iansjack »

It can be fun using languages other than C or assembler for os development, but - personally - I wouldn't recommend it for a beginner.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Should I learn Rust for OSDev?

Post by Korona »

Rust is a fine language for OS dev however I'd strongly recommend against learning a language and OS dev at the same time. Learn the language first and once you're proficient in it then start learning the OS dev basics. When learning low level stuff you will certainly have to read C and assembly code; it does not help if you have to translate this code into a language you're not familiar with.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Should I learn Rust for OSDev?

Post by dozniak »

Definitely.

See also https://robigalia.org
Learn to read.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Should I learn Rust for OSDev?

Post by OSwhatever »

It's been a while since the last post and Rust has matured a little bit more. I would like to ask this question again if anyone here has experience with Rust and OS development.

If you have experience with C/C++ vs Rust pro/cons it would be helpful. Since OS development is a little bit different from application programming how do you consider Rust being a viable alternative instead of C/C++ which today totally dominates this field. Is it good enough to use or is it too enough pain and restrictive?

Do you feel that you have to constantly resort to workarounds in Rust in in order to deal with the "walled garden" ie. making the compiler happy?
Do you have any idea what is happening under the hood. Since lifetimes are handled by the compiler, do you know where objects are actually deallocated. This might not be interesting in application programming but this might matter in OS development.
In OS development you usually end up with a range of different allocators for different purposes. Does Rust handle this easily? For example custom allocators are easy in C++ with placement new.
You constantl
isaacwoods
Member
Member
Posts: 47
Joined: Sun Sep 06, 2015 5:40 am

Re: Should I learn Rust for OSDev?

Post by isaacwoods »

I've been writing an OS in Rust (in conjunction with learning Rust, HOWEVER I already had experience with OS dev so the basic stuff wasn't difficult, and I could afford to concentrate on the language), and it's personally been quite pleasant. It's very different to writing an OS in C and a lot does feel "hidden", but as compiler development is my day-job I'm fairly aquainted with x86 assembly so figuring out what stuff is actually doing hasn't been that bad.
In OS development you usually end up with a range of different allocators for different purposes. Does Rust handle this easily?
This was a PITA before RFC 1974 but is now actually quite pleasant, although I think the actual allocator can only be changed on the crate-level.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Should I learn Rust for OSDev?

Post by Roman »

> Since lifetimes are handled by the compiler, do you know where objects are actually deallocated?

Yes, with Rust you're in full control of where objects are allocated. Rust is pretty similar to C++ in this case. The difference is in that Rust's compiler prevents memory corruption by tracking lifetimes.

> In OS development you usually end up with a range of different allocators for different purposes. Does Rust handle this easily? For example custom allocators are easy in C++ with placement new.

The standard library support for custom allocators is not yet stable. However, nothing prevents you from implementing your own containers that would support custom allocators.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Post Reply