mrkeyoor.com_
Sun 08 Nov 18:30 UTC
Open Source3 min read

Systemd accepts Rust programs while shared libraries stay in C

Systemd has merged optional Rust support for new programs. Contributors must use Meson and existing systemd APIs, with no Cargo or Rust standard library.

Systemd has merged optional Rust support for new programs, allowing contributors to use the language while keeping shared libraries in C. The integration landed on October 24. In a November 3 explanation, Christian Brauner and Lennart Poettering set out the limits: Rust components must fit the project's existing build system and behavior. This is upstream development support, not evidence that your distribution has shipped it.

The distinction matters for developers expecting a conventional Rust project. Systemd's coding rules require Meson builds, prohibit Cargo and exclude Rust's standard library. This article examines the merged change and documented rules. We haven't built or tested the integration.

New programs, existing C foundations

Rust is restricted to new leaf components: programs that nothing else in the systemd source tree depends on. Existing C code isn't being ported under the current policy. Shared libraries stay in C, including libsystemd-shared and libsystemd, as do the NSS and PAM modules.

Brauner and Poettering attribute the shared-library restriction to Rust's lack of the first-class shared-library support they need. They argue that duplicating Rust code across systemd's many small binaries would be impractical. Rust programs instead call the existing C functionality through wrappers.

For a contributor, that means learning systemd's interfaces alongside Rust. The coding rules direct programs through the in-tree systemd_shared crate. A missing wrapper belongs there, rather than becoming a raw call from an individual program.

Memory errors must remain recoverable

The restrictions extend to allocation. Systemd's Rust rules prohibit the usual alloc crate because its collections abort when memory runs out. The project's own Box and Vec return allocation errors instead. That preserves systemd's expectation that code can handle a failed allocation.

The merged pull request also describes a command-line parity test comparing equivalent C and Rust programs byte for byte. Its purpose is to keep help output and option handling consistent across languages. We haven't run that test ourselves.

Rust remains optional, and systemd without Rust remains supported, the maintainers say. Watch which new components adopt it and how distributions package the toolchain. Broader use in shared libraries would require solving the linking problem the maintainers have explicitly left open.

Sources

  1. systemd loves Rust, by Christian Brauner and Lennart Poettering
  2. Merged pull request: support programs written in Rust
  3. Systemd coding style: Rust rules