Hacker News new | ask | show | jobs
by lelanthran 1090 days ago
> Quite a few of those ~1 million lines seem to be in libc-type wrappers, which is roughly analogous to libc for C (which also isn't included).

I didn't know that Rust programs run without a libc.

2 comments

They don't. The way it's set up is:

The stdlib only exposes some syscalls via rust-friendly wrappers, and in a way that is generally a cross-platform subset, sometimes with platform extentions. So the `fs` module (https://doc.rust-lang.org/std/fs/) exposes common file operations across most (all?) supported platforms. Some unix specific file operations are exposed at: https://doc.rust-lang.org/stable/std/os/unix/fs/index.html . These things do a pretty good job for most work, but sometimes you gotta get wierd...

The libc crate allows more direct access to the syscalls on your flavor of *nix by creating a rust-> bridge for them, and exposing the C types directly. This bridge isn't a lot of code, mostly it just does the work of creating a rust function that minimally wraps the external C function. For a lot of low-level software you end up pulling the libc crate to hit your system specific calls.

And for some very system specific calls (e.g. io_uring) you end up having to pull in another crate that calls into that subsystem for you (often pulling in libc also).

All of this ends up being linked to the libc you build against tho.

Speaking from nearly total ignorance of Rust, I don't understand why things can't be hidden in a ton of wrappers and interfaces.
What’s being counted here is the interfaces and wrappers.
Rust programs can run without a libc:

1. on Linux

2. in embedded

The vast majority of them do use libc, as the underlying platform requires. The default on Linux is to use a libc as well.