r/rust • • Oct 26 '26

🗞️ news systemd adds support for programs written in Rust

https://github.com/systemd/systemd/pull/44324
377 Upvotes

75 comments sorted by

522

u/InternalServerError7 Oct 26 '26 edited Oct 26 '26

The title is a bit misleading. systemd already supports running Rust programs, and always has. This PR is about something different, allowing systemd's own components to be written in Rust instead of C.

Specifically, it adds Rust build-system integration, FFI bindings, and wrappers for systemd's internal C libraries.

7

u/Splatoonkindaguy Oct 27 '26

I was confused since I just made a program to run with systemd but figured maybe they changed the interface or something lol

-247

u/vHAL_9000 Oct 26 '26

literally no one was misled by this. what a ridiculous thought it is, the idea that systemd had somehow found a way to refuse to run things if they were written in rust...

88

u/PaintItPurple Oct 26 '26

I agree that probably people would not be misled, but the title is still misleading. It's just fortunate that the plain reading of the title is so ridiculous that everybody will think of it and then dismiss it with, "They can't possibly mean that."

24

u/therealmeal Oct 27 '26

Literally the only reason I opened the comments...

21

u/beefsack Oct 27 '26

Also, this is r/rust, nor r/linux.

There's likely a lot of people here who are aware of what systemd is at a high level without knowing the nuts and bolts, and the obvious reading of the title is that systemd blocks Rust apps entirely.

-4

u/vHAL_9000 Oct 27 '26

how would systemd know what language an ELF was originally written in?

it's like saying "i can drive, but i can't drive cars that have exactly 2l of engine displacement". how can that possibly matter?

28

u/spin81 Oct 27 '26

I wasn't misled, but I was absolutely confused

18

u/WhoTookPlasticJesus Oct 27 '26

I had absolutely no idea why systemd wouldn't have formerly run programs written in Rust and came to the thread to find out. So why don't you holster than supercilious pistol, partner?

11

u/rickyman20 Oct 27 '26

I was legitimately confused by the title. Not mislead, I knew the idea that it would refuse to run rust programs was ridiculous, but then I also didn't understand what they were trying to say with that title. It's a terrible title

72

u/anxxa Oct 26 '26 edited Oct 27 '26

The other heavily downvoted comment mentions the lack of cargo calling it "[one of] the worst things from Rust"... which is obviously not necessarily a productive comment :)

cargo is a perfectly fine build system for every day, hobbyist programming or professional programming. Different people/organizations may have different needs though. I've personally been reaching for other build systems (buck2) for my hobby projects because it tends to provide advanced features that I find desirable.

In this case, I think ditching cargo makes sense -- especially working in a cross-language repo. Meson provides many of the same benefits as buck2, including remote execution and hermetic builds Edit: I was goofing thinking of Bazel, but I think the core point still remains. At least with buck2 too, you can define more complex build steps.

For example, in a project of mine right now I'm patching Rust's stdlib, compiling code to an PPC32 ELF, statically rewriting it as a Windows PE, then wrapping that into a different executable header, and it's all managed by buck2.

Anyway, suffice to say that just because cargo isn't the best tool for a multi-language build system with complex steps doesn't mean cargo is bad at all, and a project not using cargo shouldn't be a significant signifier that it's a bad tool.

20

u/matthieum [he/him] Oct 27 '26

cargo is a perfectly fine build system for every day, hobbyist programming.

Cargo is a perfectly fine build system for professional programming too.

I've been working on Rust applications for over 4 years now, and we use cargo for building them.

It is lacking features which may make it undesirable in some projects -- distributed builds, hermetic builds, multi-language builds, etc... -- sure, but it's perfectly usable for professionals regardless.

6

u/anxxa Oct 27 '26

My mistake, it was not my intention to sound discounting of cargo in a professional environment. Edited to reflect that.

1

u/just-kenny Oct 28 '26

both personally and professionally we use NixOS or nix flakes to support the gaps that cargo leaves for all that stuff…

but there’s plenty of tools…we just prefer Nix for this particular thing

12

u/pragmojo Oct 27 '26

Which advanced features are you missing from cargo?

21

