Skip to content
Latchkey

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.

cargo
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.

Terminal
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-musl

Request the target in the toolchain action

Provision the cross target alongside the toolchain so it is present before cargo runs.

.github/workflows/ci.yml
- uses: dtolnay/rust-toolchain@stable
  with:
    targets: x86_64-unknown-linux-musl

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →