rustc_driversrustc_privateThe rustc_private feature allows external crates to use compiler internals.
rustc-private with Official ToolchainsWhen using the rustc_private feature with official Rust toolchains distributed via rustup, you need to install two additional components:
rustc-dev: Provides compiler librariesllvm-tools: Provides LLVM libraries required for linkingInstall both components using rustup:
rustup component add rustc-dev llvm-tools
Without the llvm-tools component, you'll encounter linking errors like:
error: linking with `cc` failed: exit status: 1 | = note: rust-lld: error: unable to find library -lLLVM-{version}
rustc-private with Custom ToolchainsFor custom-built toolchains or environments not using rustup, additional configuration is typically required:
export LD_LIBRARY_PATH=/path/to/llvm/lib:$LD_LIBRARY_PATH
rust-analyzer for Out-of-Tree ProjectsWhen developing out-of-tree projects that use rustc_private crates, you can configure rust-analyzer to recognize these crates.
rust-analyzer.rustc.source to "discover" in your editor settings.rust_analyzer_settings.json:{ "rust-analyzer.rustc.source": "discover" }
Cargo.toml of every crate that uses rustc_private:[package.metadata.rust-analyzer] rustc_private = true
This configuration allows rust-analyzer to properly recognize and provide IDE support for rustc_private crates in out-of-tree projects.
rustc_private linker failures often occur because llvm-tools is not installed