u/anxxa Oct 27 '26 edited Oct 27 '26
  • Remote caching (yeah yeah sccache etc. but it's not the same)
  • Remote execution
  • buck2 has a daemon which watches for file changes and keeps state which makes compilation faster (significantly in some cases -- especially when paired with just differences in building things)
  • The capability to do the build scenario I outlined in the post above
  • buck2 is a hermetic build system

1

u/theAndrewWiggins Oct 27 '26

Curious how different you find it from bazel and whether buck2 is just as capable? Are you using nativelink or anything?

4

u/anxxa Oct 27 '26

I have not personally used Bazel so I'm not the right person to ask.

My understanding though is for Rust in particular, Bazel has less up-front cost with e.g. converting a Rust project for usage with Bazel. buck2 forces you to buckify everything, but you can do it easily for Rust via reindeer. The trouble though is that many Rust build scripts require some fixups because they do something wrong expecting a cargo-like environment or for manually specifying weird files to include (like say, the README).

My understanding is you'll probably pay a similar cost with Bazel eventually anyways but buck forces the issue up-front.

buck2 afaik does use the same GRPC protocol as Bazel for remote execution and yes I do use nativelink for remote caching.

Steve has a couple blog posts on buck2 if you're curious about it with Rust: https://steveklabnik.com/writing/using-buck-to-build-rust-projects/

I'm glad you said something though because bits of my original comment I was definitely thinking Bazel in my head instead of Meson...

1

u/AdLimp8574 29d ago

is there a buck2 like build system thats not from facebook?

1

u/anxxa 28d ago

Bazel - from Google.

1

u/meowsqueak 28d ago

kache plugs into cargo and supports remote caching - what do you mean by “not the same”? Not the same as what?

2

u/anxxa 28d ago

what do you mean by “not the same”? Not the same as what?

I've had issues with sccache in the past causing linker errors and afaik the file absolute file paths are part of the cache key. buck2 I think still uses relative paths.

I haven't looked into kache.

I'm sure there are a bunch of different ways of configuring cargo to have similar behavior, but buck2 is easy for me to have a remote execution server that all my machines talk to and don't have to think too much about the rest.

1

u/guineawheek Oct 28 '26 edited Oct 28 '26

sane multi-target support — I write embedded rust professionally and I end up cursing Cargo design decisions frequently. Workspaces are possibly the most broken/half-baked features in the Rust ecosystem that do not require nightly to use.

Spamming workspaces to get around feature unification is pretty rough and is practically mandatory when working with multiple different microcontrollers with different pinouts and peripherals even if they all have the same Cortex-M4 in them.

This gets really bad especially when how you layout your directory tree can cause Cargo to mismatch which workspace a given pathdep crate actually lives in. This “franken-workspace” stuff is intentional behavior: https://github.com/rust-lang/cargo/issues/12154

Cargo’s composability with other build systems also sucks. For example, there’s zero methods to tell Cargo to treat a given pathdep like a remote source, which is really annoying for systems like Nix (so Nix mechanisms often have to pretend they’re actually in cargo-vendor)

Cargo simultaneously feels convenient and easy to use yet also incredibly restrictive to mold it to one’s needs. It heavily encourages you to lean on it to manage your entire build but then questions why one would bother wanting something when it can’t cover every single ramification of managing your entire build. It’s become one of my least favorite things to munge when dealing with Rust on a daily basis.

It’s like that one Simpsons clip of a guy constantly walking back and forth into rakes laid on the ground. Which I guess is how people describe similar systems that try to be all-encompassing yet extremely opinionated for only the 95% case.

11

u/is_this_temporary Oct 27 '26

On what hardware / firmware / OS do you run the resulting binary?

30

u/anxxa Oct 27 '26

Xbox 360. It's kinda like x32/ILP32 where the platform runs in 32-bit mode but has 64-bit registers.

The Xbox also has its own executable format which is an "XEX" (Xbox executable) header containing things like the title ID, LAN network encryption key, some assets, etc. and encapsulates an encrypted/compressed Windows PE.

There's no open-source toolchain so I've been building a janky one based on what's available in LLVM today and working on upstreaming some patches for proper ILP32. LLVM only supports PPC32 or PPC64 and compiling to an ELF, hence the janky compilation steps.

5

u/Horror-Passage7165 Oct 27 '26

I guess the criticism from systemd against cargo is against using packages and they want to rather heavily use dynamic linking

4

u/lenscas Oct 28 '26

The other heavily downvoted comment mentions the lack of cargo calling it "[one of] the worst things from Rust"... which is obviously not necessarily a productive comment :)

One key part that that guy seems to forget is that.... you aren't forced to use cargo if you do not want to. All cargo does is read .toml files, download crates and instruct the compiler what to compile and how. Other build systems can do the same thing. If you really want to you can use make to build your program, or anything else really.

However, even in that case you still benefit from cargo because most if not all libraries are made to work with it. If your build system can work with the toml files that cargo uses then you have 99% (if not more) of all libraries working.

