r/osdev • u/Smart_Fennel_703 • Mar 27 '26
C or rust?
to the guys who made a kernel from scratch
what is the best choice for the future c kernel or rust kernel???
29
Upvotes
r/osdev • u/Smart_Fennel_703 • Mar 27 '26
to the guys who made a kernel from scratch
what is the best choice for the future c kernel or rust kernel???
11
u/Popular-Jury7272 Mar 28 '26
Use C if you want to learn C. Will never not be useful.
Use Rust if you want to learn Rust. Will become more and more useful in the future.
27
u/rafaelRiv15 Mar 27 '26
Anything you like. Kernel from scratch dev is a hobby
40
u/Gingrspacecadet Mar 27 '26
literally doesn't matter. also, everyone here has written kernels from scratch, that's what the subreddit is about.
21
u/Key_River7180 EulerOS Mar 27 '26
c
6
u/JescoInc Perdition-OS Mar 28 '26
There is no objective "best choice" for the future. However, are you talking about owning every aspect of the kernel with raw pointers to memory addresses or using dependencies via libraries / crates? Because that matters with the distinction.
If you are planning on owning every aspect of the kernel with raw pointers to memory addresses, that means if you use Rust, you will have unsafe Rust code which significantly diminishes the selling point of Rust.
I would say make the core kernel in C and then have an FFI bridge for the layer just before Userland where you can define safe abstractions and use Rust, thus preserving the selling point of Rust. That way, you not only get to use both languages, but also use them in a cooperative context where each language can shine.
Here's what this stack would look like:
6
u/Jontsgame Mar 28 '26
C if you want lot of tutorials and Rust if you want it easy I tested alot variations, and I must say for me... Assembly was the easiest one ._.
just joking C was the easiest one, then Rust.
11
u/Feeling-Drawer-9171 Mar 27 '26
c. now.
16
u/Flat-Guarantee-7946 Mar 27 '26
Perl. *Drops mic*
3
u/Critical-Internet946 zurich Mar 28 '26
use whichever one you know better
3
u/lieddersturme Mar 28 '26
Zig.
2
u/tas0dev Mar 28 '26
I think either is fine! Because, it's not like someone else should decide the language for you. Rust is working well for me right now, but that doesn't mean C is bad.
2
u/elijahjflowers Mar 28 '26
Assembly & Holy C
2
u/zarlo5899 Mar 31 '26
C#
4
u/Flagtailblue Mar 28 '26
Rust for fun C for reals.
1
u/avdolainen Mar 28 '26
C
1
u/HowardPlayzOfAdmin Mar 28 '26
I would use C and C++ because this is still best for compiling things in ARM64 and knowing the issues right away.
1
u/BornRoom257 TurtleOS Mar 28 '26
C
1
u/Felt389 Mar 28 '26
C
1
u/CtrlF0rge Mar 28 '26
Rust Personally, I work in rust and I think it's better because of the more convenient controls and workflow, but for starters it's better to use c kernel and the rest in rust because there's a lot of tinkering to do at the beginning.
1
u/Some_Useless_Person Mar 28 '26
I preferred Rust. Infact, if it's your first time, use crates as well. Be it the x86_64 or risc v one. It just gives you a really nice idea of everything to do without having to manually write hexadecimal magic numbers and making mistakes.
Then, you can try replacing all the crates with your own code. Like, implementing your own IDT struct instead of the x86_64 one and so on until eventually, it's entirely your handwritten code.
1
u/littleghost09 Monela Linux Mar 28 '26
Rust is harder but more secure. Most people here will say C, I say Rust but thats only because im a cybersecurity person.
1
u/loveinalderaanplaces Mar 28 '26
For what it's worth, there are ways to do kernel development in C# of all things, or even Java if you hate yourself enough. We're at a unique time in history where compilers have gotten so good that you can mostly just choose whatever sounds good.
Having said that: Use whichever you think you can tie to your target platform's assembly language more easily, and whichever you think helps you best understand your system at an intimate level.
I use C. I can't get past Rust's syntax, but I know that's a me problem. If you like Rust, use Rust. If you like Java, that's an "ew" from me, but if you're really good at it, it doesn't matter and you should disregard others' opinions.
1
u/[deleted] Mar 29 '26
I just made my own self-hosted language for my OS bootstrapping from rust when I thought of this question. I'll share it eventually.
1
u/[deleted] Mar 29 '26
I think that c will always be a major player in kernel development. Its fast, clean, and powerful. You just have to be a good programming and remember to free() your malloc() and realloc(). C also has alot more resources to get the job done.
1
u/Odd-Entertainer-6234 Mar 30 '26
Most people here have no clue about anything, probably have never touched a kernel maybe never even wrote anything in Rust. There’s going to be no functional difference for you between rust and C when writing the kernel. You will constantly write code in Rust using unsafe because guess what? The kernel has to run unsafe code. Both the C compiler and the rust compiler will constantly get in the way (but the C compiler is far easier to shut up).
Certainly, you will get some advantages from Rust in the long run but not in an enthusiast project. Even then, you can do the same thing in C.
1
u/Unable-Ambassador-16 Apr 01 '26
Zig
1
u/NoBrick2672 Apr 01 '26
html
1
u/ThunderChaser Apr 02 '26
It doesn’t really matter. I just use Rust because I love the language and my day job is as a Rust developer so I’m very familiar with the language.
Even if you decide to write a kernel in Rust, you’re still going to want to be very comfortable with C.
1
u/linux_transgirl Apr 04 '26
You can write in any language you want, it doesn't really matter outside of personal preference. Kernels have been written in compiled BASIC
1
u/No_Frame3855 Mar 28 '26
Rust is prefered afaik because it has strict types, memory-safe, and generally much easier to not have to spend hours debugging/dealing with use-after-free or similar bugs that are much easier to create in C (though it does depend on how you code, if you're careful about it, C is also usable).
1
u/FewBrief7059 Samsara | https://gitlab.com/clownkun/Samsara Mar 28 '26
i personally made a whole OS using rust but rust is good for people who want safe code . but in most cases it forces you to write in no_std which basically strips 80% of the ecosystem. making you forced to make your own everything basically. however by the time i started development using rust. C didn't have any osdev utils or tools as so like flanterm and etc . but as for now C because everything osdev related is built around it.
-1
u/FluxProgrammingLang Mar 28 '26
Flux!
3
u/[deleted] Mar 28 '26
[removed] — view removed comment
-12
u/[deleted] Mar 27 '26
[removed] — view removed comment