8 ms·
I like Rust and I'd love to see it in the Linux kernel, but not before the GCC+Rust issues are all fixed. You shouldn't need non-GCC compilers to compile Linux
by jeroenhd 4y ago
I like Rust and I'd love to see it in the Linux kernel, but not before the GCC+Rust issues are all fixed. You shouldn't need non-GCC compilers to compile Linux and from what I can tell there isn't any GCC Rust compiler that's fully equivalent to the standard Rust compiler just yet.
They say that Rust support is optional, but when the first big driver gets written in Rust it'll become mandatory. So either the Rust integration will fail and nothing important will get written in it, or it won't be optional. I'm not sure what comfort that's supposed to bring.
- selckin 4y agoOr that then gives people the motivation to work on gcc, have to solve the chicken-egg
- superkuh 4y agoYup. And if you have to use the rustc compiler that means you cannot use the rustc compiler from your repositories. Rust changes in forwards incompatible ways so fast that rustc is literally out of date and unable to compile new Rust code in less than 3 months. It's not because Rust is inherently bad, it's just that the type of people who write in rust are bleeding edge types (for now) and have no consideration for forwards compatibility. They just assume you'll curl | rustup.whatever and install a new version of rustc every month from a third party website like every single Rust guide suggests. That's not optimal for the linux kernel. But maybe kernel dev types won't be as bad as the typical bleeding edge rust dev. And given that rapid rate of change in Rust, I don't see how GCC can ever keep up. Maybe in 10 years when Rust is more stable.
- jcranmer 4y ago> Rust changes in forwards incompatible ways so fast that rustc is literally out of date and unable to compile new Rust code in less than 3 months. It's not because Rust is inherently bad, it's just that the type of people who write in rust are bleeding edge types (for now) and have no consideration for forwards compatibility. Funnily enough, I'm using the rustc compiler from Debian repositories (who of course is not well-known for eagerness to adopt bleeding-edge), and I've not run into any Rust code that wouldn't work with that compiler.
- superkuh 4y agoI installed Debian 11 before it was released officially. Its rustc was less than 3 months old. I personally ran into 2 rust programs I couldn't compile due to compiler forwards incompatibility within weeks. One example was the software defined radio program, plotsweep, if you want to look it up in cargo.
- nicoburns 4y agoThat's an application, not a library though. There's really no reason for an application not to require the latest compiler version if they so choose. There are definitely libraries that take this approach too, but they tend to be higher-level domain-specific ones. The foundational libraries in the ecosystem tend to take a much more conservative approach to MSRV (minimum supported rust version), supporting older Rust versions for as long as possible, and only bumping the version when new features that significantly improve the library are released (and often only once the versions implementing those features are packaged in stable releases of major distros). For example, the `rand` crate supports Rust versions down to 1.36 (released in July 2019) [0], the regex crate supports down to 1.41.1 (released Feb 2020) [1], etc. [0]: https://github.com/rust-random/rand#rust-version-requirements https://github.com/rust-random/rand#rust-version-requirement... [1]: https://github.com/rust-lang/regex#minimum-rust-version-policy https://github.com/rust-lang/regex#minimum-rust-version-poli...
- superkuh 4y agoYou're saying no true Scotsman will require the latest rust compiler. I'm saying that's not how it is for non-Rust developers trying to use things written in Rust.
- nicoburns 4y agoI'm saying the really core libraries (the only ones the linux kernel would ever consider using) don't suffer from this problem. If your development environment is permissive enough that you can pick up a wider variety of libraries, then I can't see any reason not to use the latest compiler.
- cmrdporcupine 4y agoAlternatively the sheer weight of the Linux kernel's influence means that the GCC implementation of Rust becomes the dominant one, altering the way people install and manage Rust. Rust is good, but I also do not like the trend in every language and/or build system having its own package management with its own third party dependencies and its own custom installers separate from the distro. I understand the pragmatic problems this solves, but I think it has serious ramifications for reproducibility, security, auditing, etc.
- ImprobableTruth 4y agoThe reproducibility story with system package managers is an absolute nightmare. In general, language package management systems, containerization and fully statically linked distributions (appimage, flatpak, snaps, etc.) are all a direct response to system package managers being woefully inadequate in all sorts of ways. And unless something like Nix takes over which actually allows reproducible builds, we'll continue to see alternative solutions continue to encroach on system package managers.
- cmrdporcupine 4y agoAbsolutely, I understand why these systems are there. And see the issue. The problem is the rapid propagation of them. There's too many, and they live outside the purvey of the distribution management, and often (... NPM, etc.) have poor auditing and moderation. I see why they happen. I don't blame the people to make them. I just think it's a potentially awkward situation when it comes to something as core as the kernel; which has traditionally only required GCC.
- jupp0r 4y agoRapid propagation? Fully statically linked binaries have been a thing for decades. The practice only got broken under most Linux distros when glibc decided to make it impossible to be linked against statically.
- SubjectToChange 4y ago
- jjice 4y ago> it's just that the type of people who write in rust are bleeding edge types (for now) and have no consideration for forwards compatibility. Feels like a pretty blanket statement. I'd assume that they'd base the minimum version on Rust's editions. An edition is released every 3 years and is meant to be a solid LTS (as far as I'm aware) version of the language. If they use Rust 2021 edition, you can tell the compiler that (like C89 vs C11) and it will reject code that's newer. C has plenty of newer stuff too that isn't allowed in kernel code at the moment as well.
- pornel 4y agoRust editions are nothing like C versions. They're orthogonal to language version. They're more like C trigraphs or -W flags. All new Rust features are available from all Rust editions. The 2015 edition has got new features 3 weeks ago, and will get more again in 3 weeks. Old Rust editions are only for backwards compatibility with old source code, e.g. to let it use names that became keywords later.
- Rusky 4y agoEditions aren't that clear-cut- crates targeting old editions can still use most new language features, and all new library features. For example, the NLL borrow checker was originally enabled in the 2018 edition, but it's now available in 2015 as well. Editions are more designed to manage backwards-incompatible changes, like new keywords or tweaks to corner cases in the type system.
- jeroenhd 4y agoRust has language versions and you can specify the language version to use in your Cargo.toml file. This is possible today and it shouldn't pose a problem for the kernel at all as long as there are rules about what versions to support. You don't need a super modern version of the spec to use Rust. As for Rust's incompatibilities, as long as you stay clear from methods marked unstable and the nightly compiler versions you'll be fine. Rust's libraries have breaking changes, but the stable language features haven't had any since the 1.0 release as far as I'm aware. If your problem is forwards compatibility, well, you can't use clang10 to compile the kernel either. Sometimes the version gets bumped, but it doesn't need to happen too often. I think GCC's rust compiler will keep up just fine.
- vips7L 4y agoHalf of the ecosystem depends on the nightly compiler.
- wongarsu 4y agoThat used to be true a couple years ago, but I don't think I've used a nightly compiler version at any point in the last 12 months. That said, I think for this first phase the kernel is planning on a specific stable version of the compiler with nightly features enabled, because they have a couple specific needs that haven't made it through the stabilization process yet.
- smolder 4y agoI dont't think "half" is accurate, at least not anymore. A lot of things have moved from Nightly to Stable compatibility with stabilization of async, for example. Rocket builds on stable now, while for a long time it didn't. I'd like to see the actual percentage but AFAIK it would take some analysis. Crates.io shows 86417 total crates, searching for "stable" shows 3346 and "nightly" shows 2527... So that's not a good heuristic, probably.
- rdsubhas 4y agoParent is saying the proportion is very high. It's not the exact number that matters. Even if one dependency your project uses needs nightly, then your entire project has to use nightly.
- noobermin 4y agoSympathetic, but isn't Linux like the poster child for demanding vendors and whoever maintain drivers and stuff without just leaving it working for months to years? Rust is just more bleeding edge than Linux then (which might be a substantial difference, I don't know).
- raxxorraxor 4y agoShouldn't we wait for Rust to be more stable then? I still fear that its restrictions are a bit of a fad. If it is included at one point you will hardly ever get rid of it again.
- bitwize 4y agoWe've known for some time now that the future would be written in Rust. If you do not have a Rust compiler in addition to a C compiler on your system, now is the time to consider installing one.
- kramerger 4y agoNope, everybody knows that the future will be coded in Jakt. Jokes aside, I bet Jakt (a completly new language) has introduced fewer language and compiler changes in the last 3 months than Rust (5-10 years old now?).
- Deukhoofd 4y agoJakt has introduced far more language and compiler changes in the last 3 months, don't be silly. Like the entire thing has been written in Rust first in the last 3 months, and then was rewritten in Jakt. Those are massive changes!
- jeroenhd 4y agoJakt still relies on Rust to compile the current standard of the language and the language spec is frozen until the Jakt compiler becomes self hosting. Even so, the spec is far from finished and the language will probably change weekly for weeks to come once the compiler has been finished. Rust's compatibility problems are quite irrelevant in my opinion. You can pin a language version and future compilers will still run your code as long as you don't use any explicitly unstable features (so no nightly compilers and no manually enabling unstable features). Yes, Rust moves faster compared to C's glacially slow language development, but almost every language does these days. Even C comes out with new versions every few years and C compiler versions get deprecated all the time.
- eterevsky 4y agoI don't see why Rust usage in the kernel should be blocked by GCC of all things. Of course kernel has been traditionally compiled by GCC, but there was never a ban on any additional or alternative tools. There is a number of dependencies on things like make, bison and so on.
- busterarm 4y agoYou would care if you were on one of the dozen or so CPU architectures that would suddenly become unsupported.
- unrealhoang 4y agoProbably the Rust code will be drivers for devices that are not compatible with non-rust supported architectures anyway.
- busterarm 4y agoAlso true, but there's a precedent for Rust developers & shipping their changes without regard for what's being deprecated. [1] [1]: like when PyPI cryptography first switched to Rust and broke ansible/openwrt/etc.
- ntoskrnl 4y agoThe Linux kernel takes backwards compatibility much more seriously than your typical Python package.
- guerrilla 4y agoOkay but think of it this way... maybe this is creating more demand for a GCC Rust compiler. Maybe it finally gives some people the excuse or funding to do what they need to do.
- humanwhosits 4y agoThis should really motivate the rust frontend for gcc though
- Tuna-Fish 4y agoThe initial work is just scaffolding that allows using Rust for some drivers, and projects intended to test said scaffolding. (Basically, rewrites of some drivers that are already in the kernel but that are not considered to be of the greatest of quality.) It will take quite a while yet before something important is made in Rust, and this early work can be done in parallel with the GCC-Rust work.
- Wowfunhappy 4y agoThere is talk of the Apple Silicon GPU driver being written in Rust, which I would say is non-trivial!
- Tuna-Fish 4y agoWow, I hadn't heard that. But ofc this doesn't limit platforms because the hardware is only available on ARM64.
- coldtea 4y ago>You shouldn't need non-GCC compilers to compile Linux Huh? What relationship the Linux kernel and GCC has? They're independent projects. It might be handy/nice/convenient to not need non-GCC compilers to compile Linux, but it's not like it's some license requirement or project obligation on behalf of Linux
- flohofwoe 4y agoIt should be rephrased to "Rust support in Linux shouldn't require two separate compiler toolchains", e.g. either the Rust toolchain can also compile the C parts, or the C toolchain can also compile the Rust parts (can Linux actually be built with a different C compiler than GCC yet? I thought it relies on specific GCC behaviour?)
- mauricioc 4y agoThis is not an equivalent rephrasing. Although I make some pragmatic compromises every now and then, I think the GNU mission is important, and historically Linux has been an important part of the GNU system. GCC's copyleft license is a big ideological advantage for me, and, although I like the option of using LLVM, I think being forced to use LLVM is a step backwards.
- monocasa 4y agoIt can be built with llvm too; there was a lot of work put into llvm to support gccisms.
- turbinerneiter 4y agoIt's a weird phrasing, but I agree on the compiler topic, maybe for other reasons: an important project like Linux should not really on a single compiler. I think it is good to have the ability to use either GCC or LLVM to build the kernel. That ensures that you don't accidentally rely on a compiler bug, no lock-in, ... . For C and C++ code you want to be able to build with different compilers. I think that also makes sense for Rust, the language and the compiler should be two separate things and there should be multiple compiler suppliers. Are there arguments why this would be less relevant for Rust than C?
- nindalf 4y agoThe GCC story isn’t that far behind - there are two complementary efforts to get GCC support into the Rust ecosystem. One is a Rust frontend to GCC (https://github.com/Rust-GCC/gccrs https://github.com/Rust-GCC/gccrs) while the other is a GCC backend to the existing Rust compiler (https://blog.antoyo.xyz/rustc_codegen_gcc-progress-report-12 https://blog.antoyo.xyz/rustc_codegen_gcc-progress-report-12). It might take a while for these to bear fruit, but it’ll be awesome when they do. That should address the very valid concern that the full Linux kernel won’t compile for all supported architectures. And it’s not really a problem that the GCC effort will take time. The headline of this article implies that the Rust integration is nearly done but it’s only the beginning. Based on the issue tracker there’s years of work left to get everything working perfectly. That’s enough time to get GCC supported well.
- arinlen 4y ago> It might take a while for these to bear fruit, (...) That's the problem. There are no GCC-based Rust compilers, nor is there a fixed timeline for one to be delivered, specially in the short term. Therefore, as the OP pointed out, as things stand either Rust in the Linux kernel is dead in the water or it poses a major problem for the Linux community.
- nindalf 4y agoI don’t know who this “Linux community” is that doesn’t include Linus or Greg or other senior developers that have been working with the Rust for Linux folks for more than a year. They don’t think it’s “dead in the water”. Let’s assume for a second that Linus knows what he’s doing. Now look at his mail from April 2021 on what he views as show stoppers (https://lkml.org/lkml/2021/4/14/1099 https://lkml.org/lkml/2021/4/14/1099) - OOM panics and 128-bit floating point. The former has been fixed now, which is why Linus appears bullish on adding Rust support to the kernel. Check that mail for the number of times Linus mentions GCC - 0. It’s not a priority for him. It’s easy to see why. He (and everyone else involved) are very clear that this will only be used for driver code on architectures that were already supported. So therefore, there is no need to supply a GCC compiler in the short term. I pointed out two long term efforts to get GCC Rust support. These could unblock more widespread use of Rust in the kernel, but that’s jumping the gun. Let’s see even one real driver merged before thinking about that. Whatever happens, the Linux developers won’t let the project break for millions of users overnight. That’s not how they operate. Your “Linux community” should know that.
- rjsw 4y agoIs there anything in the Linux kernel that can't be compiled with clang? There is plenty of experience with building BSD variants using it.
- steveklabnik 4y agoHistorically, the answer to that was "yeah totally." But folks have put a lot of work into getting clang to build the kernel, and IIRC Google has been building their Android kernels with clang for a few years now. ~~It's not~~ (see below) It wasn't supported directly by upstream, and in fact historically was pretty much the opposite: the intention was to not care about portability between compilers at all.
- jyxent 4y agoI think it is fully supported now: https://docs.kernel.org/kbuild/llvm.html https://docs.kernel.org/kbuild/llvm.html
- steveklabnik 4y agoThank you! That's more than I knew of. (I do think that what "support" means is kind of amusing, I would also say that this counts as support, but above you have people arguing that only Rust's Tier 1 support is called "support"...)
- ncmncm 4y agoIt's one thing to say developers have to add a new compiler front end for some drivers if they want to compile them; and, that some developers will just have to add it regardless. It is wholly another to say that they need adopt a whole different code-generation regime. It adds risk, and adds to what they need to understand to know what they are building. A pro needs to understand where problems come from, and be equipped to dig down to them. So, OK for hobbyists, but a burden for pros. It is the difference between "neat project, might succeed" and "mature". Rust stands a good chance of becoming mature in a few years, more than can be said about almost everything else.
- sophacles 4y ago> You shouldn't need non-GCC compilers to compile Linux Why?
- mkoubaa 4y agoDo you really need to fix ALL the gcc rust issues ? The Linux kernel could disallow rust features that are known not to work in gcc