cargo "--target requires rustup target add" (std not installed) in CI
You passed --target for a platform whose precompiled standard library is not installed. rustc cannot find std/core for that target and the build fails. rustup must download the target before cargo can cross-build.
What this error means
cargo build --target ... fails with "error[E0463]: can't find crate for std" and a note that "the X target may not be installed" or to run rustup target add.
error[E0463]: can't find crate for `std`
|
= note: the `x86_64-unknown-linux-musl` target may not be installed
= help: consider downloading the target with `rustup target add x86_64-unknown-linux-musl`Common causes
The target std component is not installed
rustup ships precompiled std per target; the requested --target was never added, so no standard library exists for it.
A toolchain action that did not add the target
The toolchain was installed for the host only, and the cross target was not requested, so building for it has no std.
How to fix it
Add the rustup target before building
Download the precompiled std for the target, then cross-build.
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-muslRequest the target in the toolchain action
Provision the cross target alongside the toolchain so it is present before cargo runs.
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-muslHow to prevent it
- Add every cross target with
rustup target add(or the action input). - Keep target provisioning next to the build step.
- For musl/cross builds, also install the matching linker.