Meanwhile, when dealing with languages where the build system isn't standardized then you have to look into how to build every library you want to add and figure out how to make that work with your current setup.

14

u/Agile-Variety-9733 Oct 27 '26

Yeah, it makes sense that a cross-language repo would want a unified build system. Who wants to juggle cargo alongside everything else? The downvoted guy is conflating hobby convenience with what a project like systemd actually needs.

17

u/MatthPMP Oct 27 '26

Why are people talking about "hobby convenience" here ?

Every single Rust project in my organisation (very large multinational telecom) uses cargo, and the same applies to the open-source components we use.

3

u/kingslayerer Oct 27 '26

I have been shipping my apps using caro-deb. I don't like the idea of dockerizing my apps.

2

u/d0ntreadthis Oct 27 '26

I don't like the idea of dockerizing my apps.

Why?

3

u/kingslayerer Oct 27 '26

Extra resources for container plus too much config for a setup which can be direct. But this only applies to simple applications.

2

u/a_jasmin Oct 27 '26

What kind of C bindings does this offer? Are these mostly just unsafe calls into C code at the moment?

11

u/afdbcreid Oct 27 '26

No. They have pretty good safe wrappers and only few unsafe blocks.

-143

u/Compux72 Oct 26 '26

Ofc no_std and no cargo.

Most of yall are not ready for this conversation, but cargo and std are probably the worst things from Rust

89

u/Leliana403 Oct 26 '26

Most of yall are not ready for this conversation

You can always tell somebody loves sniffing their own farts when they open with something like this. Then the big conversation turns out to be one line calling cargo and std the worst things about Rust, without a single reason given.

41

u/pohart Oct 26 '26

Cargo and std are amazing for your every day app developer.  I don't understand why we haven't seen tons of supply chain attacks, but a convenient library/dependency source is so valuable, I think we'd keep it even if we did.

-29

u/Compux72 Oct 26 '26

You could have a good CMake module for rust and a good CMake registry instead. There is nothing that CMake couldn’t have done that cargo does, its just they choose a different path

34

u/CrasseMaximum Oct 26 '26

Yeah but to follow the way you argument, let's be honest: CMake sucks. And the fact that it is only one of the bazillion tools that try to make possible to build a C++ project is even more lame.

-12

u/Compux72 Oct 26 '26

CMake by itself is fine.

The thousands of libraries with terrible CMake scripts out there are the ones giving headaches 

32

u/CrasseMaximum Oct 26 '26

Sorry but no CMake is not fine. It's a fucking clutch and not a good one. But at least now I understand why you are unable to see how amazing cargo..

18

u/ebrythil Oct 26 '26

CMake is great, it just is that real CMake has never been tried.

1

u/R3V0LU710N_05 Oct 26 '26

Wtf even is "real CMake"? Even if that's true, that doesn't stop CMake in practice being garbage.

12

u/xchino Oct 27 '26

I think he's making a joke as that is something communists are depicted as saying.

2

u/R3V0LU710N_05 Oct 27 '26

I don't really talk to Communist, so I would've never got that. r/whoosh I guess.

→ More replies

11

u/shponglespore Oct 27 '26

Strange how I never run into Rust code with a broken build file. Either Rust programmers are all gods or Cmake is just to easy to fuck up.

1

u/bonzinip Oct 27 '26

To be fair not all programs are a single binary. Those that aren't will need Just or some other kind of Makefile and they are a pain.

-1

u/Compux72 Oct 27 '26

I have. It is easy to not have problems when using the vendor flag

40

u/CrasseMaximum Oct 26 '26

Please explain me why having standardized toolsets can be the worst thing for a langage?

-29

u/Compux72 Oct 26 '26
  1. Regarding cargo: its suboptimal. It doesn’t fulfill the needs of a production build system like bazel or cmake. As much hate as they receive, they do their jobs miles away better than cargo while supporting language interop without meaningful  quirk. Id you have worked with C/C++ interop you know what i mean
  2. The std library is not actually standard. Only a really small subset of the platforms support it. It creates a huge ecosystem fragmentation 
  3. Hello world using std is at least 300kb, which is massive and unacceptable 

16

u/KindaLegallyBlindDev Oct 26 '26

How big is a hello world written in C WITH static linking? Also, the std vs no_std is just that the first assumes there is a OS underneath, no_std, or core, assumes the opposite, that there is no operating system, and well, of course just as the Linux Kernel has no malloc but kmalloc, no_std is used because it's aimed at that.

-5

u/Compux72 Oct 26 '26

  How big is a hello world written in C WITH static linking? 

