Rust and the operating system, the web, databases and other languages

This is the second part of a two-part series. Read Part 1.

The increased interest in the Rust 2022 conference shows that different types of projects involve the popular programming language. It’s natural to be curious about the depth of this language and the amount of technology it currently encompasses. This article shows some of the highlights.

Could an operating system be written in Rust?

Simply put, yes, a variety of operating systems and OS-like systems are available in Rust. This includes unkernels, hypervisors, other virtual machine technologies, and firmware projects.

KataOS by Google is a secure operating system that uses seL4 as a microkernel for security purposes. Performant seL4 has been shown to be mathematically correct against its specification and is particularly secure. The pleasant notion of guaranteed integrity, availability, and confidentiality is refreshing. Internally, KataOS is also able to dynamically load and run third-party applications built outside of seL4’s CAmkES (component architecture for microkernel-based embedded systems) framework.

The current GitHub release contains most of the core components of KataOS:

  • Frameworks used for Rust, such as the sel4-sys box for seL4 system call APIs.
  • An alternative root server written in Rust.
  • A kernel patch for seL4 to also allow reclaiming memory used by the root server.

The Google reference implementation called Sparrow for KataOS allows users to evaluate KataOS on secure hardware platforms. In addition, Sparrow includes a logically secure root of trust built with OpenTitan on a RISC-V architecture.

Another goal of KataOS is to be used as the underlying operating system in the Android system. The Rust end user and developer base would explode if this came to fruition.

redox is one of the older projects of the more traditional operating systems. It offers a seemingly reasonable starting point for someone interested in a “Linux-like” development platform. A few redox observations:

  • Current version is 0.7 (we were running 0.6) so not the latest.
  • It is probably the longest running Rust OS project.
  • Boots are extremely fast. It took less than 15 seconds in QEMU emulating x86_64 on an M1 ARM.
  • It’s Unix/Linux-like, but with a microkernel design, maybe POSIX.
  • It has basic tools, internet browser, file editor, file browser, calendar, image viewer.
  • Version 0.6 runs in ~350 MB.

Primary source of the table: https://github.com/flosse/rust-os-comparison

Rust and the Web

Anyone who has had anything to do with Rust understands that there is a lot of technology available for WebAssembly (Wasm). Many consider this technology to be a (r)evolutionary web user interface. Rust technologies provide mechanisms to strip down much of the CSS, HTML, and JavaScript from website infrastructure. As the interweb will continue to be an important part of many people’s lives, Rust may also be able to offer more security checks and storage security as it evolves in cyberspace.

Wasm is included as a compile target in many Rust library stack environments. This means your program can run on the web without any code changes. Bevy, a game development toolkit, is one such environment.

WebGPU is an emerging API that provides simpler interfaces for accessing multiple GPUs in your environment. It’s not just for games. Many aspects of scientific visualization and integration with augmented reality/virtual reality (AR/VR) technologies will enable many things in terms of intelligent visual interactions and designs. This will help those who have ample data in many professions.

Rust also has nice libraries for building a web service infrastructure. Whether you’re building a platform, distributing an API, or publishing a website, you’ve got the tools. Actix, Hyper, Iron, and Rustless are some useful tools in this area.

Could a database be written in Rust?

Many experimental SQL and NoSQL stores are implemented in Rust. Several database engines have emerged, offering options for those who want to take full advantage of the language’s power. Given the speed and responsibility inherent in the environment, it’s not hard to imagine the suitability. SurrealDB (commercial), FeOphant (Postgres-like), Databend (Arrow2) and GlueSQL are some examples. Many projects supporting mobile and IoT environments are also coming online. If your dream is a full stack of Rust to evolve on, it’s on the way. Of course, there are APIs and drivers for most mainstream databases as well.

Does Rust integrate well with other programming languages?

Rust has a few tailwinds working in his favor. Polyglot APIs have become the norm for development environments and hence backends are written with this in mind. Adding another language API is usually not very difficult in such environments. For this reason, Rust APIs to existing systems extend the reach of Rust developers.

Well-documented language pairings

Rust seems to be able to extend other languages ​​well and create efficient hybrid development environments.

C — Rust directly supports the development of interfaces to C with its Foreign Function Interface (FFI). In many cases it is possible to write near-safe code here and to implement things like callbacks from C in your Rust code. In addition, FFI goes well beyond C.

Javascript — Besides linking JS and Rust to WebAssembly, with a little search engine magic it becomes clear that there are a multitude of projects and papers out there with techniques to harmonize the two environments. There are even JavaScript interpreters/frontends written in Rust. Also obvious are tutorials for creating personalized or custom interpreters. Rust can interact nicely with any number of languages ​​like Python, Lua, Erlang, Haskell, and more.

Who is likely to be using Rust soon?

Several sectors appear to be ripe for Rust, particularly where memory security and performance are critical issues. It will probably be harder not to use Rust on these ventures, especially when it comes to Greenfield. As mentioned earlier, most industries that make heavy use of cloud services and software development technologies are likely to inadvertently use them along with mobile and web apps.

Besides the computing and IT sectors, government/defence, IoT/embedded, telecom, healthcare and education/research seem to stand out. Several trends that IT managers are focusing on could also be beneficial for Rust. For example, cyber security and cloud strategies are dominant issues in the short and long term. Rust has strong messages to send for both of them. New autonomous infrastructures of different types need to be met with increased security and stability attributes. This obviously facilitates the best outcomes in terms of public safety and co-ownership at different levels of infrastructure management. This includes civil, smart home, driving, sensors and probably a lot more.

Manufacturers Ford, GM, BMW, Bosch, Volkswagen, Volvo and Toyota have all joined a new subgroup in Autosar’s Functional Safety Working Group (WG-SAF), an automotive standards group studying the use of Rust in a reference platform .

SAE International has also set up a task force for safety-related systems for Rust in the automotive industry. This is certainly a case where a spot of rust on your vehicle is welcome.

There are also developments with innovative track systems. Parallel Systems is located in this area and enables the dynamic (de)coupling and self-propelling of individual wagons.

In finance, a useful trading library, Quants/QuantLib, is experiencing an oxidation. The term “quants” in the field of securities (stocks) refers to data experts who program high-speed trading algorithms that generally take precedence over retail traders at market makers. While controversial, this shows that Wall Street is watching.

Tangentially, there are at least 25 active crypto-focused crates in the Rust environment addressing various tokens. In any case, Rust is being geared up to enter this arena and maybe bring solutions. NFTs and EFTs everywhere!

Entertainment and gaming might be surprising areas for Rust to introduce, but it’s also likely to be in areas like film processing and game development. And you’ll find it in music streaming apps, including a Spotify client, various games, console emulators, and of course, massive game development environments like Bevy, Fyrox, Piston, and Unrust. This appears to be a momentum area. Continue to play!

Conclusions

There are four key points in this two-part series:

  1. Rust will continue to make strong strides in basic computing infrastructure.
  2. The memory management model is game changing and you can expect it to be emulated in other languages.
  3. Technologies like Wasm will bring Rust more into the scope.
  4. This advent comes with a trade-off for higher productivity, but that’s likely to be for a limited time.

The Rust team is generally very supportive of newcomers and it’s rewarding to work with an emerging technology. Rust uses both Discord and Zulip for chat. Here’s how to get in. Don’t be afraid to rust your hands.

My humble thanks to Zongfang Lin, Yan Zhang, and Yan Chen from Futurewei for their contributions on KataOS details and language performance analysis.

group Created with Sketch.

Comments are closed.