Cutting down on lib-c reliance?

So I like zig, it's pretty cool how it doesn't need to dynamically link to any libs, except for kernel libs, and your executable sizes are literally 3KB. Yet you can have all this fancy stuff like allocation, io, etc.

As for rust, it relies on a crazy amount of external dependencies, and static linking doesn't really help either.

Are there any projects, toolchains, an std rewrite, etc. That will either reduce rusts syscall overhead, ie calling the kernel directly instead of going through libc first.
like even if i have to turn off rusts std, and use a library that lets me access the os in a abstracted cross platform manner

i saw musl, but it doesn't really seem that good with no windows support.

im looking for something cross platform

The cross platform option is libc. Additionally, Linux is somewhat unique in having a stable syscall interface; for both macOS and Windows the stable way to talk to the OS is libc and/or the other system libraries, and trying to bypass them is not supported.

The binary size "overhead" from Rust is mostly a one time cost for string formatting machinery, which can't be optimized out since it's used dynamically by the panic machinery. Even if it were optimized out for an empty program, it would show back up as soon as you did basically anything.

If you're interested in microoptimizing Rust binary sizes, you can check out GitHub - johnthagen/min-sized-rust: šŸ¦€ How to minimize Rust binary size šŸ“¦. But on a tier one hosted OS, the size we're talking about is rarely worth worrying about.

3 Likes

You can remove the standard library entirely using #![no_std], which allows you to avoid linking against libc and manage syscalls manually,
and you should then rely on alloc and core crates,
there is also sc crate that allows you to call syscalls directly.

UPDATE: sc for linux syscalls and windows for windows (Duh)

There was a similar topic recently: