Rust E0463 "can't find crate for proc_macro" in CI
rustc cannot find the proc_macro crate while building a procedural macro. Proc-macros compile for the host; if the host std/proc-macro component is missing (often after installing only a cross target), the crate is unavailable.
What this error means
The build fails with error[E0463]: can't find crate for proc_macro``. It is deterministic for the installed toolchain/target set.
error[E0463]: can't find crate for `proc_macro`
--> macros/src/lib.rs:1:1
|
1 | extern crate proc_macro;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crateCommon causes
Host std/proc-macro component missing
Proc-macros build for the host triple. If only a cross-compilation target's std was installed, the host proc_macro crate is absent.
Broken or partial toolchain install
An incomplete rustup install can leave the proc-macro support out of the toolchain.
How to fix it
Install the host toolchain components
Ensure the host std (which provides proc_macro) is present.
rustup toolchain install stable
rustup component add rust-std --toolchain stable
rustc --version --verbose # confirm the host tripleBuild proc-macros for the host, not the cross target
Do not pass --target for the proc-macro crate; it must compile for the host.
cargo build --locked # host build for proc-macro cratesHow to prevent it
- Keep the host toolchain fully installed even when adding cross targets.
- Remember proc-macros always build for the host triple.
- Verify
rustc --version --verboseshows the expected host.