6 ms·
Writing an OS in Rust, Second Edition
- bb88 9y agoI've seen a series of these types of articles, and I'm not sure if they're trying to make the next linux or doing it for fun. One problem to me is drivers, drivers, drivers. Linux has a bunch of 'em. Other operating systems, not so much.
- gilnaa 9y agoI think the point of this is to teach how to write embedded / bare-metal software. I can't see how this can be seen as a real OS.
- Manishearth 9y agoThis particular series is more of a toy OS for learning purposes (and through which they can teach things). At least, that's my impression of it. Redox (https://github.com/redox-os/redox https://github.com/redox-os/redox) is a Rust OS project that's aiming to actually be a usable consumer OS.
- pjmlp 9y agoWe don't need a Linux mono-culture. First, people need to learn how to write OSes, even if that is all they do with it. Second, the only way to prove there are better ways to go beyond UNIX is to write other OSes, since many in IT only believe when seeing and sometimes not even when it is shown running on front of them.
- empath75 9y agoIf you’re targeting xen, you don’t need so many.
- 0xcde4c3db 9y agoEven targeting hardware, it's not as bad as people make it out to be, provided you scope platform support and features appropriately. For a lot of hardware you can get 80% of the utility with 20% of the code, and no new OS jumps out of the gate with version 1.0 supporting every device on the planet.
- nine_k 9y agoA compatibility layer for e.g. Linux drivers to run inside a new OS is not unthinkable. I remember Linux being able to use DOS drivers for NICs back in the day, or something similar.
- steveklabnik 9y agohttps://os.phil-opp.com/news/2018-03-09-pure-rust/ https://os.phil-opp.com/news/2018-03-09-pure-rust/ provides a lot more context here. I am extremely excited by this work. One of the hardest parts of hacking on a hobby OS is the environment. My own project has been hampered for nearly a year because I switched to Windows and couldn’t get the tooling working. (A combination of my lack of Windows knowledge and a lack of desire to spend random Saturdays figuring out obscure toolchain issues.) And that’s with rustc already being a cross compiler. This now means that, with Rust, getting going on any platform Rust supports is now trivial. It’s quite exciting.
- xvilka 9y agoWindows in general is not developer-friendly environment. While it provides great experience for usual user, it seriously lacks the inner beauty of any *nix system, which is itself a developer environment as a whole.
- jwdunne 9y agoI found this. I use a Mac at work but I've got a laptop with Windows on it. My first instinct was to partition and whack on a Linux distribution. But I chose to just leave it alone. I don't want to enamour my Mrs with a bootloader again. Despite the simplicity, the typical UI for a bootloader intimidates non-techies. So I tried writing some code on Windows, using PowerShell as a terminal. How hard could it be? I've done it before. Well, PowerShell is a big leap over CMD. But it just wasn't unix. I remember one specific example. I wanted to pipe a list of URLs to a program. Easy enough in a unix shell. In power shell it's something like Get-Contents <path> | <program> That's a trivial example but when you're doing real work how burdensome does that base verbosity become? I know there's this Linux in Windows stuff and Cygwin but really, for real work, I'll just use a *nix.
- steveklabnik 9y agoTab complete is a thing. I haven’t found it to be as significant as I expected.
- deleted 9y ago
- bogomipz 9y agoWhat a great book! I had a question about the section "A Freestanding Rust Binary" specifically the the "start attribute" section. The author states: "The ! return type means that the function is diverging, i.e. not allowed to ever return. This is required because the entry point is not called by any function, but invoked directly by the operating system or bootloader. So instead of returning, the entry point should e.g. invoke the exit system call of the operating system." Is this explicitly "diverging" marking a Rust specific bit of housekeeping? For instance I wasn't aware of any parallel in the C runtime but maybe someone could shed some light on this?
- steveklabnik 9y agoIt’s part of the Rust typesystem, yes. It’s not the end of the world in this case if you don’t use it, but it’s the correct thing to do. ! is mostly useful when composing with other things, as it unifies with any type. return, break, continue, all have the type !. There’s an example of this being useful in the guessing game chapter of the book, I’d link you but I’m on mobile. So in this context, since you never really call this function directly, it’s return type isn’t super relevant.
- bogomipz 9y agoI see, so its "best practices", the code would still compile without that. Thanks. I'm curious if you might have any recommendations for a "gentle" introduction to the Rust type system.
- steveklabnik 9y agoIt’s not only about the type system, but the book is pretty gentle. It only lightly covers the more advanced stuff, and leaves a few things out, which are in the Nomicon. What languages do you code in normally? I could also give you a short summary.
- bogomipz 9y agoMy languages are generally Python, Golang, Java. Cheers.
- ape4 9y agoThat was interesting. I found the headstands necessary to write to a raw address a bit taxing. In C you'd just use the `volatile` keyword. But being able to localize unsafe code is a big win.
- kibwen 9y agoWorth noting that, as of a week ago in nightly, there are new convenience methods on unsafe pointers to make using them a bit more ergonomic (though unsafe operations will still require the `unsafe` keyword, of course). Here's the document describing the new changes: https://github.com/Gankro/rfcs/blob/0048bf68c56dd25cd2afed7717a3834a22471696/text/0000-unsafe-pointer-reform.md https://github.com/Gankro/rfcs/blob/0048bf68c56dd25cd2afed77... As an example: // This: ptr::read(self.ptr.offset(idx as isize)) // Becomes this: self.ptr.add(idx).read() This will be in stable Rust on May 10.