Live data from Hacker News

The Case for Rust in the base system

mail-archive.freebsd.org

21–30 of 155 posts

Re: The Case for Rust in the base system

#21
post #5

Very naive question. What's the main selling point of Rust besides being stably sponsored by Mozilla?

There are two very broad set of features:

1) Memory safety. If you live in the world of kernels and embedded code, your options are mostly C, C++, and (as of just the last few years) Rust. Of those, only Rust reliably prevents memory corruption mistakes like use-after-free.

2) Being a 21st century language. Rust has a lot of features that any new language would be expected to have these days: a unified build system, a library ecosystem that the build sytem knows about, slices over arrays and vectors, UTF-8 strings, convenient ways to de/serialize JSON, something like async/await, etc. This makes it competitive with languages like Java and Python for doing "everyday stuff", where realistically ~no one would use C. The main downside of Rust in a Java/Python sort of context is that the learning curve is a lot steeper.

A couple other notes:

- Some of nice 21st century features (like JSON) go away when you're writing embedded/kernel code, but others still work. Embedded ("no_std") Rust still has enums, error handling, slices, iterators, and sometimes even async/await. Those quality-of-life features are hard to replicate in C, even if you believe your code is 100% bug free :)

- If you know you're going to be writing multithreaded code, Rust's thread safety features are really unmatched. A lot of the same machinery that gets used for memory safety also turns out to be useful for thread safety. Libraries like Rayon make it surprisingly convenient to write multithreaded code, while also catching a huge percentage of mistakes at compile time. (Deadlocks are still possible though.)

Re: The Case for Rust in the base system

#22

My first thought was that rust doesn't target as many platforms as FreeBSD (at least not well), but looking at https://www.freebsd.org/platforms/ apparently the answer is that FreeBSD doesn't support many platforms anymore so I guess that's no longer a problem.

Yeah, but Rust tier 1 is only x86, x86_64, and arm64. And only Linux. That excludes MIPS, PPC, and arm32, all of which FreeBSD continues to support to varying degrees. x86_64-FreeBSD is a Rust tier 2 "it might work" target, as are arm6/7 and PPC. MIPS is Rust tier 3 "we don't build for it or test on it."

Re: The Case for Rust in the base system

#23
Reading through the list it looks like it’s not the kernel that’s being discussed, and this comment implies to me that it’s after much of the C system is built, “ imp suggested adding an additional step after buildworld for stuff that requires an external toolchain”. It’s been a while since I’ve worked with FreeBSD, but I think buildworld includes linking, which would imply to me that you couldn’t link Rust into portions of the system in that stage?

Re: The Case for Rust in the base system

#24

That would be amazing :D I run FreeBSD on my servers and use scripts to manage jails and send and receive ZFS snapshots between hosts. I've been wanting to write some more robust tools of my own for those things, than the scripts I have now, and my favourite programming language is Rust!

Can't you do that now? The article lists ports tools doing those things already

Sure I can but Rust in the base system would provide:

- A stable target, and

- Lots of FreeBSD specific Rust code to read from expert FreeBSD programmers, as guidance

- Probably better ability to build ISOs of my own that include the base system and my jail and ZFS management Rust programs, so that I can install servers from that ready-made ISO and have less post-install work to do

Re: The Case for Rust in the base system

#25
post #4

I am not familiar with FreeBSD's development model. What constitutes the "base system"?

The stuff that’s included in the system after a standard install, before you install any additional stuff. It’s all in one repository and it’s maintained by the FreeBSD project. Stuff like the kernel, libc, utils, dtrace, compilers needed to build base, ... Basically everything that’s needed for a usable system. It’s updated all together through binary patches, not separately through packages like on Linux. When you…

This is a perfect and concise description.

Re: The Case for Rust in the base system

#26

Reading through the list it looks like it’s not the kernel that’s being discussed, and this comment implies to me that it’s after much of the C system is built, “ imp suggested adding an additional step after buildworld for stuff that requires an external toolchain”. It’s been a while since I’ve worked with FreeBSD, but I think buildworld includes linking, which would imply to me that you couldn’t link Rust into port…

I think the idea is you would just move anything depending on Rust to the later stage.

Re: The Case for Rust in the base system

#27
post #17
post #5

Very naive question. What's the main selling point of Rust besides being stably sponsored by Mozilla?

Rust‘s type system prevents memory safety bugs because it reasons about object lifetimes statically. At the same time rust allows you to write systems code on bare metal.

> it reasons about object lifetimes statically.

How does that differ from RAII?

I think i misunderstand you or lack knowledge, because this sounds exactly like RAII.

I know that rust has major compile time checks, but saying that the difference is that it reason about life time as difference to c++ is misleading. I think the major point of c++ compared to c is that c++ "reason about object lifetime statically" with deconstructors and RAII. And saying that rust do this and implying c++ don't is misleading.

Re: The Case for Rust in the base system

#28

> fusefs tests. Absolutely impossible to do in C. I considered Rust, but went with C++ so they could live in base. They are too closely coupled to fusefs(5) to live out-of-tree. Can anyone comment on why this is impossible in C?

"Impossible" is mild hyperbole. Googletest makes it relatively easy to structure complicated mocked tests in a way that is verbose but not impossible in C.

Re: The Case for Rust in the base system

#30
post #5

Very naive question. What's the main selling point of Rust besides being stably sponsored by Mozilla?

There are two very broad set of features: 1) Memory safety. If you live in the world of kernels and embedded code, your options are mostly C, C++, and (as of just the last few years) Rust. Of those, only Rust reliably prevents memory corruption mistakes like use-after-free. 2) Being a 21st century language. Rust has a lot of features that any new language would be expected to have these days: a unified build system,…

> Memory safety

Another very naive question. Are memory safety concerns from a cybersecurity standpoint or from less-dev error standpoint?

Post reply on HN