Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is that even possible as long as the Linux kernel is written in C? I wonder if telling people not to learn C will have a long-term effect on being able to find competent contributors to the kernel.



> Linux kernel is written in C

Not exclusively in C, not anymore: https://docs.kernel.org/rust/index.html

It might take another decade for a C-free build to be possible, though.


Only a decade? I don't think so.

AFAIK Torvalds has also stipulated that any Rust code needs to be mirrored in C.


This right here. Rust only JUST got added to the kernel in 6.0 and I doubt that it will replace 30 years of C development any time soon.


> AFAIK Torvalds has also stipulated that any Rust code needs to be mirrored in C.

Do you have a cite for this? I hadn't heard this at all.


Apologies, I can't find a source. I probably read it on LWN somewhere. Linus wouldn't dip both feet into the water at the same time. I'm confident he's said that the kernel needs to be buildable without Rust if need be.


> I'm confident he's said that the kernel needs to be buildable without Rust if need be.

FWIW that's not the same thing? That's simply CONFIG_RUST=n, not "You have to write this driver twice in two different languages".


Wow that sounds fantastically optimistic, or pessimistic depending on your point of view I guess.

Rewriting that amount of code in ten years sounds very very hard, at least.


A significant amount of the lines of code in the kernel are for drivers (7 of 12 million lines?).

A potential strategy would be to set a date where any new drivers must be written in Rust. Deprecate every non-Rust driver on a date after that. Focus on rewriting only the drivers necessary for current hardware platforms (and some sensible/arbitrary cut-off going back x years). Then set a final deadline for a New Linux kernel release that removes all deprecated/C drivers.

I would blindly estimate that entire process to take 10-20 years (not including the time needed for debating the whole thing).

Then somebody "just" needs to rewrite the rest of the code.

So, uh, any volunteers?


They said a C-free build. For that you'd need to "just" rewrite the core kernel, which will be 150-200k lines, and the drivers + arch specific parts for one system. Still a tall order, but a decade isn't unrealistic if Rust proves itself.

Now, rewriting everything, including all the legacy drivers? Yeah, never happening even if Rust succeeds utterly.


Once they get to that point, a new language will be available that makes up for the things Rust is still short on.


Maybe there's a case to be made for a multi-language kernel. Rust is the first step. Maybe it'll make sense at some point to keep Rust, but add another language.


I don't see such a feat taking place in the next decade, you need highly dedicated people. I can see new code being written in Rust but a C free build sounds like something that really won't be happening anytime soon.

I wish something like it could happen, but I am causyiously optimistic.


As long as there isn't a Rust compiler written in Rust (there is a transpiler to LLVM bytecode, but that gets compiled by a C++ compiler, same for GCC-rs) I don't think a C-free (or a C++-free) build will be possible at all, so I'm guessing it'll take somewhere in the 60-100 year range.


There are some open issues and features like inline assembly that aren't supported, but a moderately complete backend exists now:

https://github.com/bjorn3/rustc_codegen_cranelift

The compiler frontend is already written in Rust.


Honest question: what would the engineering rationale be behind dropping LLVM entirely and have rustc have its own code generation backend? There are two out there that might be interesting, one uses gcc and another is called cranelift, but it isn't the default and focuses exclusively on compilation speed for debug binaries.


Well people keep telling me that C/C++ code should be replaced by Rust for ~safety~ reasons, and LLVM is a C++ project, so...

Let's say it would avoid all the memory bugs in LLVM, that would doubtlessly make it worth throwing away the LLVM implementation (avoid sunk cost fallacy).


If anything, it's more likely that the desirable choice is to shift LLVM to Rust.


The Linux kernel comes with many old drivers that modern programmers have little knowledge about. It is probably more realistic to write a new kernel in rust (like Redox), targeting modern machines only.


By the time it's rewritten in Rust, old drivers will be dropped due to lack of demand for them.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: