I'm still kind of surprised that Linus ended up allowing Rust into the kernel. Good, but surprising.
Looking forward to this release once it hits NixOS Unstable.
I'm still kind of surprised that Linus ended up allowing Rust into the kernel. Good, but surprising.
Looking forward to this release once it hits NixOS Unstable.
Linus is pragmatic. His only hard rule is "don't break userspace", most everything else is contingent.
From what I can tell, he views Rust for Linux as a social project as much as a technical one - attract new (and younger) developers into the kernel, which has become pretty "senior", force all of the "unwritten rules" to be written down, and break down some of the knowledge siloing and fiefdom behavior that has taken place over the years (by sharing it specifically with that younger group of developers).
If you think about it, Rust for Linux is in some ways essentially an auditing committee reviewing all of the API interactions between kernel subsystems and forcing them to be properly defined and documented. Even if the Rust part were to fail (exceedingly unlikely at this point), it's a useful endeavour in those other respects.
But of course, if Rust is successful at encoding all of those rules using the type system, that unlocks a lot of value in the kernel too. Most of the kernel code is in drivers, and it's typically written by less experienced kernel developers while being harder to review by maintainers that don't have background on or access to the hardware. So if you can get drivers written in Rust with APIs that are harder to misuse, that takes a big load off the maintainers.
I just remember how much shit he talked about C++, and I guess I assumed that that would carry over to Rust as well.
From my memory of Linus's C++ comments, they basically boil down to "the kernel needs to do everything in freestanding mode, and everything that's interesting in C++ is not in freestanding mode, so what good is it?" (plus some ranting about "zero-cost" exception handling being rather more expensive than its name implies). In general, a strong vibe of someone who tried C++ in the early 90s, gave up on it then, and is generally ignorant of how C++ is different from back then.
If Linus's first introduction to C++ was to C++11, I'd imagine his opinion of C++ would be higher (probably not high enough to permit it into the kernel, though). To a large degree, Rust is "take the good new parts of C++11, strip out some of the legacy insanity, and let's also work out how to keep as much of the good stuff in a freestanding environment as possible." Which answers a lot of the objections that Linus had to C++!
That's also in line with my memory of it.
We still don't have all of the interesting C++ features in freestanding mode. It's still a fairly unknown component of libc++ and libstdc++. I've only been playing with it recently because I was curious about how many of the c++17 and newer compile time features I could get to work in avr-g++.
And the answer is ... not much.
I've been spoiled by Rust's "core" crate.
There was also the epic quote about how keeping out all the C++ programmers was enough of a reason.
Which is funny, because you can see the truth to it. With C++ comes endless debates. No technical reason really, but a social one, and so far the Rust culture seems to be closer to C in that regard.
As someone that started with C++ on MS-DOS, back when 640 KB would be enough for everyone, there is plenty of stuff in C++, making it better than C even in kernel space.
That is why contrary to Linus opinion, Symbian, IBM z and IBM i, Windows (since Vista), GenodeOS, and OS X, have C++ running on their kernels even if it isn't the full blown language.
Additionally many of his criticism against C++, applies equally well to Rust, in terms of language complexity, just wait until some kernel driver go crazy with macros or FP inspired designs.
What is indeed a plus for Rust is the secure code mentality that both C and C++ communities have kept downplaying until companies and government had enough with burning money fixing exploits.
True, but the Rust language itself is tiny compared to C++. There are only a slim fraction of the edge cases to learn.
Note that I'm not saying Rust is easy to learn. I found it to be so, but it's going to be different for everyone. I do firmly believe that it's far easier for the average dev to learn the core of Rust than the core of C++, with far fewer footguns along that path.
Oh I don't disagree with any of that, I like Rust. I was just surprised is all.
C++ was also tiny 40 years ago, just give it 40 years as well with the current six months release cadence.
This problem is (so far) solved by the editions feature. Breaking changes can be made to the language without splitting the ecosystem (like python 2 vs 3).
https://doc.rust-lang.org/edition-guide/editions/index.html
Rust has a 6 week release cycle and a big complaint is that the language isn’t changing quickly enough so there is pushback from both ends to take into account here. My take is that there are only hard problems still to be solved given that that they need to be solved in a zero cost way.
So has Linus straight up made it know this is where he would like things to head? Because it seems a lot of the resistance to Rust in the Linux kernel is coming from seasoned C developers who do not want to document these interfaces.
On that note seems like after ruckus about Hector Martin's PRs not getting merged, things are calm but progressing.
My understanding is its contained to the "edges", mostly in drivers and not in the "core" kernel.
Still interesting indeed.
It surprised me that Linux 6.12's QR code generator is written in Rust and enabled in at least Arch and Fedora.
Why does the kernel need a QR code generator?
https://www.phoronix.com/news/Linux-6.12-DRM-Panic-QR-Code
Oh that's pretty nifty. It's always been a pita to get data (logs, traces, metadata etc) off of a crashed system. This is less human readable, but any human that wants to read it will want the raw data anyway. Way easier to do this than try to run photos of a screen through OCR.
A QR code can capture 3k of data, you can capture a lot of context and details in that, particularly if you apply a little bit of compression (and the kernel has compression algorithms embedded in it). More than can be captured on a screen normally, without it zooming out of sight.
An 80x25 ascii display carries 2000 characters which isn't shabby. But yeah, a lot harder to photograph.
Would most people rather have a cell phone picture of the screen for debug logs, or a QR code that has those logs ready to be scanned and copy/pasted?
for now, due to gcc-rs not being completed yet and the rustc compiler not supporting every linux architecture
There's two gcc-based compilers for Rust, gcc-rs which is part of the gcc suite and written in C++, and rustc_codegen_gcc, which is an optional backend for the existing Rust compiler written in Rust which emits an intermediate representation that GCC can understand. rustc_codegen_gcc is much closer to completion.
It's an experiment. If it goes well, great. If it doesn't, revert back. What's the harm?
A surprise, to be sure, but a welcome one.
[dead]