rustc "error[E0463]: can't find crate for X" in CI
rustc was told to use a crate but could not find its compiled .rlib/.rmeta on the search path. The dependency was not built, the target's standard library is not installed, or a stale target directory is confusing the compiler.
What this error means
Compilation fails with "error[E0463]: can't find crate for X" naming a dependency or, for cross builds, std or core.
error[E0463]: can't find crate for `serde`
--> src/main.rs:1:1
|
1 | use serde::Serialize;
| ^^^^^^^^^^^^^^^^^^^^^ can't find crateCommon causes
The dependency is not declared or not built
The crate is referenced in code but missing from [dependencies], or its build failed earlier so no artifact exists for rustc to link.
The target std is not installed (cross builds)
When the crate is std or core, the precompiled standard library for the requested --target is not installed via rustup.
How to fix it
Declare the dependency or build it first
- Add the crate to
[dependencies]inCargo.tomlif it is missing. - Run a clean build so the dependency artifact is produced.
- Confirm an earlier compile error did not leave the dependency unbuilt.
cargo add serde
cargo clean && cargo buildInstall the target std for cross compilation
If E0463 names std/core, add the rustup target so its precompiled standard library exists.
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-muslHow to prevent it
- Declare every crate you
useinCargo.toml. - Add required rustup targets before cross builds.
- Run
cargo cleanwhen a stale target directory misbehaves.