Linux Kernel & OS

systemd introduces support for Rust-based programs

Key Takeaway

systemd now allows leaf components and utilities to be written in Rust using Meson instead of Cargo.

Summary

The systemd project has merged infrastructure into its Git repository to allow new programs to be written in Rust as an alternative to C. While core libraries remain in C for now due to existing technical blockers, new leaf components like the upcoming systemd-keyring-setup will utilize Rust. This implementation avoids the Cargo package manager, relying instead on Meson and C linkage to maintain system integration.

Technical implementation of Rust in systemd

  • Build System: Rust components are built using Meson rather than Cargo, and only C linkage is mandated to ensure compatibility.
  • Scope of Support: Support is currently limited to leaf components and utilities; core systemd libraries are not yet compatible with Rust due to unresolved blockers.
  • Initial Use Case: The first planned component is systemd-keyring-setup, a utility for provisioning keyrings and X.509 certificates into kernel dm-verity, fs-verity, and BPF keyrings.
  • Binary Size: Rust-based binaries are slightly larger than their C counterparts, with a test program measuring 32KB compared to 20KB for the C version.
  • Configuration: The feature is optional and can be toggled via the -Drust= Meson option, though it is set to auto by default.

Why it matters

This move allows systemd to gradually adopt memory-safe programming practices for new utilities without rewriting the entire core. It sets a precedent for how critical Linux system components can integrate Rust while maintaining strict build requirements and minimizing dependency overhead.

What to do

  • Developers can use the -Drust= Meson option to toggle Rust support, which is set to auto by default
  • Systemd developers and users can expect new leaf components like systemd-keyring-setup to utilize Rust
  • Users can watch for the upcoming systemd-keyring-setup utility, which will be used for provisioning keyrings and X.509 certificates into kernel keyrings

Original reference: www.phoronix.com →