Rust "no precompiled std" - Wrong Host Toolchain in CI
The installed toolchain's host triple does not match the runner it runs on -- for example a -gnu toolchain on an Alpine/musl runner. rustc cannot find a precompiled std for the host, so even a native build fails.
What this error means
On Alpine or another musl runner, a build fails to find std/core or the linker behaves oddly, because the toolchain was installed for x86_64-unknown-linux-gnu while the host is x86_64-unknown-linux-musl. rustup show reveals the mismatched host.
error[E0463]: can't find crate for `std`
= note: the `x86_64-unknown-linux-gnu` toolchain is installed,
but this runner's host is `x86_64-unknown-linux-musl`Common causes
Toolchain host triple differs from the runner
rustup installed a toolchain for one host (commonly -gnu) while the container/runner is another (-musl). std is precompiled per host, so the wrong host has no usable std.
Glibc toolchain on a musl image
Alpine images use musl; a default glibc rustup install does not match and cannot link a native binary against the host's libc.
How to fix it
Install the toolchain for the correct host
Match the toolchain host triple to the runner.
rustup toolchain install stable-x86_64-unknown-linux-musl
rustup default stable-x86_64-unknown-linux-musl
rustup showOr add the musl target and build for it
Keep the gnu host but cross-target musl explicitly.
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-muslHow to prevent it
- Match the rustup host triple to the runner's libc (gnu vs musl).
- Use the official
rust:alpineimage when you need musl. - Run
rustup showto verify the active host before building.