6 ms·
I'm pretty sure it will be totally optional to write drivers in Rust, rather than C.
by karmanyaahm 5y ago
I'm pretty sure it will be totally optional to write drivers in Rust, rather than C.
- megous 5y agoI just really hope this thing will not be a bitch to cross-compile. I'm not interested in building llvm + rust in addition to my 5 or so gcc cross-compilers, especially looking at the cadence of rust releases. So as long as it will be possible to use the system's llvm+rust to build for all 4 CPU archs (at once) I'm currently building my kernels for, I'll probably not be too cranky about rust in the kernel.
- b20000 5y agowhat if your driver or user space app is affected by a poorly architected driver which was written in rust? now you need to deal with that rust source code. a true nightmare.
- dagmx 5y agoWhy would that be worse than if it was written in C? A rust codebase would be much easier to find the bugs in and refactor accordingly, than in C. Plus it's not like most people are going to dive into driver code without experience in the driver itself. So it's a niche set of folks this would affect, the majority of whom would likely be writing the rust code anyway since they're likely the ones most familiar with the driver aspects.
- kbenson 5y agoPeople have said the same thing about every language. I'm positive people complained about using C over assembly (people still do for certain things). I ask you to imagine a situation where a kernel is written in assembly, and they decide to start allowing C to be used for drivers. How would you view a change such as that?
- edgyquant 5y agoThere’s a huge difference. Rust syntax is a lot more complex than C, while this isn’t true for C v assembly.
- kbenson 5y agoThe semantics of C and how to write code that is well defined is much more complex than assembly.
- formerly_proven 5y agoC is easy to read and follow though. Rust has far more syntax and as a language is way beyond the complexity of C.
- nicoburns 5y agoOnly if you know C but not Rust. I personally find Rust fairly easy to follow and C a complete nightmare (the details in C are ok, but it's really hard to see the forest for the trees).
- edgyquant 5y agoI know C and can get by in Rust and I disagree that rust is easier to follow. C is a simple language, the complexity comes from large systems, while Rust is just not.
- nicoburns 5y agoWell I know Rust and I can get by in C. Perhaps that makes a difference. > C is a simple language, the complexity comes from large systems, while Rust is just not. I mean I agree that C is simple if you're making a 50 line program that writes to stdout or something. But more often than not with C or Rust you are working with a large complex system. And I'd argue that when working with such a large system, Rust programs are less complex than C programs.
- duped 5y agoCross compiling with Rust is actually not that bad.
- floatboth 5y agoLLVM is always inherently a "cross-compiler". In fact having to have "5 or so compilers" is just GCC being stupid.
- megous 5y agoGood. :)
- kelnos 5y agoCross-compilation with Rust is fairly trivial; it's just a matter of "rustup target add some-host-triple". GCC's cross-compilation story is indeed a nightmare. I expect if you have to use the GCC Rust backend (after it's ready) for arches rustc/LLVM don't support, you'll have that pain, but I expect it will just be a matter of adding an "--enable-language rust" to the GCC configure script run, similar to adding C++, ObjC, etc. to a GCC build. So the cross-compiler build will take longer, but won't involve extra steps or infrastructure.
- megous 5y agoBinutils/gcc cross-compiler can be built rather quickly, once you know the right configure flags for each. Then it's just make && make install. You can speed the buil considerably by building with -g0 and not doing a bootrstrap or building needless targets. Then you have a cross-compiler in some --prefix that you can point the kernel build system to via some environment variables and you're done. It's a well known process. It's basically built just like any other dependency and doesn't take much time. Hardly a nightmare. If it would be possible to just add rust to the list of gcc languages, that would indeed be very easy.
- lambda 5y agoCross compilation is actually much easier with Rust than it is with gcc. Every Rust compiler is a cross-compiler for all architectures that Rust supports; all you need is the rest of the toolchain like linker and libraries. rustup handles installing the libraries, and as lld (the LLVM linker) adds support for more platforms it can also be used as a cross linker, rather than a linker per target as in the older toolchains.