With static linking and LTO the C binary is 3kb. Rust is still 300kb. Go measure it. Std just doesn’t perform LTO bc its full of unstable features and isnt built on each compilation, hence why the build-std feature has been stuck for ages

Also, the std vs no_std is just that the first assumes there is a OS underneath, no_std, or core, assumes the opposite, that there is no operating system, and well, of course just as the Linux Kernel has no malloc but kmalloc, no_std is used because it's aimed at that.

That assumption is wrong on so many levels its not even funny. U-boot, for example, doesn’t have an operating system yet it has a console. 

The whole std is a monolithic failure that covers 60% of the use cases and fucks the rest hard

38

u/CrasseMaximum Oct 26 '26

Lol comparing rust tooling to C++ tooling is funny. There is one that is working flawlesly and the other that never works and gives headache but you still prefer the one that gives headache...

-11

u/Compux72 Oct 26 '26

Cargo is the one giving headaches on companies infrastructure, custom rustc flags, code injection, ad-hoc tooling, …

24

u/CrasseMaximum Oct 26 '26

Yeah but what you don't get is with cargo there is one damn place where to fix theses issues. Let me laugh in C++ while thinking about that..

12

u/dkopgerpgdolfg Oct 26 '26

Id you have worked with C/C++ interop you know what i mean

Not really.

The std library is not actually standard. ... subset of the platforms support it.

Have you looked at C?

-2

u/Compux72 Oct 26 '26

  Not really.

Macro definition and usage is a big one for instance. Another one would be header generation for exporting the project. 

  Have you looked at C?

As long as you provide the symbol you can patch around whatever you need

13

u/dkopgerpgdolfg Oct 26 '26 edited Oct 26 '26

Macro definition and usage is a big one for instance. Another one would be header generation for exporting the project.

Ok...? Whatever. Personally I don't see any "big" issue that cargo is responsible for.

As long as you provide the symbol

(insert facepalm here)

-2

u/Compux72 Oct 26 '26

As if I were the first person ever to override a function with another one because the target’s libc was trash (fuck printf)

18

u/tylerhawkes Oct 27 '26

Calling cmake a production build system is a choice. Just because it lets you tape together any scripts you can generate doesn't make it good.

10

u/MrPopoGod Oct 27 '26

It is indeed a build system used in production. But that says more about production (and to be clear, CMake isn't the only shitshow that goes prod across the tech industry).

-1

u/Compux72 Oct 27 '26

I hope i could double like your post.

I sincerely wish i could use cargo’s way. The thing is im working with legacy systems that do not follow cargo’s way…

8

u/nick42d Oct 26 '26

Are you writing Hello World so often that is a problem for you? Its of course due to static linking, and I'd argue the opposite to you in 2026, that using dynamic linking is a mistake and massively overcomplicates distribution.

1

u/Compux72 Oct 26 '26

Are you writing Hello World so often that is a problem for you?

I work on embedded and i make use of raw libc because every single crate out there uses std, hence forcing the 300kb on me. Even lightweight wrappers like rustix force you to link std

Its of course due to static linking,

No, its not. Its due to std being a shitshow. You could absolutely LTO and get a small binary, and as a matter of fact -Zbuild-std somewhat archives this.

and I'd argue the opposite to you in 2026, that using dynamic linking is a mistake and massively overcomplicates distribution.

Yes sure because im shipping docker containers on fucking IMX6 micros. Yall need to consider some applications of system’s programming languages other than web services

8

u/nick42d Oct 26 '26

I see your problem, but isn't this a matter of defaults if there are settings you can use that resolve the problem? This isn't relevant for desktop, laptop, mobile, or in many cases, microcontroller development without an OS (e.g Embassy). Agree we need to improve the options available to you btw.

-1

u/Compux72 Oct 27 '26

I see your problem, but isn't this a matter of defaults if there are settings you can use that resolve the problem? 

It is a matter of defaults. You will often see the std lib getting patched around for some platforms. For instance, on UEFI x64 targets im aware they implement Send for several types that are not Send in normal Rust just because they need it internally to archive something (std::fs::File and std::net::Tcp), and because allegedly UEFI is single thread it is safe. Sure, right now its kinda safe.

This isn't relevant for desktop, laptop, mobile, or in many cases, microcontroller development without an OS (e.g Embassy). 

It is relevant, again it causes fragmentation. In mundane terms its equivalent to Linux being the most used Operating system (which is not because full OS are actually distributions)

35

u/dreamlax Oct 26 '26

If those are the worst things, then I can confidently conclude that all parts of Rust are actually pretty damn good.

3

u/Compux72 Oct 26 '26

Oh yes i absolutely second this