PengyOS / Docs / Recipes / Rust with rustup
Rust with rustup
rustc needs a C linker, and PengyOS has none on the system, so Rust builds run in the dev box. It already has rustup and the stable toolchain. Because the box shares your home, the binaries you build are right there on the host, and they run there.
ServerDesktop
Build
mkdir -p ~/src && cd ~/src
pengyos-guest enter dev -- cargo new hello-rs
cd hello-rs
pengyos-guest enter dev -- cargo build --release
./target/release/hello-rs # runs on the host
Or open a shell in the box (pengyos-guest enter dev) and work there as on any
Linux: cargo, rustup, cargo install and
rust-analyzer all live in ~/.cargo.
Why not on the host? ~/.cargo/bin/cargo is
visible on the host too, since it's your home. But a build there stops at
linker `cc` not found. Run cargo through the box.
Toolchains
pengyos-guest enter dev -- rustup update # newest stable
pengyos-guest enter dev -- rustup toolchain install nightly
pengyos-guest enter dev -- cargo +nightly build
pengyos-guest enter dev -- rustup component add clippy rustfmt
Command-line tools from crates.io
pengyos-guest enter dev -- cargo install ripgrep tokei
~/.cargo/bin/tokei . # installed into ~/.cargo/bin, usable from the host
Add ~/.cargo/bin to your host PATH if you want these as plain commands
(path=(~/.cargo/bin $path) in ~/.zshrc).
Binaries that run anywhere: static musl builds
A normal build links against the box's glibc. It runs on the host, because PengyOS's glibc is newer, but it can fail on older systems or need a library the host lacks. A musl build has no runtime dependencies at all:
pengyos-guest enter dev
sudo apt install musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
# → target/x86_64-unknown-linux-musl/release/<name>, a single static file
Crates that bind C libraries (OpenSSL, for one) need the musl build of that library. Prefer
pure-Rust crates (rustls, ureq, reqwest with
rustls-tls) when you want static binaries.
GUI apps and system libraries
Crates that link system libraries through pkg-config (GTK, Wayland, ALSA…) want
the -dev packages in the box: sudo apt install libgtk-4-dev and so on.
The result runs on the host only if the host has those libraries too. The Desktop has the
Wayland, GL, Vulkan and font stack, but not every library Ubuntu offers.